| 1 | import antfu from '@antfu/eslint-config' |
| 2 | import * as nx from '@nx/eslint-plugin' |
| 3 | import importPlugin from 'eslint-plugin-import' |
| 4 | |
| 5 | export default antfu( |
| 6 | { |
| 7 | formatters: true, |
| 8 | ignores: [ |
| 9 | '**/dist', |
| 10 | '**/*.md', |
| 11 | '**/migrations', |
| 12 | '**/*.generated.d.ts', |
| 13 | '**/*.types.d.ts', |
| 14 | '**/*.schema.json', |
| 15 | ], |
| 16 | plugins: { |
| 17 | imports: importPlugin, |
| 18 | }, |
| 19 | rules: { |
| 20 | 'no-restricted-syntax': [ |
| 21 | 'error', |
| 22 | { |
| 23 | selector: 'CallExpression[callee.type=\'MemberExpression\'][callee.object.name=\'Logger\']', |
| 24 | message: '禁止直接使用 Logger 的静态方法,请创建实例后使用(例如 this.logger.log())。', |
| 25 | }, |
| 26 | ], |
| 27 | 'e18e/prefer-array-fill': ['off'], |
| 28 | 'e18e/prefer-array-at': ['off'], |
| 29 | 'e18e/prefer-static-regex': ['off'], |
| 30 | 'no-void': ['off'], |
| 31 | 'dot-notation': ['off'], |
| 32 | 'new-cap': ['off'], |
| 33 | 'ts/no-unused-vars': ['warn', { ignoreRestSiblings: true, argsIgnorePattern: '^_' }], |
| 34 | 'ts/consistent-type-imports': ['off'], |
| 35 | 'ts/no-inferrable-types': ['error', { ignoreProperties: true }], |
| 36 | 'ts/no-explicit-any': ['warn'], |
| 37 | 'jsdoc/require-returns-description': ['off'], |
| 38 | 'node/prefer-global/buffer': ['off'], |
| 39 | 'node/prefer-global/process': ['off'], |
| 40 | 'imports/no-absolute-path': ['error'], |
| 41 | }, |
| 42 | }, |
| 43 | ...nx.configs['flat/base'], |
| 44 | { |
| 45 | files: [ |
| 46 | '**/*.ts', |
| 47 | '**/*.tsx', |
| 48 | '**/*.js', |
| 49 | '**/*.jsx', |
| 50 | ], |
| 51 | rules: { |
| 52 | '@nx/enforce-module-boundaries': [ |
| 53 | 'error', |
| 54 | { |
| 55 | enforceBuildableLibDependency: true, |
| 56 | allow: [ |
| 57 | '^.*/eslint(\\.base)?\\.config\\.[cm]?[jt]s$', |
| 58 | ], |
| 59 | depConstraints: [ |
| 60 | { |
| 61 | sourceTag: '*', |
| 62 | onlyDependOnLibsWithTags: [ |
| 63 | '*', |
| 64 | ], |
| 65 | }, |
| 66 | ], |
| 67 | }, |
| 68 | ], |
| 69 | }, |
| 70 | }, |
| 71 | { |
| 72 | files: [ |
| 73 | '**/*.ts', |
| 74 | '**/*.tsx', |
| 75 | '**/*.cts', |
| 76 | '**/*.mts', |
| 77 | ], |
| 78 | rules: { |
| 79 | 'no-console': ['error', { allow: [''] }], |
| 80 | }, |
| 81 | }, |
| 82 | { |
| 83 | files: [ |
| 84 | 'e2e/**/*.ts', |
| 85 | ], |
| 86 | rules: { |
| 87 | 'no-console': 'off', |
| 88 | }, |
| 89 | }, |
| 90 | { |
| 91 | files: [ |
| 92 | '**/*.service.ts', |
| 93 | ], |
| 94 | rules: { |
| 95 | 'no-restricted-imports': ['error', { |
| 96 | paths: [{ |
| 97 | name: '@nestjs/mongoose', |
| 98 | importNames: ['InjectModel', 'InjectConnection'], |
| 99 | message: '禁止在 Service 中直接注入 Model 或 Connection,请通过 Repository 访问数据。', |
| 100 | }], |
| 101 | }], |
| 102 | }, |
| 103 | }, |
| 104 | { |
| 105 | files: [ |
| 106 | '**/*.ts', |
| 107 | '**/*.tsx', |
| 108 | '**/*.cts', |
| 109 | '**/*.mts', |
| 110 | '**/*.js', |
| 111 | '**/*.jsx', |
| 112 | '**/*.cjs', |
| 113 | '**/*.mjs', |
| 114 | ], |
| 115 | rules: { |
| 116 | }, |
| 117 | }, |
| 118 | ) |
| 119 |