Skip to content

Commit 39c6e9c

Browse files
committed
fix: lint swagger only if it is installed
1 parent 4318912 commit 39c6e9c

2 files changed

Lines changed: 58 additions & 32 deletions

File tree

src/eslint/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const solvro = async (...overrides: ConfigWithExtends[]) => {
2323
projectConfigs.push(...adonisPreset());
2424
} else if (isNestJs) {
2525
const { nestjsPreset } = await import("./presets/nestjs.js");
26-
projectConfigs.push(...nestjsPreset());
26+
projectConfigs.push(...(await nestjsPreset()));
2727
} else if (isReact) {
2828
const { reactPreset } = await import("./presets/react.js");
2929
projectConfigs.push(...(await reactPreset()));

src/eslint/presets/nestjs.ts

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,69 @@
11
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";
34

45
import { imports } from "../configs/imports";
56
import { node } from "../configs/node";
67
import { typescriptStrict } from "../configs/typescript-strict";
78
import { unicorn } from "../configs/unicorn";
89

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,
1916
{
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+
},
2130
},
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+
},
2450
},
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"],
3461
},
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"],
4067
},
41-
files: ["./src/main.ts"],
42-
},
43-
];
68+
];
69+
};

0 commit comments

Comments
 (0)