Skip to content

Commit d334989

Browse files
committed
feat(eslint): remove usage of airbnb deprecated rules
1 parent 8ce47fe commit d334989

File tree

9 files changed

+655
-155
lines changed

9 files changed

+655
-155
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
"builtin-modules": "4.0.0",
3636
"cross-env": "7.0.3",
3737
"esbuild-plugin-browserslist": "0.15.0",
38-
"eslint": "9.13.0",
39-
"globals": "15.12.0",
38+
"eslint": "9.16.0",
39+
"globals": "15.13.0",
4040
"happy-dom": "15.11.7",
4141
"husky": "9.1.7",
4242
"lint-staged": "15.2.10",
4343
"mockdate": "3.0.5",
4444
"read-pkg": "9.0.1",
4545
"shx": "0.3.4",
4646
"tstyche": "3.0.0",
47-
"typescript": "5.6.3",
47+
"typescript": "5.7.2",
4848
"vite": "5.4.11",
4949
"vitest": "2.1.6",
5050
"vitest-localstorage-mock": "0.1.2",

packages/cookie-consent/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"cookie": "1.0.1"
4545
},
4646
"devDependencies": {
47-
"@types/cookie": "0.6.0",
4847
"react": "18.3.1",
4948
"@scaleway/use-segment": "workspace:*"
5049
},
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'
2+
import { FlatCompat } from '@eslint/eslintrc'
3+
import path from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
6+
const filename = fileURLToPath(import.meta.url)
7+
const dirname = path.dirname(filename)
8+
9+
const compat = new FlatCompat({
10+
baseDirectory: dirname,
11+
})
12+
13+
const config = compat.extends('airbnb-base')
14+
15+
const defaultAirBnbRules = [...fixupPluginRules(config)].reduce(
16+
(acc, curerntConfig) => ({
17+
...acc,
18+
...curerntConfig.rules,
19+
}),
20+
{},
21+
)
22+
23+
console.debug('defaultAirBnbRules', defaultAirBnbRules.semi)
24+
25+
export default [
26+
...fixupConfigRules(compat.extends('airbnb-base')),
27+
{
28+
rules: {
29+
// Replace Airbnb 'brace-style' rule with '@typescript-eslint' version
30+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/brace-style.md
31+
'brace-style': 'off',
32+
'@stylistic/ts/brace-style': defaultAirBnbRules['brace-style'],
33+
34+
// Replace Airbnb 'comma-dangle' rule with '@typescript-eslint' version
35+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-dangle.md
36+
// The TypeScript version also adds 3 new options, all of which should be set to the same value as the base config
37+
'comma-dangle': 'off',
38+
'@stylistic/ts/comma-dangle': [
39+
defaultAirBnbRules['comma-dangle'][0],
40+
{
41+
...defaultAirBnbRules['comma-dangle'][1],
42+
enums: defaultAirBnbRules['comma-dangle'][1].arrays,
43+
generics: defaultAirBnbRules['comma-dangle'][1].arrays,
44+
tuples: defaultAirBnbRules['comma-dangle'][1].arrays,
45+
},
46+
],
47+
48+
// Replace Airbnb 'comma-spacing' rule with '@typescript-eslint' version
49+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-spacing.md
50+
'comma-spacing': 'off',
51+
'@stylistic/ts/comma-spacing': defaultAirBnbRules['comma-spacing'],
52+
53+
// Replace Airbnb 'func-call-spacing' rule with '@typescript-eslint' version
54+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/func-call-spacing.md
55+
'func-call-spacing': 'off',
56+
'@stylistic/ts/func-call-spacing':
57+
defaultAirBnbRules['func-call-spacing'],
58+
59+
// Replace Airbnb 'indent' rule with '@typescript-eslint' version
60+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md
61+
indent: 'off',
62+
'@stylistic/ts/indent': defaultAirBnbRules.indent,
63+
64+
// Replace Airbnb 'keyword-spacing' rule with '@typescript-eslint' version
65+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/keyword-spacing.md
66+
'keyword-spacing': 'off',
67+
'@stylistic/ts/keyword-spacing': defaultAirBnbRules['keyword-spacing'],
68+
69+
// Replace Airbnb 'no-extra-semi' rule with '@typescript-eslint' version
70+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-semi.md
71+
'no-extra-semi': 'off',
72+
'@stylistic/ts/no-extra-semi': defaultAirBnbRules['no-extra-semi'],
73+
74+
// Replace Airbnb 'object-curly-spacing' rule with '@typescript-eslint' version
75+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/object-curly-spacing.md
76+
'object-curly-spacing': 'off',
77+
'@stylistic/ts/object-curly-spacing':
78+
defaultAirBnbRules['object-curly-spacing'],
79+
80+
// Replace Airbnb 'semi' rule with '@typescript-eslint' version
81+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/semi.md
82+
semi: 'off',
83+
'@stylistic/ts/semi': defaultAirBnbRules.semi,
84+
85+
// Replace Airbnb 'space-before-blocks' rule with '@typescript-eslint' version
86+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/space-before-blocks.md
87+
'space-before-blocks': 'off',
88+
'@stylistic/ts/space-before-blocks':
89+
defaultAirBnbRules['space-before-blocks'],
90+
91+
// Replace Airbnb 'space-before-function-paren' rule with '@typescript-eslint' version
92+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/space-before-function-paren.md
93+
'space-before-function-paren': 'off',
94+
'@stylistic/ts/space-before-function-paren':
95+
defaultAirBnbRules['space-before-function-paren'],
96+
97+
// Replace Airbnb 'space-infix-ops' rule with '@typescript-eslint' version
98+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/space-infix-ops.md
99+
'space-infix-ops': 'off',
100+
'@stylistic/ts/space-infix-ops': defaultAirBnbRules['space-infix-ops'],
101+
102+
// Replace Airbnb 'lines-between-class-members' rule with '@typescript-eslint' version
103+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/lines-between-class-members.md
104+
'lines-between-class-members': 'off',
105+
'@stylistic/ts/lines-between-class-members':
106+
defaultAirBnbRules['lines-between-class-members'],
107+
},
108+
},
109+
]
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'
2+
import { FlatCompat } from '@eslint/eslintrc'
3+
import path from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
6+
const filename = fileURLToPath(import.meta.url)
7+
const dirname = path.dirname(filename)
8+
9+
const compat = new FlatCompat({
10+
baseDirectory: dirname,
11+
})
12+
13+
const config = compat.extends('airbnb-base')
14+
15+
const defaultAirBnbRules = [...fixupPluginRules(config)].reduce(
16+
(acc, curerntConfig) => ({
17+
...acc,
18+
...curerntConfig.rules,
19+
}),
20+
{},
21+
)
22+
// console.debug(defaultAirBnbRules, defaultAirBnbRules['brace-style'])
23+
24+
export default [
25+
...fixupConfigRules(compat.extends('airbnb-base')),
26+
{
27+
rules: {
28+
// Replace Airbnb 'camelcase' rule with '@typescript-eslint/naming-convention'
29+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
30+
camelcase: 'off',
31+
// The `@typescript-eslint/naming-convention` rule allows `leadingUnderscore` and `trailingUnderscore` settings. However, the existing `no-underscore-dangle` rule already takes care of this.
32+
'@typescript-eslint/naming-convention': [
33+
'error',
34+
// Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables (23.10)
35+
{
36+
selector: 'variable',
37+
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
38+
},
39+
// Allow camelCase functions (23.2), and PascalCase functions (23.8)
40+
{
41+
selector: 'function',
42+
format: ['camelCase', 'PascalCase'],
43+
},
44+
// Airbnb recommends PascalCase for classes (23.3), and although Airbnb does not make TypeScript recommendations, we are assuming this rule would similarly apply to anything "type like", including interfaces, type aliases, and enums
45+
{
46+
selector: 'typeLike',
47+
format: ['PascalCase'],
48+
},
49+
],
50+
51+
// Replace Airbnb 'default-param-last' rule with '@typescript-eslint' version
52+
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/default-param-last.md
53+
'default-param-last': 'off',
54+
'@typescript-eslint/default-param-last':
55+
defaultAirBnbRules['default-param-last'],
56+
57+
// Replace Airbnb 'dot-notation' rule with '@typescript-eslint' version
58+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/dot-notation.md
59+
'dot-notation': 'off',
60+
'@typescript-eslint/dot-notation': defaultAirBnbRules['dot-notation'],
61+
62+
// Replace Airbnb 'no-array-constructor' rule with '@typescript-eslint' version
63+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md
64+
'no-array-constructor': 'off',
65+
'@typescript-eslint/no-array-constructor':
66+
defaultAirBnbRules['no-array-constructor'],
67+
68+
// Replace Airbnb 'no-dupe-class-members' rule with '@typescript-eslint' version
69+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
70+
'no-dupe-class-members': 'off',
71+
'@typescript-eslint/no-dupe-class-members':
72+
defaultAirBnbRules['no-dupe-class-members'],
73+
74+
// Replace Airbnb 'no-empty-function' rule with '@typescript-eslint' version
75+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
76+
'no-empty-function': 'off',
77+
'@typescript-eslint/no-empty-function':
78+
defaultAirBnbRules['no-empty-function'],
79+
80+
// Replace Airbnb 'no-extra-parens' rule with '@typescript-eslint' version
81+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-parens.md
82+
'no-extra-parens': 'off',
83+
'@typescript-eslint/no-extra-parens':
84+
defaultAirBnbRules['no-extra-parens'],
85+
86+
// Replace Airbnb 'no-implied-eval' and 'no-new-func' rules with '@typescript-eslint' version
87+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-implied-eval.md
88+
'no-implied-eval': 'off',
89+
'no-new-func': 'off',
90+
'@typescript-eslint/no-implied-eval':
91+
defaultAirBnbRules['no-implied-eval'],
92+
93+
// Replace Airbnb 'no-loss-of-precision' rule with '@typescript-eslint' version
94+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-loss-of-precision.md
95+
'no-loss-of-precision': 'off',
96+
'@typescript-eslint/no-loss-of-precision':
97+
defaultAirBnbRules['no-loss-of-precision'],
98+
99+
// Replace Airbnb 'no-loop-func' rule with '@typescript-eslint' version
100+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-loop-func.md
101+
'no-loop-func': 'off',
102+
'@typescript-eslint/no-loop-func': defaultAirBnbRules['no-loop-func'],
103+
104+
// Replace Airbnb 'no-magic-numbers' rule with '@typescript-eslint' version
105+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-magic-numbers.md
106+
'no-magic-numbers': 'off',
107+
'@typescript-eslint/no-magic-numbers':
108+
defaultAirBnbRules['no-magic-numbers'],
109+
110+
// Replace Airbnb 'no-redeclare' rule with '@typescript-eslint' version
111+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-redeclare.md
112+
'no-redeclare': 'off',
113+
'@typescript-eslint/no-redeclare': defaultAirBnbRules['no-redeclare'],
114+
115+
// Replace Airbnb 'no-shadow' rule with '@typescript-eslint' version
116+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
117+
'no-shadow': 'off',
118+
'@typescript-eslint/no-shadow': defaultAirBnbRules['no-shadow'],
119+
120+
// Replace Airbnb 'no-unused-expressions' rule with '@typescript-eslint' version
121+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
122+
'no-unused-expressions': 'off',
123+
'@typescript-eslint/no-unused-expressions':
124+
defaultAirBnbRules['no-unused-expressions'],
125+
126+
// Replace Airbnb 'no-unused-vars' rule with '@typescript-eslint' version
127+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
128+
'no-unused-vars': 'off',
129+
'@typescript-eslint/no-unused-vars': defaultAirBnbRules['no-unused-vars'],
130+
131+
// Replace Airbnb 'no-use-before-define' rule with '@typescript-eslint' version
132+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
133+
'no-use-before-define': 'off',
134+
'@typescript-eslint/no-use-before-define':
135+
defaultAirBnbRules['no-use-before-define'],
136+
137+
// Replace Airbnb 'no-useless-constructor' rule with '@typescript-eslint' version
138+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-useless-constructor.md
139+
'no-useless-constructor': 'off',
140+
'@typescript-eslint/no-useless-constructor':
141+
defaultAirBnbRules['no-useless-constructor'],
142+
143+
// Replace Airbnb 'quotes' rule with '@typescript-eslint' version
144+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/quotes.md
145+
quotes: 'off',
146+
// '@typescript-eslint/quotes': defaultAirBnbRules.quotes,
147+
148+
// Replace Airbnb 'require-await' rule with '@typescript-eslint' version
149+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/require-await.md
150+
'require-await': 'off',
151+
'@typescript-eslint/require-await': defaultAirBnbRules['require-await'],
152+
153+
// Replace Airbnb 'no-return-await' rule with '@typescript-eslint' version
154+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/return-await.md
155+
'no-return-await': 'off',
156+
'@typescript-eslint/return-await': [
157+
defaultAirBnbRules['no-return-await'],
158+
'in-try-catch',
159+
],
160+
161+
// Append 'ts' and 'tsx' to Airbnb 'import/extensions' rule
162+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
163+
'import/extensions': [
164+
defaultAirBnbRules['import/extensions'][0],
165+
defaultAirBnbRules['import/extensions'][1],
166+
{
167+
...defaultAirBnbRules['import/extensions'][2],
168+
ts: 'never',
169+
tsx: 'never',
170+
},
171+
],
172+
173+
// Append 'ts' and 'tsx' extensions to Airbnb 'import/no-extraneous-dependencies' rule
174+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
175+
'import/no-extraneous-dependencies': [
176+
defaultAirBnbRules['import/no-extraneous-dependencies'][0],
177+
{
178+
...defaultAirBnbRules['import/no-extraneous-dependencies'][1],
179+
devDependencies: defaultAirBnbRules[
180+
'import/no-extraneous-dependencies'
181+
][1].devDependencies.reduce((result, devDep) => {
182+
const toAppend = [devDep]
183+
const devDepWithTs = devDep.replace(/\bjs(x?)\b/g, 'ts$1')
184+
if (devDepWithTs !== devDep) {
185+
toAppend.push(devDepWithTs)
186+
}
187+
return [...result, ...toAppend]
188+
}, []),
189+
},
190+
],
191+
},
192+
},
193+
]

