@@ -5,6 +5,25 @@ import path from 'node:path'
55import { fileURLToPath } from 'node:url'
66import shared from './shared.mjs'
77
8+ /* eslint-disable import/no-extraneous-dependencies */
9+ const {
10+ rules : baseBestPracticesRules ,
11+ } = require ( 'eslint-config-airbnb-base/rules/best-practices' )
12+ const {
13+ rules : baseErrorsRules ,
14+ } = require ( 'eslint-config-airbnb-base/rules/errors' )
15+ const { rules : baseES6Rules } = require ( 'eslint-config-airbnb-base/rules/es6' )
16+ const {
17+ rules : baseImportsRules ,
18+ } = require ( 'eslint-config-airbnb-base/rules/imports' )
19+ const {
20+ rules : baseStyleRules ,
21+ } = require ( 'eslint-config-airbnb-base/rules/style' )
22+ const {
23+ rules : baseVariablesRules ,
24+ } = require ( 'eslint-config-airbnb-base/rules/variables' )
25+ /* eslint-enable import/no-extraneous-dependencies */
26+
827const filename = fileURLToPath ( import . meta. url )
928const dirname = path . dirname ( filename )
1029
@@ -16,7 +35,7 @@ export default [
1635 ...fixupConfigRules (
1736 compat . extends (
1837 'eslint-config-airbnb' ,
19- 'eslint-config-airbnb-typescript' ,
38+ // 'eslint-config-airbnb-typescript',
2039 'plugin:@typescript-eslint/recommended' ,
2140 'plugin:@typescript-eslint/recommended-requiring-type-checking' ,
2241 ) ,
@@ -72,6 +91,218 @@ export default [
7291 allowExpressions : true ,
7392 } ,
7493 ] ,
94+ // Replace Airbnb 'brace-style' rule with '@typescript-eslint' version
95+ 'brace-style' : 'off' ,
96+ '@typescript-eslint/brace-style' : baseStyleRules [ 'brace-style' ] ,
97+
98+ // Replace Airbnb 'camelcase' rule with '@typescript-eslint/naming-convention'
99+ camelcase : 'off' ,
100+ // The `@typescript-eslint/naming-convention` rule allows `leadingUnderscore` and `trailingUnderscore` settings. However, the existing `no-underscore-dangle` rule already takes care of this.
101+ '@typescript-eslint/naming-convention' : [
102+ 'error' ,
103+ // Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables (23.10)
104+ {
105+ selector : 'variable' ,
106+ format : [ 'camelCase' , 'PascalCase' , 'UPPER_CASE' ] ,
107+ } ,
108+ // Allow camelCase functions (23.2), and PascalCase functions (23.8)
109+ {
110+ selector : 'function' ,
111+ format : [ 'camelCase' , 'PascalCase' ] ,
112+ } ,
113+ // 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
114+ {
115+ selector : 'typeLike' ,
116+ format : [ 'PascalCase' ] ,
117+ } ,
118+ ] ,
119+
120+ // Replace Airbnb 'comma-dangle' rule with '@typescript-eslint' version
121+ // The TypeScript version also adds 3 new options, all of which should be set to the same value as the base config
122+ 'comma-dangle' : 'off' ,
123+ '@typescript-eslint/comma-dangle' : [
124+ baseStyleRules [ 'comma-dangle' ] [ 0 ] ,
125+ {
126+ ...baseStyleRules [ 'comma-dangle' ] [ 1 ] ,
127+ enums : baseStyleRules [ 'comma-dangle' ] [ 1 ] . arrays ,
128+ generics : baseStyleRules [ 'comma-dangle' ] [ 1 ] . arrays ,
129+ tuples : baseStyleRules [ 'comma-dangle' ] [ 1 ] . arrays ,
130+ } ,
131+ ] ,
132+
133+ // Replace Airbnb 'comma-spacing' rule with '@typescript-eslint' version
134+ 'comma-spacing' : 'off' ,
135+ '@typescript-eslint/comma-spacing' : baseStyleRules [ 'comma-spacing' ] ,
136+
137+ // Replace Airbnb 'default-param-last' rule with '@typescript-eslint' version
138+ 'default-param-last' : 'off' ,
139+ '@typescript-eslint/default-param-last' :
140+ baseBestPracticesRules [ 'default-param-last' ] ,
141+
142+ // Replace Airbnb 'dot-notation' rule with '@typescript-eslint' version
143+ 'dot-notation' : 'off' ,
144+ '@typescript-eslint/dot-notation' : baseBestPracticesRules [ 'dot-notation' ] ,
145+
146+ // Replace Airbnb 'func-call-spacing' rule with '@typescript-eslint' version
147+ 'func-call-spacing' : 'off' ,
148+ '@typescript-eslint/func-call-spacing' :
149+ baseStyleRules [ 'func-call-spacing' ] ,
150+
151+ // Replace Airbnb 'indent' rule with '@typescript-eslint' version
152+ indent : 'off' ,
153+ '@typescript-eslint/indent' : baseStyleRules . indent ,
154+
155+ // Replace Airbnb 'keyword-spacing' rule with '@typescript-eslint' version
156+ 'keyword-spacing' : 'off' ,
157+ '@typescript-eslint/keyword-spacing' : baseStyleRules [ 'keyword-spacing' ] ,
158+
159+ // Replace Airbnb 'lines-between-class-members' rule with '@typescript-eslint' version
160+ 'lines-between-class-members' : 'off' ,
161+ '@typescript-eslint/lines-between-class-members' :
162+ baseStyleRules [ 'lines-between-class-members' ] ,
163+
164+ // Replace Airbnb 'no-array-constructor' rule with '@typescript-eslint' version
165+ 'no-array-constructor' : 'off' ,
166+ '@typescript-eslint/no-array-constructor' :
167+ baseStyleRules [ 'no-array-constructor' ] ,
168+
169+ // Replace Airbnb 'no-dupe-class-members' rule with '@typescript-eslint' version
170+ 'no-dupe-class-members' : 'off' ,
171+ '@typescript-eslint/no-dupe-class-members' :
172+ baseES6Rules [ 'no-dupe-class-members' ] ,
173+
174+ // Replace Airbnb 'no-empty-function' rule with '@typescript-eslint' version
175+ 'no-empty-function' : 'off' ,
176+ '@typescript-eslint/no-empty-function' :
177+ baseBestPracticesRules [ 'no-empty-function' ] ,
178+
179+ // Replace Airbnb 'no-extra-parens' rule with '@typescript-eslint' version
180+ 'no-extra-parens' : 'off' ,
181+ '@typescript-eslint/no-extra-parens' : baseErrorsRules [ 'no-extra-parens' ] ,
182+
183+ // Replace Airbnb 'no-extra-semi' rule with '@typescript-eslint' version
184+ 'no-extra-semi' : 'off' ,
185+ '@typescript-eslint/no-extra-semi' : baseErrorsRules [ 'no-extra-semi' ] ,
186+
187+ // Replace Airbnb 'no-implied-eval' and 'no-new-func' rules with '@typescript-eslint' version
188+ 'no-implied-eval' : 'off' ,
189+ 'no-new-func' : 'off' ,
190+ '@typescript-eslint/no-implied-eval' :
191+ baseBestPracticesRules [ 'no-implied-eval' ] ,
192+
193+ // Replace Airbnb 'no-loss-of-precision' rule with '@typescript-eslint' version
194+ 'no-loss-of-precision' : 'off' ,
195+ '@typescript-eslint/no-loss-of-precision' :
196+ baseErrorsRules [ 'no-loss-of-precision' ] ,
197+
198+ // Replace Airbnb 'no-loop-func' rule with '@typescript-eslint' version
199+ 'no-loop-func' : 'off' ,
200+ '@typescript-eslint/no-loop-func' : baseBestPracticesRules [ 'no-loop-func' ] ,
201+
202+ // Replace Airbnb 'no-magic-numbers' rule with '@typescript-eslint' version
203+ 'no-magic-numbers' : 'off' ,
204+ '@typescript-eslint/no-magic-numbers' :
205+ baseBestPracticesRules [ 'no-magic-numbers' ] ,
206+
207+ // Replace Airbnb 'no-redeclare' rule with '@typescript-eslint' version
208+ 'no-redeclare' : 'off' ,
209+ '@typescript-eslint/no-redeclare' : baseBestPracticesRules [ 'no-redeclare' ] ,
210+
211+ // Replace Airbnb 'no-shadow' rule with '@typescript-eslint' version
212+ 'no-shadow' : 'off' ,
213+ '@typescript-eslint/no-shadow' : baseVariablesRules [ 'no-shadow' ] ,
214+
215+ // Replace Airbnb 'space-before-blocks' rule with '@typescript-eslint' version
216+ 'space-before-blocks' : 'off' ,
217+ '@typescript-eslint/space-before-blocks' :
218+ baseStyleRules [ 'space-before-blocks' ] ,
219+
220+ // Replace Airbnb 'no-throw-literal' rule with '@typescript-eslint' version
221+ 'no-throw-literal' : 'off' ,
222+ '@typescript-eslint/no-throw-literal' :
223+ baseBestPracticesRules [ 'no-throw-literal' ] ,
224+
225+ // Replace Airbnb 'no-unused-expressions' rule with '@typescript-eslint' version
226+ 'no-unused-expressions' : 'off' ,
227+ '@typescript-eslint/no-unused-expressions' :
228+ baseBestPracticesRules [ 'no-unused-expressions' ] ,
229+
230+ // Replace Airbnb 'no-unused-vars' rule with '@typescript-eslint' version
231+ 'no-unused-vars' : 'off' ,
232+ '@typescript-eslint/no-unused-vars' : baseVariablesRules [ 'no-unused-vars' ] ,
233+
234+ // Replace Airbnb 'no-use-before-define' rule with '@typescript-eslint' version
235+ 'no-use-before-define' : 'off' ,
236+ '@typescript-eslint/no-use-before-define' :
237+ baseVariablesRules [ 'no-use-before-define' ] ,
238+
239+ // Replace Airbnb 'no-useless-constructor' rule with '@typescript-eslint' version
240+ 'no-useless-constructor' : 'off' ,
241+ '@typescript-eslint/no-useless-constructor' :
242+ baseES6Rules [ 'no-useless-constructor' ] ,
243+
244+ // Replace Airbnb 'quotes' rule with '@typescript-eslint' version
245+ quotes : 'off' ,
246+ '@typescript-eslint/quotes' : baseStyleRules . quotes ,
247+
248+ // Replace Airbnb 'semi' rule with '@typescript-eslint' version
249+ semi : 'off' ,
250+ '@typescript-eslint/semi' : baseStyleRules . semi ,
251+
252+ // Replace Airbnb 'space-before-function-paren' rule with '@typescript-eslint' version
253+ 'space-before-function-paren' : 'off' ,
254+ '@typescript-eslint/space-before-function-paren' :
255+ baseStyleRules [ 'space-before-function-paren' ] ,
256+
257+ // Replace Airbnb 'require-await' rule with '@typescript-eslint' version
258+ 'require-await' : 'off' ,
259+ '@typescript-eslint/require-await' :
260+ baseBestPracticesRules [ 'require-await' ] ,
261+
262+ // Replace Airbnb 'no-return-await' rule with '@typescript-eslint' version
263+ 'no-return-await' : 'off' ,
264+ '@typescript-eslint/return-await' : [
265+ baseBestPracticesRules [ 'no-return-await' ] ,
266+ 'in-try-catch' ,
267+ ] ,
268+
269+ // Replace Airbnb 'space-infix-ops' rule with '@typescript-eslint' version
270+ 'space-infix-ops' : 'off' ,
271+ '@typescript-eslint/space-infix-ops' : baseStyleRules [ 'space-infix-ops' ] ,
272+
273+ // Replace Airbnb 'object-curly-spacing' rule with '@typescript-eslint' version
274+ 'object-curly-spacing' : 'off' ,
275+ '@typescript-eslint/object-curly-spacing' :
276+ baseStyleRules [ 'object-curly-spacing' ] ,
277+
278+ // Append 'ts' and 'tsx' to Airbnb 'import/extensions' rule
279+ 'import/extensions' : [
280+ baseImportsRules [ 'import/extensions' ] [ 0 ] ,
281+ baseImportsRules [ 'import/extensions' ] [ 1 ] ,
282+ {
283+ ...baseImportsRules [ 'import/extensions' ] [ 2 ] ,
284+ ts : 'never' ,
285+ tsx : 'never' ,
286+ } ,
287+ ] ,
288+
289+ // Append 'ts' and 'tsx' extensions to Airbnb 'import/no-extraneous-dependencies' rule
290+ 'import/no-extraneous-dependencies' : [
291+ baseImportsRules [ 'import/no-extraneous-dependencies' ] [ 0 ] ,
292+ {
293+ ...baseImportsRules [ 'import/no-extraneous-dependencies' ] [ 1 ] ,
294+ devDependencies : baseImportsRules [
295+ 'import/no-extraneous-dependencies'
296+ ] [ 1 ] . devDependencies . reduce ( ( result , devDep ) => {
297+ const toAppend = [ devDep ]
298+ const devDepWithTs = devDep . replace ( / \b j s ( x ? ) \b / g, 'ts$1' )
299+ if ( devDepWithTs !== devDep ) {
300+ toAppend . push ( devDepWithTs )
301+ }
302+ return [ ...result , ...toAppend ]
303+ } , [ ] ) ,
304+ } ,
305+ ] ,
75306 } ,
76307 } ,
77308]
0 commit comments