Skip to content

Commit 2dc0b2c

Browse files
committed
CH-147 Linting update in samples and templates
1 parent 4e9ff9c commit 2dc0b2c

9 files changed

Lines changed: 421 additions & 1081 deletions

File tree

application-templates/webapp/frontend/.eslintrc.cjs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
7+
8+
export default tseslint.config(
9+
{
10+
ignores: [
11+
'dist',
12+
'node_modules',
13+
'.yalc',
14+
'src/rest/*' // do not lint generated code
15+
]
16+
},
17+
{
18+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
19+
files: ['**/*.{ts,tsx,js,jsx}'],
20+
languageOptions: {
21+
ecmaVersion: "latest",
22+
globals: globals.browser,
23+
sourceType: "module"
24+
},
25+
plugins: {
26+
'react-hooks': reactHooks,
27+
'react-refresh': reactRefresh,
28+
},
29+
rules: {
30+
...reactHooks.configs.recommended.rules,
31+
'react-refresh/only-export-components': [
32+
'warn',
33+
{ allowConstantExport: true },
34+
],
35+
indent: ["error", 2, {
36+
SwitchCase: 1,
37+
}],
38+
curly: "error", // enforce braces for one-line blocks
39+
"no-tabs": "error", // enforce no tabs
40+
"no-console": ["warn", {
41+
allow: ["warn", "error", "debug"],
42+
}],
43+
"@typescript-eslint/no-explicit-any": "off", // No strict typing (annoying especially with React elements and events callbacks)
44+
"consistent-return": "warn", // https://eslint.org/docs/latest/rules/consistent-return
45+
"prefer-arrow-callback": ["warn"],
46+
"object-curly-spacing": ["warn", "always"], // enforce consistent spacing inside braces
47+
"func-style": "off", // function expressions or arrow functions are equally valid
48+
"no-unneeded-ternary": "warn", // disallow unnecessary ternary expressions
49+
// React rules: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules
50+
"react/prop-types": "off", // PropTypes are not forced
51+
"react/forbid-prop-types": "off", // all PropTypes are allowed
52+
"react-hooks/rules-of-hooks": "error", // https://react.dev/reference/rules/rules-of-hooks
53+
"react-hooks/exhaustive-deps": "warn", // Hooks dependency array, sometimes it's better to ignore
54+
},
55+
}
56+
)

application-templates/webapp/frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"start:dev": "DOMAIN=https://test.ch.metacell.us vite",
77
"start:local": "DOMAIN=http://samples.ch vite",
88
"prebuild": "eslint .",
9-
"build": "vite build"
9+
"build": "vite build",
10+
"lint": "eslint src --report-unused-disable-directives --fix"
1011
}
1112
}

applications/samples/frontend/.eslintrc.cjs

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
7+
8+
export default tseslint.config(
9+
{
10+
ignores: [
11+
'dist',
12+
'node_modules',
13+
'.yalc',
14+
'src/rest/*' // do not lint generated code
15+
]
16+
},
17+
{
18+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
19+
files: ['**/*.{ts,tsx,js,jsx}'],
20+
languageOptions: {
21+
ecmaVersion: "latest",
22+
globals: globals.browser,
23+
sourceType: "module"
24+
},
25+
plugins: {
26+
'react-hooks': reactHooks,
27+
'react-refresh': reactRefresh,
28+
},
29+
rules: {
30+
...reactHooks.configs.recommended.rules,
31+
'react-refresh/only-export-components': [
32+
'warn',
33+
{ allowConstantExport: true },
34+
],
35+
indent: ["error", 2, {
36+
SwitchCase: 1,
37+
}],
38+
curly: "error", // enforce braces for one-line blocks
39+
"no-tabs": "error", // enforce no tabs
40+
"no-console": ["warn", {
41+
allow: ["warn", "error", "debug"],
42+
}],
43+
"@typescript-eslint/no-explicit-any": "off", // No strict typing (annoying especially with React elements and events callbacks)
44+
"consistent-return": "warn", // https://eslint.org/docs/latest/rules/consistent-return
45+
"prefer-arrow-callback": ["warn"],
46+
"object-curly-spacing": ["warn", "always"], // enforce consistent spacing inside braces
47+
"func-style": "off", // function expressions or arrow functions are equally valid
48+
"no-unneeded-ternary": "warn", // disallow unnecessary ternary expressions
49+
// React rules: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules
50+
"react/prop-types": "off", // PropTypes are not forced
51+
"react/forbid-prop-types": "off", // all PropTypes are allowed
52+
"react-hooks/rules-of-hooks": "error", // https://react.dev/reference/rules/rules-of-hooks
53+
"react-hooks/exhaustive-deps": "warn", // Hooks dependency array, sometimes it's better to ignore
54+
},
55+
}
56+
)

