import globals from 'globals' import pluginJs from '@eslint/js' import pluginVue from 'eslint-plugin-vue' import prettier from 'eslint-plugin-prettier' import eslintConfigPrettier from 'eslint-config-prettier' /** @type {import('eslint').Linter.Config[]} */ export default [ { ignores: ['node_modules', 'dist'] }, { files: ['**/*.{js,mjs,cjs,vue}'] }, { languageOptions: { globals: { ...globals.browser, ...globals.node } } }, pluginJs.configs.recommended, ...pluginVue.configs['flat/essential'], ...pluginVue.configs['flat/strongly-recommended'], eslintConfigPrettier, { plugins: { prettier }, rules: { // 添加 prettier 规则 'prettier/prettier': [ 'error', { singleAttributePerLine: false, htmlWhitespaceSensitivity: 'ignore' } ], // 基础规则 'no-console': ['warn', { allow: ['warn', 'error'] }], // 允许 console.warn 和 console.error semi: 'off', // 语句末尾分号 'no-var': 'error', 'prefer-const': 'error', // 优先使用 const 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], // 未使用的变量警告 // Vue 相关规则 'vue/multi-word-component-names': 'off', // 关闭组件名必须多词的限制 'vue/no-v-html': 'warn', // 使用 v-html 有 XSS 风险,仅警告 'vue/require-default-prop': 'error', // Props 需要默认值 // 移动端性能相关 'vue/no-async-in-computed-properties': 'error', // 计算属性中不应有异步操作 'vue/no-side-effects-in-computed-properties': 'error', // 计算属性中不应有副作用 // 格式化相关 'vue/html-indent': ['error', 2], // HTML 缩进 2 个空格 'vue/html-closing-bracket-newline': [ 'error', { // 标签闭合括号换行规则 singleline: 'never', multiline: 'always' } ] } } ]