Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to FlatConfig #64

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
24 changes: 17 additions & 7 deletions eslint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:n/recommended'],
plugins: ['n'],
const nodePlugin = require('eslint-plugin-n');
const eslintJs = require('@eslint/js');
const globals = require('globals');

const commonConfig = {
languageOptions: {
globals: {
...globals.node,
SukkaW marked this conversation as resolved.
Show resolved Hide resolved
...globals.es6,
},
},
rules: {
// override recommended
'no-empty': ['error', { allowEmptyCatch: true }],
Expand Down Expand Up @@ -133,8 +141,10 @@ module.exports = {
'template-curly-spacing': 'error',
'yield-star-spacing': 'error',
},
env: {
node: true,
es6: true
}
};

module.exports = [
eslintJs.configs.recommended,
nodePlugin.configs["flat/recommended-script"],
commonConfig,
];
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@
"ts.js",
"ts-test.js"
],
"exports": {
"./eslint": "./eslint.js",
"./test": "./test.js",
"./ts": "./ts.js",
"./ts-test": "./ts-test.js"
},
"author": "Tommy Chen <[email protected]> (http://zespia.tw)",
"maintainers": [
"Abner Chou <[email protected]> (http://abnerchou.me)"
],
"license": "MIT",
"peerDependencies": {
"eslint": ">= 8.23.0"
"eslint": ">= 9.13.0"
},
"dependencies": {
"eslint-plugin-n": "^17.9.0",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0"
"@eslint/js": "^9.13.0",
"eslint-plugin-n": "^17.12.0",
"globals": "^15.11.0",
"typescript-eslint": "^8.12.2",
"eslint-plugin-mocha": "^10.5.0"
},
"engines": {
"node": ">=18"
Expand Down
28 changes: 24 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
module.exports = {
extends: './eslint.js',
const eslint = require('./eslint.js');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such naming may be confusing

const globals = require('globals');
const mochaPlugin = require('eslint-plugin-mocha');

const testConfig = {
languageOptions: {
globals: {
...globals.mocha
},
},
rules: {
'no-unused-expressions': 'off'
},
env: {
mocha: true
};

const mochaConfig = {
...mochaPlugin.configs.flat.recommended,
rules: {
Copy link
Member

@uiolee uiolee Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will overwrite the rules in mochaPlugin.configs.flat.recommended, please make sure this meets your expectations

"mocha/no-mocha-arrows": 0,
"mocha/handle-done-callback": 0,
"mocha/max-top-level-suites": 0,
}
};

module.exports = [
...eslint,
testConfig,
mochaConfig,
];
19 changes: 14 additions & 5 deletions ts-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
module.exports = {
extends: './ts.js',
const tsJs = require('./ts.js');
const globals = require('globals');

const tsTestConfig = {
languageOptions: {
globals: {
...globals.mocha
},
},
rules: {
'no-unused-expressions': 'off'
},
env: {
mocha: true
}
};

module.exports = [
...tsJs,
tsTestConfig,
];
23 changes: 14 additions & 9 deletions ts.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'./eslint.js',
'plugin:@typescript-eslint/recommended'
],
const tseslint = require('typescript-eslint');
const nodePlugin = require('eslint-plugin-n');
const eslint = require('./eslint.js');

const nodeConfig = {
rules: {
'n/no-unsupported-features/es-syntax': ['error', { 'ignores': ['modules'] }],
'n/no-missing-import': ['error', { 'tryExtensions': ['.js', '.ts'] }]
}
};
},
}

module.exports = [].concat(
eslint,
nodePlugin.configs["flat/mixed-esm-and-cjs"],
...tseslint.configs.recommended,
nodeConfig,
);