Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.
0544bdd

Personally, I think it would be better to rename the file itself from eslint.js. If we were to align it with other file names, it would be js.js, but I don't think that’s a good choice for naming.

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this override is correct. I read the rules in README and configured the overrides to ignore specific settings in our test code. For example, we use allow functions in our test code, but in the eslint-plugin-mocha recommended configuration, this is a warning by default.

"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,
);