packages/eslint-config-react/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
"@emotion/eslint-plugin": "11.12.0",
3535
"@eslint/compat": "1.2.3",
3636
"@eslint/eslintrc": "3.2.0",
37-
"@typescript-eslint/eslint-plugin": "7.18.0",
38-
"@typescript-eslint/parser": "7.18.0",
37+
"@stylistic/eslint-plugin-js": "2.11.0",
38+
"@stylistic/eslint-plugin-ts": "2.11.0",
39+
"@typescript-eslint/eslint-plugin": "8.16.0",
40+
"@typescript-eslint/parser": "8.16.0",
3941
"eslint-config-airbnb": "19.0.4",
40-
"eslint-config-airbnb-typescript": "18.0.0",
4142
"eslint-config-prettier": "9.1.0",
4243
"eslint-plugin-deprecation": "3.0.0",
4344
"eslint-plugin-eslint-comments": "3.2.0",

packages/eslint-config-react/shared.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { fixupConfigRules } from '@eslint/compat'
22
import { FlatCompat } from '@eslint/eslintrc'
3+
import stylisticJs from '@stylistic/eslint-plugin-js'
34
import path from 'node:path'
45
import { fileURLToPath } from 'node:url'
56

@@ -20,6 +21,9 @@ export default [
2021
),
2122
),
2223
{
24+
plugins: {
25+
'@stylistic/js': stylisticJs,
26+
},
2327
rules: {
2428
curly: 'error',
2529

0 commit comments

Comments
 (0)