Skip to content

Commit

Permalink
feat: migrate to FlatConfig (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin authored Jan 15, 2025
1 parent 90c1854 commit ea0ca0d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 31 deletions.
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,
...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.17.0"
},
"dependencies": {
"eslint-plugin-n": "^17.9.0",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0"
"@eslint/js": "^9.17.0",
"eslint-plugin-n": "^17.15.1",
"globals": "^15.14.0",
"typescript-eslint": "^8.19.0",
"eslint-plugin-mocha": "^10.5.0"
},
"engines": {
"node": ">=18"
Expand Down
26 changes: 20 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
module.exports = {
extends: './eslint.js',
const jsConfig = require('./eslint.js');
const globals = require('globals');
const mochaPlugin = require('eslint-plugin-mocha');

const testConfig = {
...mochaPlugin.configs.flat.recommended,
languageOptions: {
globals: {
...globals.mocha
},
},
rules: {
'no-unused-expressions': 'off'
'no-unused-expressions': 0,
"mocha/no-mocha-arrows": 0,
"mocha/handle-done-callback": 0,
"mocha/max-top-level-suites": 0,
},
env: {
mocha: true
}
};

module.exports = [
...jsConfig,
testConfig
];
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 tsConfig = require('./ts.js');
const globals = require('globals');

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

module.exports = [
...tsConfig,
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 jsConfig = 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(
jsConfig,
nodePlugin.configs["flat/mixed-esm-and-cjs"],
...tsEslint.configs.recommended,
nodeConfig,
);

0 comments on commit ea0ca0d

Please sign in to comment.