build: fix eslint stylistic

pull/9940/head
AkaraChen 2 years ago
parent 510ce057f7
commit 4873e6e2a1

@ -1,7 +1,7 @@
import { import {
GLOB_JSX, GLOB_TESTS, GLOB_TSX, combine, javascript, node, GLOB_TESTS, combine, javascript, node,
stylistic, typescript, unicorn stylistic, typescript, unicorn,
} from '@antfu/eslint-config' } 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'
@ -21,27 +21,27 @@ const storybook = [
{ {
plugins: ['storybook'], plugins: ['storybook'],
files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'], files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: { rules: {
'react-hooks/rules-of-hooks': 'off', 'react-hooks/rules-of-hooks': 'off',
'import/no-anonymous-default-export': 'off', 'import/no-anonymous-default-export': 'off',
'storybook/await-interactions': 'error', 'storybook/await-interactions': 'error',
'storybook/context-in-play-function': 'error', 'storybook/context-in-play-function': 'error',
'storybook/default-exports': 'error', 'storybook/default-exports': 'error',
'storybook/hierarchy-separator': 'warn', 'storybook/hierarchy-separator': 'warn',
'storybook/no-redundant-story-name': 'warn', 'storybook/no-redundant-story-name': 'warn',
'storybook/prefer-pascal-case': 'warn', 'storybook/prefer-pascal-case': 'warn',
'storybook/story-exports': 'error', 'storybook/story-exports': 'error',
'storybook/use-storybook-expect': 'error', 'storybook/use-storybook-expect': 'error',
'storybook/use-storybook-testing-library': 'error', 'storybook/use-storybook-testing-library': 'error',
} },
}, },
{ {
plugins: ['storybook'], plugins: ['storybook'],
files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'], files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: { rules: {
'storybook/no-uninstalled-addons': 'error', 'storybook/no-uninstalled-addons': 'error',
} },
} },
] ]
export default combine( export default combine(
@ -49,27 +49,41 @@ export default combine(
lessOpinionated: true, lessOpinionated: true,
// original @antfu/eslint-config does not support jsx // original @antfu/eslint-config does not support jsx
jsx: false, jsx: false,
semi: false,
quotes: 'single',
overrides: { overrides: {
// original config // original config
"style/indent": ["error", 2], 'style/indent': ['error', 2],
'style/quotes': ['error', 'single'],
'curly': ['error', 'multi-line'],
'style/comma-spacing': ['error', { before: false, after: true }],
'style/quote-props': ['warn', 'consistent-as-needed'],
// these options does not exist in old version // these options does not exist in old version
// maybe useless // maybe useless
"style/indent-binary-ops": "off", 'style/indent-binary-ops': 'off',
"style/multiline-ternary": "off", 'style/multiline-ternary': 'off',
'antfu/top-level-function': 'off',
'antfu/curly': 'off',
'antfu/consistent-chaining': 'off',
// copy from eslint-config-antfu 0.36.0
'style/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
'style/dot-location': ['error', 'property'],
'style/object-curly-newline': ['error', { consistent: true, multiline: true }],
'style/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
'style/template-curly-spacing': ['error', 'never'],
'style/keyword-spacing': 'off',
// not exist in old version, and big change // not exist in old version, and big change
"style/quote-props": "off", 'style/member-delimiter-style': 'off',
"style/member-delimiter-style": "off", },
"style/quotes": "off",
"style/comma-dangle": "off",
}
}), }),
typescript({ typescript({
overrides: { overrides: {
// useful, but big change // useful, but big change
"ts/no-empty-object-type": "off", 'ts/no-empty-object-type': 'off',
} },
}), }),
javascript({ javascript({
overrides: { overrides: {
@ -77,8 +91,8 @@ export default combine(
'no-unused-vars': 'off', 'no-unused-vars': 'off',
// useless // useless
'no-use-before-define': 'warn' 'no-use-before-define': 'warn',
} },
}), }),
unicorn(), unicorn(),
node(), node(),
@ -96,30 +110,36 @@ export default combine(
'**/.next/', '**/.next/',
'**/public/*', '**/public/*',
'**/*.json', '**/*.json',
] ],
}, },
{ {
// orignal config // orignal config
rules: { rules: {
// from old version of antfu/eslint-config // from old version of antfu/eslint-config
// typescript will handle this, see https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors // typescript will handle this, see https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
"no-undef": "off", 'no-undef': 'off',
'ts/consistent-type-definitions': ['error', 'type'], 'ts/consistent-type-definitions': ['error', 'type'],
// orignal ts/no-var-requires // orignal ts/no-var-requires
'ts/no-require-imports': 'off', 'ts/no-require-imports': 'off',
"no-console": 'off', 'no-console': 'off',
"react-hooks/exhaustive-deps": "warn", 'react-hooks/exhaustive-deps': 'warn',
"react/display-name": "off", 'react/display-name': 'off',
'array-callback-return': ['error', {
allowImplicit: false,
checkForEach: false,
}],
// orignal config, but removed in new version antfu/eslint-config // copy from eslint-config-antfu 0.36.0
// big change 'camelcase': 'off',
"curly": "off", 'curly': ['error', 'multi-or-nest', 'consistent'],
'default-case-last': 'error',
'dot-notation': ['error', { allowKeywords: true }],
'new-cap': ['error', { newIsCap: true, capIsNew: false, properties: true }],
// antfu use eslint-plugin-perfectionist to replace this // antfu use eslint-plugin-perfectionist to replace this
// will cause big change, so keep the original // will cause big change, so keep the original sort-imports
// sort-imports 'sort-imports': [
"sort-imports": [
'error', 'error',
{ {
ignoreCase: false, ignoreCase: false,
@ -131,8 +151,8 @@ export default combine(
], ],
// antfu migrate to eslint-plugin-unused-imports // antfu migrate to eslint-plugin-unused-imports
"unused-imports/no-unused-vars": "warn", 'unused-imports/no-unused-vars': 'warn',
"unused-imports/no-unused-imports": "warn", 'unused-imports/no-unused-imports': 'warn',
}, },
languageOptions: { languageOptions: {
@ -140,25 +160,25 @@ export default combine(
...globals.browser, ...globals.browser,
...globals.es2025, ...globals.es2025,
...globals.node, ...globals.node,
'React': 'readable', React: 'readable',
'JSX': 'readable', JSX: 'readable',
} },
} },
}, },
storybook, storybook,
// need futher research // need futher research
{ {
rules: { rules: {
// not exist in old version // not exist in old version
"antfu/consistent-list-newline": "off", 'antfu/consistent-list-newline': 'off',
'node/prefer-global/process': 'off', 'node/prefer-global/process': 'off',
'node/prefer-global/buffer': 'off', 'node/prefer-global/buffer': 'off',
'node/no-callback-literal': 'off', 'node/no-callback-literal': 'off',
// useful, but big change // useful, but big change
"unicorn/prefer-number-properties": "warn", 'unicorn/prefer-number-properties': 'warn',
"unicorn/no-new-array": "warn" 'unicorn/no-new-array': 'warn',
} },
}, },
// suppress error for `no-undef` rule // suppress error for `no-undef` rule
{ {

Loading…
Cancel
Save