Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Commit 750a857

Browse files
authored
Add ESLint with our standard config (#95)
- Added ESLint + plugins for TypeScript and Prettier. - Added the standard config + env: {node: true,} to keep TypeScript happy. - Fixed all the errors that were preventing the app from compiling. Closes #87.
1 parent f23d79d commit 750a857

File tree

7 files changed

+109
-17
lines changed

7 files changed

+109
-17
lines changed

.eslintrc.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module.exports = {
2+
extends: [
3+
'eslint:recommended',
4+
'plugin:@typescript-eslint/eslint-recommended',
5+
'plugin:@typescript-eslint/recommended',
6+
'prettier/@typescript-eslint',
7+
'plugin:prettier/recommended',
8+
],
9+
plugins: [],
10+
rules: {
11+
'prettier/prettier': [
12+
'error',
13+
{
14+
useTabs: false, // \( ̄▽ ̄)/
15+
tabWidth: 2,
16+
semi: true,
17+
singleQuote: true,
18+
},
19+
],
20+
// allows unused vars when declared in arguments
21+
'@typescript-eslint/no-unused-vars': [
22+
'error',
23+
{ vars: 'all', args: 'none' },
24+
],
25+
// disables case checks for class/interface/type
26+
'@typescript-eslint/class-name-casing': 0,
27+
// disables case checks for properties
28+
'@typescript-eslint/camelcase': 0,
29+
// allows 'any' typehint
30+
'@typescript-eslint/no-explicit-any': 0,
31+
// enforces 2 spaces indent
32+
indent: [
33+
'error',
34+
2,
35+
{
36+
SwitchCase: 1,
37+
VariableDeclarator: { var: 2, let: 2, const: 3 },
38+
outerIIFEBody: 1,
39+
MemberExpression: 1,
40+
FunctionDeclaration: { parameters: 1, body: 1 },
41+
FunctionExpression: { parameters: 1, body: 1 },
42+
CallExpression: { arguments: 1 },
43+
ArrayExpression: 1,
44+
ObjectExpression: 1,
45+
ImportDeclaration: 1,
46+
flatTernaryExpressions: false,
47+
ignoreComments: false,
48+
},
49+
],
50+
},
51+
env: {
52+
node: true,
53+
},
54+
};

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
]
3838
},
3939
"devDependencies": {
40+
"@typescript-eslint/eslint-plugin": "^4.9.1",
41+
"@typescript-eslint/parser": "^4.9.1",
42+
"eslint": "^7.15.0",
43+
"eslint-config-prettier": "^7.0.0",
44+
"eslint-plugin-prettier": "^3.2.0",
4045
"prettier": "^2.2.1"
4146
}
4247
}

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MainContentWrapper } from './components/MainContentWrapper/MainContentW
55
import { TabNavigation } from './components/TabNavigation/TabNavigation';
66
import { Tab } from './components/Tab/Tab';
77

8-
function App() {
8+
function App(): JSX.Element {
99
return (
1010
<div>
1111
<Header />

src/components/Header/Header.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ const useStyles = makeStyles({
6969
},
7070
});
7171

72-
export const Header = () => {
72+
export const Header = (): JSX.Element => {
7373
const [value, setValue] = React.useState(0);
7474

75-
const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => {
75+
const handleChange = (
76+
event: React.ChangeEvent<unknown>,
77+
newValue: number
78+
) => {
7679
setValue(newValue);
7780
};
7881

src/components/TabNavigation/TabNavigation.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export const TabNavigation: React.FC<TabNavigationProps> = (props) => {
3535
/**
3636
* Callback function required by the props "onChange" of the "Tabs" Material-UI component.
3737
*/
38-
const tabChangeHandler = (event: React.ChangeEvent<{}>, newValue: number) => {
38+
const tabChangeHandler = (
39+
event: React.ChangeEvent<unknown>,
40+
newValue: number
41+
) => {
3942
setValue(newValue);
4043
};
4144

src/serviceWorker.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ type Config = {
2525
onUpdate?: (registration: ServiceWorkerRegistration) => void;
2626
};
2727

28-
export function register(config?: Config) {
28+
export function register(config?: Config): void {
2929
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
3030
// The URL constructor is available in all browsers that support SW.
31-
const publicUrl = new URL(
32-
process.env.PUBLIC_URL,
33-
window.location.href
34-
);
31+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
3532
if (publicUrl.origin !== window.location.origin) {
3633
// Our service worker won't work if PUBLIC_URL is on a different origin
3734
// from what our page is served on. This might happen if a CDN is used to
@@ -65,7 +62,7 @@ export function register(config?: Config) {
6562
function registerValidSW(swUrl: string, config?: Config) {
6663
navigator.serviceWorker
6764
.register(swUrl)
68-
.then(registration => {
65+
.then((registration) => {
6966
registration.onupdatefound = () => {
7067
const installingWorker = registration.installing;
7168
if (installingWorker == null) {
@@ -101,25 +98,25 @@ function registerValidSW(swUrl: string, config?: Config) {
10198
};
10299
};
103100
})
104-
.catch(error => {
101+
.catch((error) => {
105102
console.error('Error during service worker registration:', error);
106103
});
107104
}
108105

109106
function checkValidServiceWorker(swUrl: string, config?: Config) {
110107
// Check if the service worker can be found. If it can't reload the page.
111108
fetch(swUrl, {
112-
headers: { 'Service-Worker': 'script' }
109+
headers: { 'Service-Worker': 'script' },
113110
})
114-
.then(response => {
111+
.then((response) => {
115112
// Ensure service worker exists, and that we really are getting a JS file.
116113
const contentType = response.headers.get('content-type');
117114
if (
118115
response.status === 404 ||
119116
(contentType != null && contentType.indexOf('javascript') === -1)
120117
) {
121118
// No service worker found. Probably a different app. Reload the page.
122-
navigator.serviceWorker.ready.then(registration => {
119+
navigator.serviceWorker.ready.then((registration) => {
123120
registration.unregister().then(() => {
124121
window.location.reload();
125122
});
@@ -136,13 +133,13 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
136133
});
137134
}
138135

139-
export function unregister() {
136+
export function unregister(): void {
140137
if ('serviceWorker' in navigator) {
141138
navigator.serviceWorker.ready
142-
.then(registration => {
139+
.then((registration) => {
143140
registration.unregister();
144141
})
145-
.catch(error => {
142+
.catch((error) => {
146143
console.error(error.message);
147144
});
148145
}

0 commit comments

Comments
 (0)