build: update eslint config antfu

This commit is contained in:
AkaraChen 2024-10-21 16:21:12 +08:00
parent f4f11135d3
commit 2094c54951
3 changed files with 1638 additions and 603 deletions

View File

@ -1,3 +1,4 @@
import { stylistic, typescript, combine, javascript } from '@antfu/eslint-config'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
@ -11,45 +12,91 @@ const compat = new FlatCompat({
allConfig: js.configs.all,
})
const ignores = [
'**/node_modules/*',
'**/node_modules/',
'**/dist/',
'**/build/',
'**/out/',
'**/.next/',
// TODO: remove this
'**/*.json',
'**/*.md',
]
const backup = {
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-var-requires': 'off',
'no-console': 'off',
'indent': 'off',
'@typescript-eslint/indent': ['error', 2, {
SwitchCase: 1,
flatTernaryExpressions: false,
ignoredNodes: [
'PropertyDefinition[decorators]',
'TSUnionType',
'FunctionExpression[params]:has(Identifier[decorators])',
],
}],
'react-hooks/exhaustive-deps': 'warn',
'react/display-name': 'warn',
// storybook plugin not support v9, so add its recommended rules here
const storybook = [
{
plugins: ['storybook'],
files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: {
'react-hooks/rules-of-hooks': 'off',
'import/no-anonymous-default-export': 'off',
'storybook/await-interactions': 'error',
'storybook/context-in-play-function': 'error',
'storybook/default-exports': 'error',
'storybook/hierarchy-separator': 'warn',
'storybook/no-redundant-story-name': 'warn',
'storybook/prefer-pascal-case': 'warn',
'storybook/story-exports': 'error',
'storybook/use-storybook-expect': 'error',
'storybook/use-storybook-testing-library': 'error',
}
},
}
const config = [
{ ignores },
...compat.extends('next', '@antfu', 'plugin:storybook/recommended'),
backup,
{
plugins: ['storybook'],
files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: {
'storybook/no-uninstalled-addons': 'error',
}
}
]
export default config
export default combine(
stylistic({
lessOpinionated: true,
// original @antfu/eslint-config does not support jsx
jsx: false,
overrides: {
"style/indent": "off",
// these options does not exist in old version
"style/indent-binary-ops": "off",
"style/multiline-ternary": "off",
// big change
"style/quote-props": "off",
"style/member-delimiter-style": "off",
"style/quotes": "off",
"style/comma-dangle": "off",
}
}),
typescript({
overrides: {
// useful, but big change
"ts/no-empty-object-type": "off",
}
}),
// javascript(),
// TODO: remove this when upgrade to nextjs 15
compat.extends('next'),
{
ignores: [
'**/node_modules/*',
'**/node_modules/',
'**/dist/',
'**/build/',
'**/out/',
'**/.next/',
'**/public/*',
'**/*.json',
]
},
{
// orignal config
rules: {
'ts/consistent-type-definitions': ['error', 'type'],
'ts/no-require-imports': 'off',
"no-console": 'off',
"react-hooks/exhaustive-deps": "warn",
"react/display-name": "off",
"curly": "off",
}
},
storybook,
// need futher research
{
rules: {
// not exist in old version
"antfu/consistent-list-newline": "off"
}
}
)

View File

@ -108,7 +108,7 @@
"zustand": "^4.5.2"
},
"devDependencies": {
"@antfu/eslint-config": "^0.36.0",
"@antfu/eslint-config": "^3.8.0",
"@chromatic-com/storybook": "^1.9.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
@ -147,8 +147,8 @@
"bing-translate-api": "^4.0.2",
"code-inspector-plugin": "^0.13.0",
"cross-env": "^7.0.3",
"eslint": "^8.36.0",
"eslint-config-next": "^14.0.4",
"eslint": "^9.10.0",
"eslint-config-next": "^15.0.0-canary.202",
"eslint-plugin-storybook": "^0.9.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
@ -161,7 +161,10 @@
"tailwindcss": "^3.4.4",
"ts-node": "^10.9.2",
"typescript": "4.9.5",
"uglify-js": "^3.17.4"
"uglify-js": "^3.17.4",
"@eslint-react/eslint-plugin": "^1.15.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.12"
},
"resolutions": {
"@types/react": "~18.2.0",
@ -176,4 +179,4 @@
"eslint --fix"
]
}
}
}

File diff suppressed because it is too large Load Diff