|
| 1 | +import nxEslintPlugin from '@nx/eslint-plugin'; |
| 2 | +import jestExtendedPlugin from 'eslint-plugin-jest-extended'; |
| 3 | +import jsoncParser from 'jsonc-eslint-parser'; |
| 4 | +import fs from 'node:fs'; |
| 5 | +import tseslint from 'typescript-eslint'; |
| 6 | +import node from '@code-pushup/eslint-config/node.js'; |
| 7 | +import typescript from '@code-pushup/eslint-config/typescript.js'; |
| 8 | +import vitest from '@code-pushup/eslint-config/vitest.js'; |
| 9 | + |
| 10 | +export default tseslint.config( |
| 11 | + ...typescript, |
| 12 | + ...node, |
| 13 | + ...vitest, |
| 14 | + { |
| 15 | + settings: { |
| 16 | + 'import/resolver': { |
| 17 | + typescript: { |
| 18 | + project: 'tsconfig.base.json', |
| 19 | + alwaysTryTypes: true, |
| 20 | + extensions: ['.ts', '.tsx', '.d.ts', '.js', '.jsx'], |
| 21 | + }, |
| 22 | + node: { |
| 23 | + extensions: ['.ts', '.tsx', '.d.ts', '.js', '.jsx'], |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + { plugins: { '@nx': nxEslintPlugin } }, |
| 29 | + { |
| 30 | + files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], |
| 31 | + rules: { |
| 32 | + '@nx/enforce-module-boundaries': [ |
| 33 | + 'error', |
| 34 | + { |
| 35 | + enforceBuildableLibDependency: true, |
| 36 | + allow: [ |
| 37 | + String.raw`^.*/eslint(\.base)?\.config\.[cm]?js$`, |
| 38 | + String.raw`^.*/code-pushup\.(config|preset)(\.m?[jt]s)?$`, |
| 39 | + '^[./]+/tools/.*$', |
| 40 | + String.raw`^[./]+/(testing/)?test-setup-config/src/index\.js$`, |
| 41 | + ], |
| 42 | + depConstraints: [ |
| 43 | + { |
| 44 | + sourceTag: 'scope:shared', |
| 45 | + onlyDependOnLibsWithTags: ['scope:shared'], |
| 46 | + }, |
| 47 | + { |
| 48 | + sourceTag: 'scope:core', |
| 49 | + onlyDependOnLibsWithTags: ['scope:core', 'scope:shared'], |
| 50 | + }, |
| 51 | + { |
| 52 | + sourceTag: 'scope:plugin', |
| 53 | + onlyDependOnLibsWithTags: ['scope:shared'], |
| 54 | + }, |
| 55 | + { |
| 56 | + sourceTag: 'scope:tooling', |
| 57 | + onlyDependOnLibsWithTags: ['scope:tooling', 'scope:shared'], |
| 58 | + }, |
| 59 | + { |
| 60 | + sourceTag: 'type:e2e', |
| 61 | + onlyDependOnLibsWithTags: [ |
| 62 | + 'type:app', |
| 63 | + 'type:feature', |
| 64 | + 'type:util', |
| 65 | + 'type:testing', |
| 66 | + ], |
| 67 | + }, |
| 68 | + { |
| 69 | + sourceTag: 'type:app', |
| 70 | + onlyDependOnLibsWithTags: [ |
| 71 | + 'type:feature', |
| 72 | + 'type:util', |
| 73 | + 'type:testing', |
| 74 | + ], |
| 75 | + }, |
| 76 | + { |
| 77 | + sourceTag: 'type:feature', |
| 78 | + onlyDependOnLibsWithTags: [ |
| 79 | + 'type:feature', |
| 80 | + 'type:util', |
| 81 | + 'type:testing', |
| 82 | + ], |
| 83 | + }, |
| 84 | + { |
| 85 | + sourceTag: 'type:util', |
| 86 | + onlyDependOnLibsWithTags: ['type:util', 'type:testing'], |
| 87 | + }, |
| 88 | + { |
| 89 | + sourceTag: 'type:testing', |
| 90 | + onlyDependOnLibsWithTags: ['type:util', 'type:testing'], |
| 91 | + }, |
| 92 | + ], |
| 93 | + }, |
| 94 | + ], |
| 95 | + }, |
| 96 | + }, |
| 97 | + { |
| 98 | + files: ['**/*.test.ts', '**/*.spec.ts'], |
| 99 | + plugins: { 'jest-extended': jestExtendedPlugin }, |
| 100 | + rules: { |
| 101 | + 'vitest/consistent-test-filename': [ |
| 102 | + 'warn', |
| 103 | + { |
| 104 | + pattern: String.raw`.*\.(bench|type|unit|int|e2e)\.test\.[tj]sx?$`, |
| 105 | + }, |
| 106 | + ], |
| 107 | + 'jest-extended/prefer-to-be-array': 'warn', |
| 108 | + 'jest-extended/prefer-to-be-false': 'warn', |
| 109 | + 'jest-extended/prefer-to-be-object': 'warn', |
| 110 | + 'jest-extended/prefer-to-be-true': 'warn', |
| 111 | + 'jest-extended/prefer-to-have-been-called-once': 'warn', |
| 112 | + }, |
| 113 | + }, |
| 114 | + { |
| 115 | + files: ['**/*.type.test.ts'], |
| 116 | + rules: { |
| 117 | + 'vitest/expect-expect': 'off', |
| 118 | + }, |
| 119 | + }, |
| 120 | + { |
| 121 | + files: ['**/*.json'], |
| 122 | + languageOptions: { parser: jsoncParser }, |
| 123 | + }, |
| 124 | + { |
| 125 | + files: ['**/*.ts', '**/*.js'], |
| 126 | + rules: { |
| 127 | + 'n/file-extension-in-import': ['error', 'always'], |
| 128 | + 'unicorn/number-literal-case': 'off', |
| 129 | + }, |
| 130 | + }, |
| 131 | + { |
| 132 | + files: ['**/perf/**/*.ts'], |
| 133 | + rules: { |
| 134 | + '@typescript-eslint/no-magic-numbers': 'off', |
| 135 | + 'sonarjs/no-duplicate-string': 'off', |
| 136 | + }, |
| 137 | + }, |
| 138 | + { |
| 139 | + // tests need only be compatible with local Node version |
| 140 | + // publishable packages should pick up version range from "engines" in their package.json |
| 141 | + files: ['e2e/**/*.ts', 'testing/**/*.ts', '**/*.test.ts'], |
| 142 | + settings: { |
| 143 | + node: { |
| 144 | + version: fs.readFileSync('.node-version', 'utf8'), |
| 145 | + }, |
| 146 | + }, |
| 147 | + }, |
| 148 | + { |
| 149 | + ignores: [ |
| 150 | + '**/*.mock.*', |
| 151 | + '**/code-pushup.config.ts', |
| 152 | + '**/mocks/fixtures/**', |
| 153 | + '**/__snapshots__/**', |
| 154 | + '**/dist', |
| 155 | + '**/*.md', |
| 156 | + ], |
| 157 | + }, |
| 158 | +); |
0 commit comments