applications/samples/frontend/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
"start": "DOMAIN=http://localhost:5000 vite",
99
"start:dev": "DOMAIN=https://test.ch.metacell.us vite",
1010
"start:local": "DOMAIN=http://samples.ch vite",
11-
"prebuild": "eslint .",
11+
"prebuild": "eslint src",
1212
"build": "vite build",
13-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
13+
"lint": "eslint src --report-unused-disable-directives --fix",
1414
"preview": "vite preview"
1515
},
1616
"dependencies": {
1717
"react": "^18.3.1",
1818
"react-dom": "^18.3.1"
1919
},
2020
"devDependencies": {
21-
"@types/node": "^22.0.0",
21+
"@eslint/js": "^9.9.0",
2222
"@types/react": "^18.3.3",
2323
"@types/react-dom": "^18.3.0",
24-
"@typescript-eslint/eslint-plugin": "^7.15.0",
25-
"@typescript-eslint/parser": "^7.15.0",
2624
"@vitejs/plugin-react": "^4.3.1",
27-
"eslint": "^8.57.0",
28-
"eslint-plugin-react-hooks": "^4.6.2",
29-
"eslint-plugin-react-refresh": "^0.4.7",
30-
"typescript": "^5.2.2",
31-
"vite": "^5.3.4"
25+
"eslint": "^9.9.0",
26+
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
27+
"eslint-plugin-react-refresh": "^0.4.9",
28+
"globals": "^15.9.0",
29+
"typescript": "^5.5.3",
30+
"typescript-eslint": "^8.0.1",
31+
"vite": "^5.4.1"
3232
}
3333
}

applications/samples/frontend/src/App.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import Version from './components/Version';
33

44

55
const Main = () => (
6-
<>
7-
<img src="/logo.png" width="800" />
8-
<h1>Sample React application is working!</h1>
9-
<Version />
10-
<RestTest />
11-
<p>See api documentation <a href="/api/ui/">here</a></p>
12-
</>
13-
)
6+
<>
7+
<img src="/logo.png" width="800" />
8+
<h1>Sample React application is working!</h1>
9+
<Version />
10+
<RestTest />
11+
<p>See api documentation <a href="/api/ui/">here</a></p>
12+
</>
13+
)
1414

1515

1616
export default Main;

applications/samples/frontend/vite.config.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ export default defineConfig(({ mode }) => {
2222

2323

2424
return {
25-
plugins: [react()],
26-
server: {
27-
port: 9000,
28-
proxy: {
29-
'/api/': {
30-
target: replaceHost( proxyTarget, 'samples'),
31-
secure: false,
32-
changeOrigin: true,
33-
},
34-
'/proxy/common/api': {
35-
target: replaceHost( proxyTarget, 'common'),
36-
secure: false,
37-
changeOrigin: true,
38-
rewrite: (path) => path.replace(/^\/proxy\/common\/api/, '/api')
25+
plugins: [react()],
26+
server: {
27+
port: 9000,
28+
proxy: {
29+
'/api/': {
30+
target: replaceHost( proxyTarget, 'samples'),
31+
secure: false,
32+
changeOrigin: true,
33+
},
34+
'/proxy/common/api': {
35+
target: replaceHost( proxyTarget, 'common'),
36+
secure: false,
37+
changeOrigin: true,
38+
rewrite: (path) => path.replace(/^\/proxy\/common\/api/, '/api')
39+
}
3940
}
40-
}
41-
}}}
41+
} }}
4242
)

0 commit comments

Comments
 (0)