@tianyio/quality-helper
Version:
统一项目规范的工具包
169 lines (167 loc) • 4.55 kB
JavaScript
import tsEslint from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import vueEslint from 'eslint-plugin-vue'
import vueParser from 'vue-eslint-parser'
import promiseEslint from 'eslint-plugin-promise'
import prettierConfig from 'eslint-config-prettier'
import prettierEslint from 'eslint-plugin-prettier'
export default [
// 新增 ignore 配置
{
ignores: ['**/node_modules', '**/dist']
},
{
files: ['**/*.vue'],
languageOptions: {
parser: vueParser,
parserOptions: {
parser: '@typescript-eslint/parser',
ecmaVersion: 2021,
sourceType: 'module',
ecmaFeatures: {
jsx: false
},
vueFeatures: {
interpolation: true,
templateLanguageProcessors: ['typescript']
}
}
},
rules: {
...vueEslint.configs['flat/base'],
...vueEslint.configs['flat/essential'],
...vueEslint.configs['flat/strongly-recommended'],
...vueEslint.configs['flat/recommended'],
'vue/multi-word-component-names': 'off',
'vue/require-default-prop': 'off',
// vue-template中标签属性规则
'vue/html-self-closing': 'error',
// 闭合标签空格
'vue/html-closing-bracket-spacing': 'off'
/*// 标签属性占行
'vue/max-attributes-per-line': [
'error',
{
singleline: {
max: 3
},
multiline: {
max: 1
}
}
],*/
// 对齐
// 'vue/html-indent': 'error',
}
},
// TypeScript 文件配置
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module'
}
},
plugins: {
'@typescript-eslint': tsEslint
},
rules: {
...tsEslint.configs.recommendedTypeChecked,
...tsEslint.configs.strictTypeChecked,
...tsEslint.configs.recommended.rules,
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['off'],
// 允许非空断言运算符
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/ban-types': 0,
// "@typescript-eslint/no-explicit-any": ["off"],
'@typescript-eslint/explicit-module-boundary-types': 2,
'@typescript-eslint/no-var-requires': 0
}
},
// Prettier 整合
{
plugins: {
prettier: prettierEslint
},
rules: {
...prettierConfig.rules,
// 'prettier/prettier': 'error',
'prettier/prettier': [
'error',
{
endOfLine: 'auto'
}
]
}
},
// Promise 插件
{
plugins: {
promise: promiseEslint
},
rules: {
...promiseEslint.configs.recommended.rules,
'promise/catch-or-return': 'warn',
'promise/no-nesting': 'warn',
'promise/always-return': 'warn',
'promise/no-return-wrap': 'warn'
}
},
// 全局规则
{
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// 关闭禁止混用tab和空格
'no-mixed-spaces-and-tabs': 2,
'no-extra-semi': 2,
indent: [
'off',
2,
{
SwitchCase: 1,
ObjectExpression: 'off',
MemberExpression: 'off',
CallExpression: {
arguments: 1
},
FunctionDeclaration: {
parameters: 2
},
FunctionExpression: {
parameters: 1
}
}
],
'no-tabs': 'off',
// 禁止结尾没有分号
semi: [2, 'never'],
// 禁止出现多行空行
'no-multiple-empty-lines': 0,
// 禁止重复引用
'no-duplicate-imports': 'off',
// 禁止在 import 和 export 和解构赋值时将引用重命名为相同的名字
'no-useless-rename': 0,
'no-return-await': 0,
// 转义符
'no-useless-escape': 0,
// 不允许扩展原生对象
// "no-extend-native" : 0,
// 不允许对null用==或者!=
'no-eq-null': 2,
'no-unneeded-ternary': 'error',
'linebreak-style': [0, 'error', 'windows'],
// 对象字面量项尾不能有逗号
'comma-dangle': ['error', 'never'],
'multiline-ternary': 0,
'prefer-regex-literals': 0
}
}
]