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

Merged
merged 17 commits into from
Jan 15, 2025
27 changes: 20 additions & 7 deletions eslint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:n/recommended'],
plugins: ['n'],
import nodePlugin from 'eslint-plugin-n';
import eslintJs from '@eslint/js';
import globals from 'globals';

const commonConfig = {
languageOptions: {
globals: {
...globals.node,
...globals.es6,
},
},
plugins: {
nodePlugin,
},
rules: {
// override recommended
'no-empty': ['error', { allowEmptyCatch: true }],
Expand Down Expand Up @@ -133,8 +144,10 @@ module.exports = {
'template-curly-spacing': 'error',
'yield-star-spacing': 'error',
},
env: {
node: true,
es6: true
}
};

export default [
eslintJs.configs.recommended,
...nodePlugin.configs.recommended,
commonConfig,
];
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
],
"license": "MIT",
"peerDependencies": {
"eslint": ">= 8.23.0"
"eslint": ">= 9.10.0"
},
"dependencies": {
"eslint-plugin-n": "^17.9.0",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0"
"@eslint/js": "^9.10.0",
"eslint-plugin-n": "^17.10.3",
"globals": "^15.9.0",
"typescript-eslint": "^8.6.0"
Copy link
Member

@SukkaW SukkaW Sep 21, 2024

Choose a reason for hiding this comment

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

Since we are creating new presets, it is a good chance for us to add a few more presets. E.g. we could add https://www.npmjs.com/package/eslint-plugin-mocha since almost all Hexo repos use mocha.

Note that we might need to disable a few rules (E.g. mocha/no-mocha-arrows since we all use arrow functions).

Copy link
Member

@uiolee uiolee Oct 4, 2024

Choose a reason for hiding this comment

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

need "type": "module", or name js file to mjs

Oops! Something went wrong! :(

ESLint: 9.11.1

/home/user/eslint-config-hexo/eslint.js:1
import nodePlugin from 'eslint-plugin-n';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)

Copy link
Member

@SukkaW SukkaW Oct 4, 2024

Choose a reason for hiding this comment

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

Then keep using const = require then. In the ESLint world, CommonJS is still the first-class citizen.

},
"engines": {
"node": ">=18"
Expand Down
19 changes: 14 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
module.exports = {
extends: './eslint.js',
import eslint from './eslint';
import globals from 'globals';

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

export default [
eslint,
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',
import tsJs from './tsts';
import globals from 'globals';

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

export default [
tsJs,
tsTestConfig,
];
35 changes: 26 additions & 9 deletions ts.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'./eslint.js',
'plugin:@typescript-eslint/recommended'
],
import tseslint from 'typescript-eslint';
import nodePlugin from 'eslint-plugin-n';
import eslint from './eslint';

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

const tslintConfig = tseslint.config({
plugins: {
'@typescript-eslint': tseslint.plugin,
},
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: true,
},
},
});

export default [
eslint,
...nodePlugin.configs["flat/mixed-esm-and-cjs"],
tslintConfig,
nodeConfig,
];