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 path from 'node:path'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import js from '@eslint/js' import js from '@eslint/js'
@ -11,45 +12,91 @@ const compat = new FlatCompat({
allConfig: js.configs.all, allConfig: js.configs.all,
}) })
const ignores = [ // storybook plugin not support v9, so add its recommended rules here
'**/node_modules/*', const storybook = [
'**/node_modules/', {
'**/dist/', plugins: ['storybook'],
'**/build/', files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
'**/out/', rules: {
'**/.next/', 'react-hooks/rules-of-hooks': 'off',
// TODO: remove this 'import/no-anonymous-default-export': 'off',
'**/*.json', 'storybook/await-interactions': 'error',
'**/*.md', 'storybook/context-in-play-function': 'error',
] 'storybook/default-exports': 'error',
'storybook/hierarchy-separator': 'warn',
const backup = { 'storybook/no-redundant-story-name': 'warn',
rules: { 'storybook/prefer-pascal-case': 'warn',
'@typescript-eslint/consistent-type-definitions': ['error', 'type'], 'storybook/story-exports': 'error',
'@typescript-eslint/no-var-requires': 'off', 'storybook/use-storybook-expect': 'error',
'no-console': 'off', 'storybook/use-storybook-testing-library': 'error',
'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',
}, },
} {
plugins: ['storybook'],
const config = [ files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
{ ignores }, rules: {
...compat.extends('next', '@antfu', 'plugin:storybook/recommended'), 'storybook/no-uninstalled-addons': 'error',
backup, }
}
] ]
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" "zustand": "^4.5.2"
}, },
"devDependencies": { "devDependencies": {
"@antfu/eslint-config": "^0.36.0", "@antfu/eslint-config": "^3.8.0",
"@chromatic-com/storybook": "^1.9.0", "@chromatic-com/storybook": "^1.9.0",
"@eslint/eslintrc": "^3.1.0", "@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0", "@eslint/js": "^9.13.0",
@ -147,8 +147,8 @@
"bing-translate-api": "^4.0.2", "bing-translate-api": "^4.0.2",
"code-inspector-plugin": "^0.13.0", "code-inspector-plugin": "^0.13.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "^8.36.0", "eslint": "^9.10.0",
"eslint-config-next": "^14.0.4", "eslint-config-next": "^15.0.0-canary.202",
"eslint-plugin-storybook": "^0.9.0", "eslint-plugin-storybook": "^0.9.0",
"husky": "^8.0.3", "husky": "^8.0.3",
"jest": "^29.7.0", "jest": "^29.7.0",
@ -161,7 +161,10 @@
"tailwindcss": "^3.4.4", "tailwindcss": "^3.4.4",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"typescript": "4.9.5", "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": { "resolutions": {
"@types/react": "~18.2.0", "@types/react": "~18.2.0",
@ -176,4 +179,4 @@
"eslint --fix" "eslint --fix"
] ]
} }
} }

File diff suppressed because it is too large Load Diff