UNPKG

@tianyio/quality-helper

Version:

A comprehensive quality helper tool for project scaffolding and management

244 lines (239 loc) 6.67 kB
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' import js from '@eslint/js' export default [ // 全局忽略配置(从 .eslintignore 迁移) { ignores: [ // 依赖目录 '**/node_modules/**', // 构建输出目录 '**/dist/**', '**/build/**', '**/out/**', '**/.next/**', '**/.nuxt/**', '**/.output/**', // 缓存目录 '**/.cache/**', '**/.parcel-cache/**', '**/.vite/**', '**/.turbo/**', // 日志文件 '**/*.log', '**/npm-debug.log*', '**/yarn-debug.log*', '**/yarn-error.log*', '**/pnpm-debug.log*', '**/lerna-debug.log*', // 环境变量文件 '**/.env', '**/.env.*', // 临时文件 '**/*.tmp', '**/*.temp', // 系统文件 '**/.DS_Store', '**/Thumbs.db', // IDE 配置 '**/.vscode/**', '**/.idea/**', '**/*.swp', '**/*.swo', // 测试覆盖率 '**/coverage/**', '**/.nyc_output/**', // 文档生成 '**/docs/**', // 静态资源 '**/public/**', '**/static/**', '**/assets/**', // 配置文件(排除 eslint.config.js) '**/vite.config.*', '**/webpack.config.*', '**/rollup.config.*', '**/vitest.config.*', '**/jest.config.*', // 类型定义文件(但保留手写的类型定义) '**/*.d.ts', '!**/src/**/*.d.ts', // 压缩文件 '**/*.zip', '**/*.tar.gz', '**/*.rar', // 锁文件 '**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml', '**/templates/**', ], }, // JavaScript 文件配置 { files: ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.cjs'], languageOptions: { ecmaVersion: 2022, sourceType: 'module', globals: { console: 'readonly', process: 'readonly', }, }, rules: { ...js.configs.recommended.rules, 'no-duplicate-imports': 'error', }, }, // Vue 文件配置 { files: ['**/*.vue'], languageOptions: { parser: vueParser, parserOptions: { parser: '@typescript-eslint/parser', ecmaVersion: 2022, sourceType: 'module', projectService: true, tsconfigRootDir: import.meta.dirname, extraFileExtensions: ['.vue'], ecmaFeatures: { jsx: true, }, }, }, plugins: { vue: vueEslint, }, rules: { ...vueEslint.configs['flat/essential'].rules, ...vueEslint.configs['flat/strongly-recommended'].rules, 'no-duplicate-imports': 'off', 'vue/multi-word-component-names': 'off', 'vue/require-default-prop': 'off', 'vue/component-definition-name-casing': ['error', 'PascalCase'], 'vue/component-name-in-template-casing': ['error', 'PascalCase'], 'vue/define-macros-order': [ 'error', { order: ['defineProps', 'defineEmits'], }, ], 'vue/no-unused-vars': 'error', 'vue/padding-line-between-blocks': ['error', 'always'], }, }, // TypeScript 文件配置(排除 .vue 文件,避免与 Vue 配置冲突) { files: ['**/*.ts', '**/*.tsx'], languageOptions: { parser: tsParser, parserOptions: { ecmaVersion: 2022, sourceType: 'module', projectService: true, tsconfigRootDir: import.meta.dirname, }, }, plugins: { '@typescript-eslint': tsEslint, }, rules: { ...tsEslint.configs.recommended.rules, // 允许在 TypeScript 中将值导入与类型导入拆分为两行 'no-duplicate-imports': 'off', '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-unused-vars': [ 'warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', ignoreRestSiblings: true, }, ], '@typescript-eslint/no-non-null-assertion': 'warn', '@typescript-eslint/ban-types': 'off', '@typescript-eslint/no-var-requires': 'off', '@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports', fixStyle: 'separate-type-imports' }, ], '@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }], '@typescript-eslint/prefer-nullish-coalescing': 'error', '@typescript-eslint/prefer-optional-chain': 'error', '@typescript-eslint/no-unnecessary-type-assertion': 'error', }, }, // Prettier 整合(简化配置,避免与 prettier.config.js 冲突) { plugins: { prettier: prettierEslint, }, rules: { ...prettierConfig.rules, 'prettier/prettier': 'error', }, }, // 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': 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn', // 代码质量 'no-unused-vars': 'off', // 由 TypeScript 处理 'no-undef': 'off', // 由 TypeScript 处理 'no-useless-rename': 'error', 'no-useless-escape': 'warn', 'no-eq-null': 'error', 'no-unneeded-ternary': 'error', 'prefer-const': 'error', 'prefer-template': 'error', // 代码风格(由 Prettier 处理,这里关闭冲突规则) indent: 'off', semi: 'off', quotes: 'off', 'comma-dangle': 'off', 'no-tabs': 'off', 'no-mixed-spaces-and-tabs': 'off', 'no-extra-semi': 'off', 'arrow-parens': 'off', 'generator-star-spacing': 'off', 'no-multiple-empty-lines': 'off', 'linebreak-style': 'off', 'multiline-ternary': 'off', // 现代 JavaScript 特性 'prefer-arrow-callback': 'error', 'prefer-destructuring': [ 'error', { array: true, object: true, }, { enforceForRenamedProperties: false, }, ], 'object-shorthand': 'error', 'prefer-regex-literals': 'error', }, }, ]