feat: 更新模板
This commit is contained in:
175
eslint.config.js
175
eslint.config.js
@@ -1,139 +1,46 @@
|
||||
import {defineConfig, globalIgnores} from 'eslint/config'
|
||||
import {fixupConfigRules, fixupPluginRules} from '@eslint/compat'
|
||||
import react from 'eslint-plugin-react'
|
||||
import unusedImports from 'eslint-plugin-unused-imports'
|
||||
import _import from 'eslint-plugin-import'
|
||||
import typescriptEslint from '@typescript-eslint/eslint-plugin'
|
||||
import jsxA11Y from 'eslint-plugin-jsx-a11y'
|
||||
import prettier from 'eslint-plugin-prettier'
|
||||
import globals from 'globals'
|
||||
import tsParser from '@typescript-eslint/parser'
|
||||
import path from 'node:path'
|
||||
import {fileURLToPath} from 'node:url'
|
||||
import js from '@eslint/js'
|
||||
import {FlatCompat} from '@eslint/eslintrc'
|
||||
import prettierConfig from 'eslint-config-prettier'
|
||||
import importPlugin from 'eslint-plugin-import'
|
||||
import prettierPlugin from 'eslint-plugin-prettier'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import globals from 'globals'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
recommendedConfig: js.configs.recommended,
|
||||
allConfig: js.configs.all
|
||||
})
|
||||
|
||||
export default defineConfig([globalIgnores([
|
||||
'**/*.css',
|
||||
'**/.changeset',
|
||||
'**/dist',
|
||||
'esm/*',
|
||||
'public/*',
|
||||
'tests/*',
|
||||
'scripts/*',
|
||||
'**/*.config.js',
|
||||
'**/.DS_Store',
|
||||
'**/node_modules',
|
||||
'**/coverage'
|
||||
]), {
|
||||
extends: fixupConfigRules(compat.extends(
|
||||
'plugin:react/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
'plugin:react-hooks/recommended',
|
||||
'plugin:jsx-a11y/recommended'
|
||||
)),
|
||||
|
||||
plugins: {
|
||||
react: fixupPluginRules(react),
|
||||
'unused-imports': unusedImports,
|
||||
import: fixupPluginRules(_import),
|
||||
'@typescript-eslint': typescriptEslint,
|
||||
'jsx-a11y': fixupPluginRules(jsxA11Y),
|
||||
prettier: fixupPluginRules(prettier)
|
||||
export default [
|
||||
{
|
||||
ignores: ['dist'],
|
||||
},
|
||||
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, 'off'])),
|
||||
...globals.node
|
||||
js.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
{
|
||||
files: ['**/*.{ts,tsx,js,jsx}'],
|
||||
plugins: {
|
||||
'@typescript-eslint': tseslint.plugin,
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
prettier: prettierPlugin,
|
||||
import: importPlugin,
|
||||
},
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'prettier/prettier': ['error', { endOfLine: 'auto' }],
|
||||
'import/order': [
|
||||
'error',
|
||||
{
|
||||
groups: [['builtin', 'external'], 'internal', ['parent', 'sibling', 'index']],
|
||||
'newlines-between': 'always',
|
||||
alphabetize: {
|
||||
order: 'asc',
|
||||
caseInsensitive: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
parser: tsParser,
|
||||
ecmaVersion: 12,
|
||||
sourceType: 'module',
|
||||
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
jsx: true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect'
|
||||
}
|
||||
},
|
||||
|
||||
files: [
|
||||
'**/*.{ts,tsx,js,jsx}'
|
||||
],
|
||||
|
||||
rules: {
|
||||
'no-console': 'warn',
|
||||
'react/prop-types': 'off',
|
||||
'react/jsx-uses-react': 'off',
|
||||
'react/react-in-jsx-scope': 'off',
|
||||
'react-hooks/exhaustive-deps': 'off',
|
||||
'jsx-a11y/click-events-have-key-events': 'warn',
|
||||
'jsx-a11y/interactive-supports-focus': 'warn',
|
||||
'prettier/prettier': 'warn',
|
||||
'no-unused-vars': 'off',
|
||||
'unused-imports/no-unused-vars': 'off',
|
||||
'unused-imports/no-unused-imports': 'warn',
|
||||
|
||||
'@typescript-eslint/no-unused-vars': ['warn', {
|
||||
args: 'after-used',
|
||||
ignoreRestSiblings: false,
|
||||
argsIgnorePattern: '^_.*?$'
|
||||
}],
|
||||
|
||||
'import/order': ['error', {
|
||||
'groups': [['external', 'builtin'], 'internal', 'parent', 'sibling', 'index'],
|
||||
|
||||
alphabetize: {
|
||||
order: 'asc',
|
||||
caseInsensitive: true
|
||||
},
|
||||
|
||||
'newlines-between': 'always'
|
||||
}],
|
||||
|
||||
'react/self-closing-comp': 'warn',
|
||||
|
||||
'react/jsx-sort-props': ['warn', {
|
||||
callbacksLast: true,
|
||||
shorthandFirst: true,
|
||||
noSortAlphabetically: false,
|
||||
reservedFirst: true
|
||||
}],
|
||||
|
||||
'padding-line-between-statements': ['warn', {
|
||||
blankLine: 'always',
|
||||
prev: '*',
|
||||
next: 'return'
|
||||
}, {
|
||||
blankLine: 'always',
|
||||
prev: ['const', 'let', 'var'],
|
||||
next: '*'
|
||||
}, {
|
||||
blankLine: 'any',
|
||||
prev: ['const', 'let', 'var'],
|
||||
next: ['const', 'let', 'var']
|
||||
}],
|
||||
|
||||
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
|
||||
|
||||
'@typescript-eslint/consistent-type-imports': ['error', {
|
||||
fixStyle: 'inline-type-imports'
|
||||
}]
|
||||
}
|
||||
}])
|
||||
prettierConfig,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user