Skip to content

Commit ea0ca0d

Browse files
authored
feat: migrate to FlatConfig (#64)
1 parent 90c1854 commit ea0ca0d

File tree

5 files changed

+77
-31
lines changed

5 files changed

+77
-31
lines changed

eslint.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
module.exports = {
2-
extends: ['eslint:recommended', 'plugin:n/recommended'],
3-
plugins: ['n'],
1+
const nodePlugin = require('eslint-plugin-n');
2+
const eslintJs = require('@eslint/js');
3+
const globals = require('globals');
4+
5+
const commonConfig = {
6+
languageOptions: {
7+
globals: {
8+
...globals.node,
9+
...globals.es6,
10+
},
11+
},
412
rules: {
513
// override recommended
614
'no-empty': ['error', { allowEmptyCatch: true }],
@@ -133,8 +141,10 @@ module.exports = {
133141
'template-curly-spacing': 'error',
134142
'yield-star-spacing': 'error',
135143
},
136-
env: {
137-
node: true,
138-
es6: true
139-
}
140144
};
145+
146+
module.exports = [
147+
eslintJs.configs.recommended,
148+
nodePlugin.configs["flat/recommended-script"],
149+
commonConfig,
150+
];

package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@
1515
"ts.js",
1616
"ts-test.js"
1717
],
18+
"exports": {
19+
"./eslint": "./eslint.js",
20+
"./test": "./test.js",
21+
"./ts": "./ts.js",
22+
"./ts-test": "./ts-test.js"
23+
},
1824
"author": "Tommy Chen <[email protected]> (http://zespia.tw)",
1925
"maintainers": [
2026
"Abner Chou <[email protected]> (http://abnerchou.me)"
2127
],
2228
"license": "MIT",
2329
"peerDependencies": {
24-
"eslint": ">= 8.23.0"
30+
"eslint": ">= 9.17.0"
2531
},
2632
"dependencies": {
27-
"eslint-plugin-n": "^17.9.0",
28-
"@typescript-eslint/eslint-plugin": "^7.15.0",
29-
"@typescript-eslint/parser": "^7.15.0"
33+
"@eslint/js": "^9.17.0",
34+
"eslint-plugin-n": "^17.15.1",
35+
"globals": "^15.14.0",
36+
"typescript-eslint": "^8.19.0",
37+
"eslint-plugin-mocha": "^10.5.0"
3038
},
3139
"engines": {
3240
"node": ">=18"

test.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
module.exports = {
2-
extends: './eslint.js',
1+
const jsConfig = require('./eslint.js');
2+
const globals = require('globals');
3+
const mochaPlugin = require('eslint-plugin-mocha');
4+
5+
const testConfig = {
6+
...mochaPlugin.configs.flat.recommended,
7+
languageOptions: {
8+
globals: {
9+
...globals.mocha
10+
},
11+
},
312
rules: {
4-
'no-unused-expressions': 'off'
13+
'no-unused-expressions': 0,
14+
"mocha/no-mocha-arrows": 0,
15+
"mocha/handle-done-callback": 0,
16+
"mocha/max-top-level-suites": 0,
517
},
6-
env: {
7-
mocha: true
8-
}
918
};
19+
20+
module.exports = [
21+
...jsConfig,
22+
testConfig
23+
];

ts-test.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
module.exports = {
2-
extends: './ts.js',
1+
const tsConfig = require('./ts.js');
2+
const globals = require('globals');
3+
4+
const tsTestConfig = {
5+
languageOptions: {
6+
globals: {
7+
...globals.mocha
8+
},
9+
},
310
rules: {
411
'no-unused-expressions': 'off'
512
},
6-
env: {
7-
mocha: true
8-
}
913
};
14+
15+
module.exports = [
16+
...tsConfig,
17+
tsTestConfig,
18+
];

ts.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
module.exports = {
2-
parser: '@typescript-eslint/parser',
3-
plugins: ['@typescript-eslint'],
4-
extends: [
5-
'./eslint.js',
6-
'plugin:@typescript-eslint/recommended'
7-
],
1+
const tsEslint = require('typescript-eslint');
2+
const nodePlugin = require('eslint-plugin-n');
3+
const jsConfig = require('./eslint.js');
4+
5+
const nodeConfig = {
86
rules: {
97
'n/no-unsupported-features/es-syntax': ['error', { 'ignores': ['modules'] }],
108
'n/no-missing-import': ['error', { 'tryExtensions': ['.js', '.ts'] }]
11-
}
12-
};
9+
},
10+
}
11+
12+
module.exports = [].concat(
13+
jsConfig,
14+
nodePlugin.configs["flat/mixed-esm-and-cjs"],
15+
...tsEslint.configs.recommended,
16+
nodeConfig,
17+
);

0 commit comments

Comments
 (0)