74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
/**
|
|
* ESLint 配置
|
|
* 遵循瑞小美代码规范(必须配置)
|
|
*/
|
|
|
|
import js from '@eslint/js'
|
|
import vue from 'eslint-plugin-vue'
|
|
import typescript from '@typescript-eslint/eslint-plugin'
|
|
import typescriptParser from '@typescript-eslint/parser'
|
|
import vueParser from 'vue-eslint-parser'
|
|
|
|
export default [
|
|
js.configs.recommended,
|
|
...vue.configs['flat/recommended'],
|
|
{
|
|
files: ['**/*.{ts,tsx,vue}'],
|
|
languageOptions: {
|
|
parser: vueParser,
|
|
parserOptions: {
|
|
parser: typescriptParser,
|
|
ecmaVersion: 'latest',
|
|
sourceType: 'module',
|
|
},
|
|
globals: {
|
|
// Vue 3 编译器宏
|
|
defineProps: 'readonly',
|
|
defineEmits: 'readonly',
|
|
defineExpose: 'readonly',
|
|
withDefaults: 'readonly',
|
|
// 浏览器全局变量
|
|
window: 'readonly',
|
|
document: 'readonly',
|
|
console: 'readonly',
|
|
setTimeout: 'readonly',
|
|
setInterval: 'readonly',
|
|
clearTimeout: 'readonly',
|
|
clearInterval: 'readonly',
|
|
fetch: 'readonly',
|
|
FormData: 'readonly',
|
|
File: 'readonly',
|
|
Blob: 'readonly',
|
|
URL: 'readonly',
|
|
URLSearchParams: 'readonly',
|
|
},
|
|
},
|
|
plugins: {
|
|
'@typescript-eslint': typescript,
|
|
},
|
|
rules: {
|
|
// Vue 规则
|
|
'vue/multi-word-component-names': 'off',
|
|
'vue/no-v-html': 'off',
|
|
'vue/require-default-prop': 'off',
|
|
'vue/require-explicit-emits': 'error',
|
|
'vue/v-on-event-hyphenation': ['error', 'always'],
|
|
|
|
// TypeScript 规则
|
|
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
'@typescript-eslint/no-explicit-any': 'warn',
|
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
|
|
// 通用规则
|
|
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
|
'no-unused-vars': 'off', // 使用 @typescript-eslint/no-unused-vars
|
|
'prefer-const': 'error',
|
|
'no-var': 'error',
|
|
},
|
|
},
|
|
{
|
|
ignores: ['dist/**', 'node_modules/**', '*.d.ts'],
|
|
},
|
|
]
|