Skip to content

Commit

Permalink
feat(eslint): 适配支持 ESLint V9 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed Apr 9, 2024
1 parent 96f3e73 commit 7534c56
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 29 deletions.
58 changes: 58 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// module.exports = [
// ...require('./preset/eslint'),
// ];
const path = require('path');
const eslint = require('@eslint/js');
const tseslint = require('typescript-eslint');

module.exports = [
...tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
tsconfigRootDir: path.resolve(__dirname),
project: './tsconfig.eslint.json',
projectFolderIgnoreList: ['**/node_modules/**', '**/dist/**'],
warnOnUnsupportedTypeScriptVersion: false,
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2023,
sourceType: 'module',
},
},
plugins: {
prettier: require('eslint-plugin-prettier'),
unicorn: require('eslint-plugin-unicorn'),
},
ignores: ['**/node_modules/**', 'dist/**', 'cjs/**', 'esm/**', 'docs/**', 'mock/**', '**/*.js', '**/*.d.ts'],
rules: {
'prettier/prettier': 'warn',
indent: ['off', 2],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { varsIgnorePattern: '^_', argsIgnorePattern: '^_', ignoreRestSiblings: true }],
// TODO
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/await-thenable': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/no-await-expression-member': 'off',
},
files: ['src/**/*.ts'],
},
{
files: ['*.js', '*.cjs', '*.mjs'],
...tseslint.configs.disableTypeChecked,
}
),
];
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,41 @@
"bin"
],
"dependencies": {
"@lzwme/fe-utils": "^1.6.0",
"commander": "^11.1.0",
"@lzwme/fe-utils": "^1.7.2",
"commander": "^12.0.0",
"console-log-colors": "^0.4.0",
"enquirer": "^2.4.1",
"fast-glob": "^3.3.2",
"micromatch": "^4.0.5"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@jest/core": "^29.7.0",
"@jest/test-result": "^29.7.0",
"@jest/types": "^29.6.3",
"@node-rs/deno-lint": "^1.19.0",
"@types/eslint": "^8.56.2",
"@types/jest": "^29.5.11",
"@node-rs/deno-lint": "^1.20.1",
"@types/eslint": "^8.56.7",
"@types/jest": "^29.5.12",
"@types/micromatch": "^4.0.6",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"@types/node": "^20.12.6",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-jest": "^28.2.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^50.0.1",
"husky": "^8.0.3",
"eslint-plugin-unicorn": "^52.0.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.4",
"prettier": "^3.2.5",
"standard-version": "^9.5.0",
"stylelint": "^16.1.0",
"ts-jest": "^29.1.1",
"stylelint": "^16.3.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typedoc": "^0.25.7",
"typescript": "^5.3.3"
"typedoc": "^0.25.13",
"typescript": "^5.4.4",
"typescript-eslint": "^7.6.0"
},
"peerDependencies": {
"@jest/core": "*"
Expand Down
18 changes: 12 additions & 6 deletions preset/eslint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { assign } = require('@lzwme/fe-utils');
// const { assign } = require('@lzwme/fe-utils');
const { existsSync } = require('node:fs');
const { resolve } = require('node:path');
const antdBoolean = ['visible', 'confirmLoading', 'closable', 'centered', 'maskClosable', 'forceRender', 'destroyOnClose'];
Expand All @@ -9,7 +9,7 @@ const eslint = {
commonjs: true,
es6: true,
node: true,
es2021: true,
es2022: true,
},
globals: {
Atomics: 'readonly',
Expand Down Expand Up @@ -184,8 +184,8 @@ if (existsSync(pkgFile)) {
pragma: 'React',
version: 'detect',
};
eslint.extends.push('plugin:react-hooks/recommended', 'plugin:jsx-a11y/recommended');
eslint.plugins.push('jsx-a11y', 'react');
eslint.extends.push('plugin:react-hooks/recommended');
eslint.plugins.push('react');
eslint.overrides.push({
// 3) Now we enable eslint-plugin-testing-library rules or preset only for matching files!
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
Expand Down Expand Up @@ -241,8 +241,13 @@ if (existsSync(pkgFile)) {
'react/jsx-boolean-value': 'error',

'testing-library/no-node-access': 'off',
});
}

// ====== jsx-a11y =======
if (pkgDeps['eslint-plugin-jsx-a11y']) {
eslint.extends.push('plugin:jsx-a11y/recommended');
eslint.plugins.push('jsx-a11y');
Object.assign(eslint.rules, {
'jsx-a11y/tabindex-no-positive': 'warn',
'jsx-a11y/label-has-associated-control': 'warn',
'jsx-a11y/no-autofocus': [
Expand Down Expand Up @@ -367,4 +372,5 @@ if (existsSync(pkgFile)) {
}
}

module.exports = eslint;
const { ESLint } = require('eslint');
module.exports = +ESLint.version.split('.')[0] < 9 ? eslint : require('./eslint.v9.js');
Loading

0 comments on commit 7534c56

Please sign in to comment.