|
| 1 | +module.exports = { |
| 2 | + env: { |
| 3 | + node: true, |
| 4 | + es2021: true, |
| 5 | + mocha: true, |
| 6 | + }, |
| 7 | + extends: 'eslint:recommended', |
| 8 | + parserOptions: { |
| 9 | + ecmaVersion: 2021, |
| 10 | + sourceType: 'commonjs', |
| 11 | + }, |
| 12 | + rules: { |
| 13 | + // 代码风格 |
| 14 | + 'indent': ['error', 4, { SwitchCase: 1 }], |
| 15 | + 'linebreak-style': ['warn', 'unix'], // Windows 使用 CRLF,降级为警告 |
| 16 | + 'quotes': ['warn', 'single', { avoidEscape: true }], |
| 17 | + 'semi': ['error', 'always'], |
| 18 | + 'no-trailing-spaces': 'warn', |
| 19 | + 'eol-last': ['warn', 'always'], |
| 20 | + |
| 21 | + // 最佳实践 |
| 22 | + 'no-unused-vars': ['warn', { |
| 23 | + argsIgnorePattern: '^_', |
| 24 | + varsIgnorePattern: '^_', |
| 25 | + }], |
| 26 | + 'no-console': 'off', // 允许 console(日志库) |
| 27 | + 'no-empty': ['error', { allowEmptyCatch: true }], |
| 28 | + 'no-prototype-builtins': 'off', |
| 29 | + |
| 30 | + // ES6+ |
| 31 | + 'prefer-const': 'warn', |
| 32 | + 'no-var': 'warn', |
| 33 | + 'object-shorthand': 'warn', |
| 34 | + 'prefer-arrow-callback': 'off', |
| 35 | + |
| 36 | + // 异步 |
| 37 | + 'require-await': 'warn', |
| 38 | + 'no-return-await': 'off', |
| 39 | + |
| 40 | + // 错误预防 |
| 41 | + 'no-undef': 'error', |
| 42 | + 'no-dupe-keys': 'error', |
| 43 | + 'no-duplicate-case': 'error', |
| 44 | + 'no-unreachable': 'error', |
| 45 | + }, |
| 46 | + ignorePatterns: [ |
| 47 | + 'node_modules/', |
| 48 | + 'coverage/', |
| 49 | + 'old/', |
| 50 | + '*.min.js', |
| 51 | + ], |
| 52 | +}; |
| 53 | + |
0 commit comments