|
1 | 1 | import eslintNestJs from "@darraghor/eslint-plugin-nestjs-typed"; |
2 | | -import type { ConfigWithExtends } from "typescript-eslint"; |
| 2 | +import { isPackageListed } from "local-pkg"; |
| 3 | +import type { ConfigArray, ConfigWithExtends } from "typescript-eslint"; |
3 | 4 |
|
4 | 5 | import { imports } from "../configs/imports"; |
5 | 6 | import { node } from "../configs/node"; |
6 | 7 | import { typescriptStrict } from "../configs/typescript-strict"; |
7 | 8 | import { unicorn } from "../configs/unicorn"; |
8 | 9 |
|
9 | | -export const nestjsPreset = (): ConfigWithExtends[] => [ |
10 | | - ...node(), |
11 | | - ...unicorn(), |
12 | | - ...typescriptStrict(), |
13 | | - ...imports({ forbidDefaultExport: true }), |
14 | | - ...eslintNestJs.configs.flatRecommended, |
15 | | - { |
16 | | - rules: { |
17 | | - "no-implicit-coercion": [ |
18 | | - "error", |
| 10 | +export const nestjsPreset = async (): Promise<ConfigWithExtends[]> => { |
| 11 | + const hasSwagger = await isPackageListed("@nestjs/swagger"); |
| 12 | + |
| 13 | + const nestjsConfig = hasSwagger |
| 14 | + ? ([ |
| 15 | + ...eslintNestJs.configs.flatRecommended, |
19 | 16 | { |
20 | | - allow: ["+"], |
| 17 | + rules: { |
| 18 | + "@darraghor/nestjs-typed/api-property-matches-property-optionality": |
| 19 | + "warn", |
| 20 | + "@darraghor/nestjs-typed/controllers-should-supply-api-tags": |
| 21 | + "warn", |
| 22 | + "@darraghor/nestjs-typed/api-method-should-specify-api-response": |
| 23 | + "warn", |
| 24 | + "@darraghor/nestjs-typed/api-method-should-specify-api-operation": |
| 25 | + "warn", |
| 26 | + "@darraghor/nestjs-typed/api-enum-property-best-practices": "warn", |
| 27 | + "@darraghor/nestjs-typed/api-property-returning-array-should-set-array": |
| 28 | + "warn", |
| 29 | + }, |
21 | 30 | }, |
22 | | - ], |
23 | | - "unicorn/prefer-top-level-await": "off", |
| 31 | + ] satisfies ConfigArray) |
| 32 | + : eslintNestJs.configs.flatNoSwagger; |
| 33 | + |
| 34 | + return [ |
| 35 | + ...node(), |
| 36 | + ...unicorn(), |
| 37 | + ...typescriptStrict(), |
| 38 | + ...imports({ forbidDefaultExport: true }), |
| 39 | + ...nestjsConfig, |
| 40 | + { |
| 41 | + rules: { |
| 42 | + "no-implicit-coercion": [ |
| 43 | + "error", |
| 44 | + { |
| 45 | + allow: ["+"], |
| 46 | + }, |
| 47 | + ], |
| 48 | + "unicorn/prefer-top-level-await": "off", |
| 49 | + }, |
24 | 50 | }, |
25 | | - }, |
26 | | - { |
27 | | - rules: { |
28 | | - "@typescript-eslint/no-extraneous-class": [ |
29 | | - "error", |
30 | | - { |
31 | | - allowEmpty: true, |
32 | | - }, |
33 | | - ], |
| 51 | + { |
| 52 | + rules: { |
| 53 | + "@typescript-eslint/no-extraneous-class": [ |
| 54 | + "error", |
| 55 | + { |
| 56 | + allowEmpty: true, |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + files: ["**/*.module.ts"], |
34 | 61 | }, |
35 | | - files: ["**/*.module.ts"], |
36 | | - }, |
37 | | - { |
38 | | - rules: { |
39 | | - "@typescript-eslint/no-floating-promises": "off", |
| 62 | + { |
| 63 | + rules: { |
| 64 | + "@typescript-eslint/no-floating-promises": "off", |
| 65 | + }, |
| 66 | + files: ["./src/main.ts"], |
40 | 67 | }, |
41 | | - files: ["./src/main.ts"], |
42 | | - }, |
43 | | -]; |
| 68 | + ]; |
| 69 | +}; |
0 commit comments