206 lines
5.9 KiB
JavaScript
206 lines
5.9 KiB
JavaScript
module.exports = {
|
||
root: true,
|
||
extends: [
|
||
'eslint:recommended',
|
||
'plugin:vue/vue3-recommended',
|
||
'plugin:jsonc/recommended-with-jsonc',
|
||
'plugin:@typescript-eslint/recommended',
|
||
'plugin:prettier/recommended',
|
||
'plugin:n/recommended',
|
||
'plugin:import/recommended',
|
||
'plugin:regexp/recommended',
|
||
],
|
||
env: {
|
||
browser: true,
|
||
node: true,
|
||
es6: true,
|
||
},
|
||
parser: 'vue-eslint-parser',
|
||
parserOptions: {
|
||
ecmaVersion: 'latest',
|
||
parser: '@typescript-eslint/parser',
|
||
sourceType: 'module',
|
||
jsxPragma: 'React',
|
||
ecmaFeatures: {
|
||
jsx: true,
|
||
},
|
||
project: './tsconfig.*?.json',
|
||
createDefaultProgram: false,
|
||
extraFileExtensions: ['.vue'],
|
||
},
|
||
plugins: ['vue', '@typescript-eslint', 'import', 'simple-import-sort'],
|
||
rules: {
|
||
'max-len': ['error', { code: 140, tabWidth: 2, ignoreComments: true }],
|
||
'no-console': 'warn',
|
||
'no-unused-vars': 'off',
|
||
'no-case-declarations': 'off',
|
||
'no-use-before-define': 'off',
|
||
'space-before-function-paren': 'off',
|
||
|
||
'simple-import-sort/imports': 'error',
|
||
'simple-import-sort/exports': 'error',
|
||
'import/no-unresolved': 'off',
|
||
'import/first': 'error',
|
||
'import/newline-after-import': 'error',
|
||
'import/no-duplicates': 'error',
|
||
|
||
'@typescript-eslint/no-unused-vars': [
|
||
'error',
|
||
{
|
||
argsIgnorePattern: '^_',
|
||
varsIgnorePattern: '^_',
|
||
},
|
||
],
|
||
'@typescript-eslint/ban-ts-comment': 'off',
|
||
'@typescript-eslint/ban-types': 'off',
|
||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||
'@typescript-eslint/no-explicit-any': 'off',
|
||
'@typescript-eslint/no-var-requires': 'off',
|
||
'@typescript-eslint/no-use-before-define': 'off',
|
||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||
'@typescript-eslint/no-empty-function': 'off',
|
||
'vue/script-setup-uses-vars': 'error',
|
||
'vue/no-reserved-component-names': 'off',
|
||
'vue/custom-event-name-casing': 'off',
|
||
'vue/attributes-order': 'off',
|
||
'vue/one-component-per-file': 'off',
|
||
'vue/html-closing-bracket-newline': 'off',
|
||
'vue/max-attributes-per-line': 'off',
|
||
'vue/multiline-html-element-content-newline': 'off',
|
||
'vue/singleline-html-element-content-newline': 'off',
|
||
'vue/attribute-hyphenation': 'off',
|
||
'vue/require-default-prop': 'off',
|
||
'vue/require-explicit-emits': 'off',
|
||
'vue/prefer-import-from-vue': 'off',
|
||
'vue/html-self-closing': [
|
||
'error',
|
||
{
|
||
html: {
|
||
void: 'always',
|
||
normal: 'never',
|
||
component: 'always',
|
||
},
|
||
svg: 'always',
|
||
math: 'always',
|
||
},
|
||
],
|
||
'vue/multi-word-component-names': 'off',
|
||
eqeqeq: ['warn', 'always', { null: 'never' }],
|
||
'no-debugger': 'error',
|
||
'no-empty': ['warn', { allowEmptyCatch: true }],
|
||
'prefer-const': [
|
||
'error',
|
||
{
|
||
destructuring: 'all',
|
||
},
|
||
],
|
||
|
||
'n/no-missing-import': 'off',
|
||
'n/no-unpublished-import': 'off',
|
||
'n/no-unsupported-features/es-syntax': [
|
||
'error',
|
||
{
|
||
version: '>=18.0.0',
|
||
ignores: [],
|
||
},
|
||
],
|
||
'n/no-extraneous-import': [
|
||
'error',
|
||
{
|
||
allowModules: ['unbuild', '@vben/vite-config'],
|
||
},
|
||
],
|
||
|
||
'prettier/prettier': 'error',
|
||
'import/no-unresolved': 'off',
|
||
|
||
'object-shorthand': ['error', 'always', { ignoreConstructors: false, avoidQuotes: true }],
|
||
|
||
'@typescript-eslint/ban-ts-comment': [
|
||
'error',
|
||
{
|
||
'ts-expect-error': 'allow-with-description',
|
||
'ts-ignore': 'allow-with-description',
|
||
'ts-nocheck': 'allow-with-description',
|
||
'ts-check': false,
|
||
},
|
||
],
|
||
|
||
/**
|
||
* 【强制】关键字前后有一个空格
|
||
* @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/keyword-spacing.md
|
||
*/
|
||
'keyword-spacing': 'off',
|
||
'@typescript-eslint/keyword-spacing': [
|
||
'error',
|
||
{
|
||
before: true,
|
||
after: true,
|
||
overrides: {
|
||
return: { after: true },
|
||
throw: { after: true },
|
||
case: { after: true },
|
||
},
|
||
},
|
||
],
|
||
|
||
/**
|
||
* 禁止出现空函数,普通函数(非 async/await/generator)、箭头函数、类上的方法除外
|
||
* @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
|
||
*/
|
||
'no-empty-function': 'off',
|
||
'@typescript-eslint/no-empty-function': [
|
||
'error',
|
||
{
|
||
allow: ['arrowFunctions', 'functions', 'methods'],
|
||
},
|
||
],
|
||
|
||
/**
|
||
* 优先使用 interface 而不是 type 定义对象类型
|
||
* @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
|
||
*/
|
||
'@typescript-eslint/consistent-type-definitions': ['warn', 'interface'],
|
||
'@typescript-eslint/no-non-null-assertion': 'error',
|
||
'@typescript-eslint/no-var-requires': 'error',
|
||
'@typescript-eslint/ban-types': 'error',
|
||
|
||
'vue/attributes-order': 'error',
|
||
'vue/require-default-prop': 'error',
|
||
'vue/require-explicit-emits': 'error',
|
||
'vue/prefer-import-from-vue': 'error',
|
||
'vue/multiline-html-element-content-newline': 'error',
|
||
'vue/html-closing-bracket-newline': 'error',
|
||
'vue/one-component-per-file': 'error',
|
||
'vue/custom-event-name-casing': 'error',
|
||
},
|
||
overrides: [
|
||
{
|
||
files: ['*.json', '*.json5', '*.jsonc'],
|
||
parser: 'jsonc-eslint-parser',
|
||
},
|
||
{
|
||
files: ['**.test.ts'],
|
||
rules: {
|
||
'no-console': 'off',
|
||
},
|
||
},
|
||
{
|
||
files: ['package.json'],
|
||
parser: 'jsonc-eslint-parser',
|
||
rules: {
|
||
'jsonc/sort-keys': 'off',
|
||
},
|
||
},
|
||
],
|
||
globals: { defineOptions: 'readonly' },
|
||
ignorePatterns: ['**/vendor/**', '**/dist/**', '**/node_modules/**'],
|
||
settings: {
|
||
'import/resolver': {
|
||
node: { extensions: ['.ts', '.d.ts', '.tsx'] },
|
||
},
|
||
'import/ignore': ['node_modules'],
|
||
},
|
||
};
|