@webpieces/dev-config 0.2.76 → 0.2.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/architecture/executors/validate-code/executor.d.ts +14 -6
- package/architecture/executors/validate-code/executor.js +61 -37
- package/architecture/executors/validate-code/executor.js.map +1 -1
- package/architecture/executors/validate-code/executor.ts +94 -58
- package/architecture/executors/validate-code/schema.json +48 -29
- package/architecture/executors/validate-modified-files/executor.d.ts +4 -3
- package/architecture/executors/validate-modified-files/executor.js +32 -30
- package/architecture/executors/validate-modified-files/executor.js.map +1 -1
- package/architecture/executors/validate-modified-files/executor.ts +36 -33
- package/architecture/executors/validate-modified-files/schema.json +9 -4
- package/architecture/executors/validate-modified-methods/executor.d.ts +7 -6
- package/architecture/executors/validate-modified-methods/executor.js +53 -47
- package/architecture/executors/validate-modified-methods/executor.js.map +1 -1
- package/architecture/executors/validate-modified-methods/executor.ts +57 -51
- package/architecture/executors/validate-modified-methods/schema.json +10 -5
- package/architecture/executors/validate-new-methods/executor.d.ts +4 -4
- package/architecture/executors/validate-new-methods/executor.js +64 -83
- package/architecture/executors/validate-new-methods/executor.js.map +1 -1
- package/architecture/executors/validate-new-methods/executor.ts +75 -96
- package/architecture/executors/validate-new-methods/schema.json +11 -10
- package/architecture/executors/validate-no-any-unknown/executor.d.ts +1 -2
- package/architecture/executors/validate-no-any-unknown/executor.js +57 -55
- package/architecture/executors/validate-no-any-unknown/executor.js.map +1 -1
- package/architecture/executors/validate-no-any-unknown/executor.ts +62 -57
- package/architecture/executors/validate-no-any-unknown/schema.json +2 -2
- package/architecture/executors/validate-no-inline-types/executor.d.ts +1 -2
- package/architecture/executors/validate-no-inline-types/executor.js +25 -58
- package/architecture/executors/validate-no-inline-types/executor.js.map +1 -1
- package/architecture/executors/validate-no-inline-types/executor.ts +26 -59
- package/architecture/executors/validate-no-inline-types/schema.json +2 -2
- package/architecture/executors/validate-return-types/executor.d.ts +1 -2
- package/architecture/executors/validate-return-types/executor.js +25 -58
- package/architecture/executors/validate-return-types/executor.js.map +1 -1
- package/architecture/executors/validate-return-types/executor.ts +26 -59
- package/architecture/executors/validate-return-types/schema.json +2 -2
- package/package.json +1 -1
|
@@ -2,13 +2,21 @@ import { ExecutorContext } from '@nx/devkit';
|
|
|
2
2
|
import { ReturnTypeMode } from '../validate-return-types/executor';
|
|
3
3
|
import { NoInlineTypesMode } from '../validate-no-inline-types/executor';
|
|
4
4
|
import { NoAnyUnknownMode } from '../validate-no-any-unknown/executor';
|
|
5
|
-
export type
|
|
5
|
+
export type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';
|
|
6
|
+
export type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';
|
|
7
|
+
export interface MethodMaxLimitConfig {
|
|
8
|
+
limit?: number;
|
|
9
|
+
mode?: MethodMaxLimitMode;
|
|
10
|
+
disableAllowed?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface FileMaxLimitConfig {
|
|
13
|
+
limit?: number;
|
|
14
|
+
mode?: FileMaxLimitMode;
|
|
15
|
+
disableAllowed?: boolean;
|
|
16
|
+
}
|
|
6
17
|
export interface ValidateCodeOptions {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
strictNewMethodMaxLines?: number;
|
|
10
|
-
modifiedMethodsMaxLines?: number;
|
|
11
|
-
modifiedFilesMaxLines?: number;
|
|
18
|
+
methodMaxLimit?: MethodMaxLimitConfig;
|
|
19
|
+
fileMaxLimit?: FileMaxLimitConfig;
|
|
12
20
|
requireReturnTypeMode?: ReturnTypeMode;
|
|
13
21
|
noInlineTypeLiteralsMode?: NoInlineTypesMode;
|
|
14
22
|
noAnyUnknownMode?: NoAnyUnknownMode;
|
|
@@ -8,46 +8,70 @@ const executor_3 = tslib_1.__importDefault(require("../validate-modified-files/e
|
|
|
8
8
|
const executor_4 = tslib_1.__importDefault(require("../validate-return-types/executor"));
|
|
9
9
|
const executor_5 = tslib_1.__importDefault(require("../validate-no-inline-types/executor"));
|
|
10
10
|
const executor_6 = tslib_1.__importDefault(require("../validate-no-any-unknown/executor"));
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.log(
|
|
28
|
-
console.log(`
|
|
29
|
-
console.log(`
|
|
30
|
-
console.log(`
|
|
11
|
+
function parseConfig(options) {
|
|
12
|
+
const methodConfig = options.methodMaxLimit ?? {};
|
|
13
|
+
const fileConfig = options.fileMaxLimit ?? {};
|
|
14
|
+
return {
|
|
15
|
+
methodLimit: methodConfig.limit ?? 80,
|
|
16
|
+
methodMode: methodConfig.mode ?? 'NEW_AND_MODIFIED_METHODS',
|
|
17
|
+
methodDisableAllowed: methodConfig.disableAllowed ?? true,
|
|
18
|
+
fileLimit: fileConfig.limit ?? 900,
|
|
19
|
+
fileMode: fileConfig.mode ?? 'MODIFIED_FILES',
|
|
20
|
+
fileDisableAllowed: fileConfig.disableAllowed ?? true,
|
|
21
|
+
returnTypeMode: options.requireReturnTypeMode ?? 'OFF',
|
|
22
|
+
noInlineTypesMode: options.noInlineTypeLiteralsMode ?? 'OFF',
|
|
23
|
+
noAnyUnknownMode: options.noAnyUnknownMode ?? 'OFF',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function logConfig(config) {
|
|
27
|
+
console.log('\n\ud83d\udccf Running Code Validations\n');
|
|
28
|
+
console.log(` Method limits: mode=${config.methodMode}, limit=${config.methodLimit}, disableAllowed=${config.methodDisableAllowed}`);
|
|
29
|
+
console.log(` File limits: mode=${config.fileMode}, limit=${config.fileLimit}, disableAllowed=${config.fileDisableAllowed}`);
|
|
30
|
+
console.log(` Require return types: ${config.returnTypeMode}`);
|
|
31
|
+
console.log(` No inline type literals: ${config.noInlineTypesMode}`);
|
|
32
|
+
console.log(` No any/unknown: ${config.noAnyUnknownMode}`);
|
|
31
33
|
console.log('');
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
}
|
|
35
|
+
function isAllOff(config) {
|
|
36
|
+
return config.methodMode === 'OFF' && config.fileMode === 'OFF' &&
|
|
37
|
+
config.returnTypeMode === 'OFF' && config.noInlineTypesMode === 'OFF' &&
|
|
38
|
+
config.noAnyUnknownMode === 'OFF';
|
|
39
|
+
}
|
|
40
|
+
async function runMethodValidators(config, context) {
|
|
41
|
+
const results = [];
|
|
42
|
+
const runNew = config.methodMode === 'NEW_METHODS' || config.methodMode === 'NEW_AND_MODIFIED_METHODS';
|
|
43
|
+
const runModified = config.methodMode === 'NEW_AND_MODIFIED_METHODS' || config.methodMode === 'MODIFIED_FILES';
|
|
44
|
+
if (runNew) {
|
|
45
|
+
results.push(await (0, executor_1.default)({
|
|
46
|
+
limit: config.methodLimit,
|
|
47
|
+
mode: config.methodMode, disableAllowed: config.methodDisableAllowed,
|
|
48
|
+
}, context));
|
|
49
|
+
}
|
|
50
|
+
if (runModified) {
|
|
51
|
+
results.push(await (0, executor_2.default)({
|
|
52
|
+
limit: config.methodLimit, mode: config.methodMode, disableAllowed: config.methodDisableAllowed,
|
|
53
|
+
}, context));
|
|
47
54
|
}
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
57
|
+
async function runExecutor(options, context) {
|
|
58
|
+
const config = parseConfig(options);
|
|
59
|
+
if (isAllOff(config)) {
|
|
60
|
+
console.log('\n\u23ed\ufe0f Skipping all code validations (all modes: OFF)\n');
|
|
61
|
+
return { success: true };
|
|
50
62
|
}
|
|
63
|
+
logConfig(config);
|
|
64
|
+
const methodResults = await runMethodValidators(config, context);
|
|
65
|
+
const fileResult = await (0, executor_3.default)({
|
|
66
|
+
limit: config.fileLimit, mode: config.fileMode, disableAllowed: config.fileDisableAllowed,
|
|
67
|
+
}, context);
|
|
68
|
+
const returnTypesResult = await (0, executor_4.default)({ mode: config.returnTypeMode }, context);
|
|
69
|
+
const noInlineTypesResult = await (0, executor_5.default)({ mode: config.noInlineTypesMode }, context);
|
|
70
|
+
const noAnyUnknownResult = await (0, executor_6.default)({ mode: config.noAnyUnknownMode }, context);
|
|
71
|
+
const allSuccess = methodResults.every((r) => r.success) &&
|
|
72
|
+
fileResult.success && returnTypesResult.success &&
|
|
73
|
+
noInlineTypesResult.success && noAnyUnknownResult.success;
|
|
74
|
+
console.log(allSuccess ? '\n\u2705 All code validations passed\n' : '\n\u274c Some code validations failed\n');
|
|
51
75
|
return { success: allSuccess };
|
|
52
76
|
}
|
|
53
77
|
//# sourceMappingURL=executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-code/executor.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-code/executor.ts"],"names":[],"mappings":";;AAmGA,8BA2BC;;AA7HD,wFAAqE;AACrE,6FAA+E;AAC/E,2FAA2E;AAC3E,yFAA2F;AAC3F,4FAAmG;AACnG,2FAAgG;AAyChG,SAAS,WAAW,CAAC,OAA4B;IAC7C,MAAM,YAAY,GAAyB,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;IACxE,MAAM,UAAU,GAAuB,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;IAElE,OAAO;QACH,WAAW,EAAE,YAAY,CAAC,KAAK,IAAI,EAAE;QACrC,UAAU,EAAE,YAAY,CAAC,IAAI,IAAI,0BAA0B;Q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,GAAG,MAAM,IAAA,kBAAwB,EAAC;QAC9C,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,CAAC,kBAAkB;KAC5F,EAAE,OAAO,CAAC,CAAC;IACZ,MAAM,iBAAiB,GAAG,MAAM,IAAA,kBAAsB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IACjG,MAAM,mBAAmB,GAAG,MAAM,IAAA,kBAAwB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,iBAAiB,EAAE,EAAE,OAAO,CAAC,CAAC;IACxG,MAAM,kBAAkB,GAAG,MAAM,IAAA,kBAAuB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;IAErG,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACpD,UAAU,CAAC,OAAO,IAAI,iBAAiB,CAAC,OAAO;QAC/C,mBAAmB,CAAC,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC;IAE9D,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,wCAAwC,CAAC,CAAC,CAAC,yCAAyC,CAAC,CAAC;IAC/G,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { ExecutorContext } from '@nx/devkit';\nimport runNewMethodsExecutor from '../validate-new-methods/executor';\nimport runModifiedMethodsExecutor from '../validate-modified-methods/executor';\nimport runModifiedFilesExecutor from '../validate-modified-files/executor';\nimport runReturnTypesExecutor, { ReturnTypeMode } from '../validate-return-types/executor';\nimport runNoInlineTypesExecutor, { NoInlineTypesMode } from '../validate-no-inline-types/executor';\nimport runNoAnyUnknownExecutor, { NoAnyUnknownMode } from '../validate-no-any-unknown/executor';\n\nexport type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';\nexport type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';\n\nexport interface MethodMaxLimitConfig {\n limit?: number;\n mode?: MethodMaxLimitMode;\n disableAllowed?: boolean;\n}\n\nexport interface FileMaxLimitConfig {\n limit?: number;\n mode?: FileMaxLimitMode;\n disableAllowed?: boolean;\n}\n\nexport interface ValidateCodeOptions {\n methodMaxLimit?: MethodMaxLimitConfig;\n fileMaxLimit?: FileMaxLimitConfig;\n requireReturnTypeMode?: ReturnTypeMode;\n noInlineTypeLiteralsMode?: NoInlineTypesMode;\n noAnyUnknownMode?: NoAnyUnknownMode;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface ParsedConfig {\n methodLimit: number;\n methodMode: MethodMaxLimitMode;\n methodDisableAllowed: boolean;\n fileLimit: number;\n fileMode: FileMaxLimitMode;\n fileDisableAllowed: boolean;\n returnTypeMode: ReturnTypeMode;\n noInlineTypesMode: NoInlineTypesMode;\n noAnyUnknownMode: NoAnyUnknownMode;\n}\n\nfunction parseConfig(options: ValidateCodeOptions): ParsedConfig {\n const methodConfig: MethodMaxLimitConfig = options.methodMaxLimit ?? {};\n const fileConfig: FileMaxLimitConfig = options.fileMaxLimit ?? {};\n\n return {\n methodLimit: methodConfig.limit ?? 80,\n methodMode: methodConfig.mode ?? 'NEW_AND_MODIFIED_METHODS',\n methodDisableAllowed: methodConfig.disableAllowed ?? true,\n fileLimit: fileConfig.limit ?? 900,\n fileMode: fileConfig.mode ?? 'MODIFIED_FILES',\n fileDisableAllowed: fileConfig.disableAllowed ?? true,\n returnTypeMode: options.requireReturnTypeMode ?? 'OFF',\n noInlineTypesMode: options.noInlineTypeLiteralsMode ?? 'OFF',\n noAnyUnknownMode: options.noAnyUnknownMode ?? 'OFF',\n };\n}\n\nfunction logConfig(config: ParsedConfig): void {\n console.log('\\n\\ud83d\\udccf Running Code Validations\\n');\n console.log(` Method limits: mode=${config.methodMode}, limit=${config.methodLimit}, disableAllowed=${config.methodDisableAllowed}`);\n console.log(` File limits: mode=${config.fileMode}, limit=${config.fileLimit}, disableAllowed=${config.fileDisableAllowed}`);\n console.log(` Require return types: ${config.returnTypeMode}`);\n console.log(` No inline type literals: ${config.noInlineTypesMode}`);\n console.log(` No any/unknown: ${config.noAnyUnknownMode}`);\n console.log('');\n}\n\nfunction isAllOff(config: ParsedConfig): boolean {\n return config.methodMode === 'OFF' && config.fileMode === 'OFF' &&\n config.returnTypeMode === 'OFF' && config.noInlineTypesMode === 'OFF' &&\n config.noAnyUnknownMode === 'OFF';\n}\n\nasync function runMethodValidators(config: ParsedConfig, context: ExecutorContext): Promise<ExecutorResult[]> {\n const results: ExecutorResult[] = [];\n const runNew = config.methodMode === 'NEW_METHODS' || config.methodMode === 'NEW_AND_MODIFIED_METHODS';\n const runModified = config.methodMode === 'NEW_AND_MODIFIED_METHODS' || config.methodMode === 'MODIFIED_FILES';\n\n if (runNew) {\n results.push(await runNewMethodsExecutor({\n limit: config.methodLimit,\n mode: config.methodMode, disableAllowed: config.methodDisableAllowed,\n }, context));\n }\n if (runModified) {\n results.push(await runModifiedMethodsExecutor({\n limit: config.methodLimit, mode: config.methodMode, disableAllowed: config.methodDisableAllowed,\n }, context));\n }\n return results;\n}\n\nexport default async function runExecutor(\n options: ValidateCodeOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const config = parseConfig(options);\n\n if (isAllOff(config)) {\n console.log('\\n\\u23ed\\ufe0f Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n logConfig(config);\n\n const methodResults = await runMethodValidators(config, context);\n const fileResult = await runModifiedFilesExecutor({\n limit: config.fileLimit, mode: config.fileMode, disableAllowed: config.fileDisableAllowed,\n }, context);\n const returnTypesResult = await runReturnTypesExecutor({ mode: config.returnTypeMode }, context);\n const noInlineTypesResult = await runNoInlineTypesExecutor({ mode: config.noInlineTypesMode }, context);\n const noAnyUnknownResult = await runNoAnyUnknownExecutor({ mode: config.noAnyUnknownMode }, context);\n\n const allSuccess = methodResults.every((r) => r.success) &&\n fileResult.success && returnTypesResult.success &&\n noInlineTypesResult.success && noAnyUnknownResult.success;\n\n console.log(allSuccess ? '\\n\\u2705 All code validations passed\\n' : '\\n\\u274c Some code validations failed\\n');\n return { success: allSuccess };\n}\n"]}
|
|
@@ -6,14 +6,24 @@ import runReturnTypesExecutor, { ReturnTypeMode } from '../validate-return-types
|
|
|
6
6
|
import runNoInlineTypesExecutor, { NoInlineTypesMode } from '../validate-no-inline-types/executor';
|
|
7
7
|
import runNoAnyUnknownExecutor, { NoAnyUnknownMode } from '../validate-no-any-unknown/executor';
|
|
8
8
|
|
|
9
|
-
export type
|
|
9
|
+
export type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';
|
|
10
|
+
export type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';
|
|
11
|
+
|
|
12
|
+
export interface MethodMaxLimitConfig {
|
|
13
|
+
limit?: number;
|
|
14
|
+
mode?: MethodMaxLimitMode;
|
|
15
|
+
disableAllowed?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface FileMaxLimitConfig {
|
|
19
|
+
limit?: number;
|
|
20
|
+
mode?: FileMaxLimitMode;
|
|
21
|
+
disableAllowed?: boolean;
|
|
22
|
+
}
|
|
10
23
|
|
|
11
24
|
export interface ValidateCodeOptions {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
strictNewMethodMaxLines?: number;
|
|
15
|
-
modifiedMethodsMaxLines?: number;
|
|
16
|
-
modifiedFilesMaxLines?: number;
|
|
25
|
+
methodMaxLimit?: MethodMaxLimitConfig;
|
|
26
|
+
fileMaxLimit?: FileMaxLimitConfig;
|
|
17
27
|
requireReturnTypeMode?: ReturnTypeMode;
|
|
18
28
|
noInlineTypeLiteralsMode?: NoInlineTypesMode;
|
|
19
29
|
noAnyUnknownMode?: NoAnyUnknownMode;
|
|
@@ -23,69 +33,95 @@ export interface ExecutorResult {
|
|
|
23
33
|
success: boolean;
|
|
24
34
|
}
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
interface ParsedConfig {
|
|
37
|
+
methodLimit: number;
|
|
38
|
+
methodMode: MethodMaxLimitMode;
|
|
39
|
+
methodDisableAllowed: boolean;
|
|
40
|
+
fileLimit: number;
|
|
41
|
+
fileMode: FileMaxLimitMode;
|
|
42
|
+
fileDisableAllowed: boolean;
|
|
43
|
+
returnTypeMode: ReturnTypeMode;
|
|
44
|
+
noInlineTypesMode: NoInlineTypesMode;
|
|
45
|
+
noAnyUnknownMode: NoAnyUnknownMode;
|
|
46
|
+
}
|
|
36
47
|
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
48
|
+
function parseConfig(options: ValidateCodeOptions): ParsedConfig {
|
|
49
|
+
const methodConfig: MethodMaxLimitConfig = options.methodMaxLimit ?? {};
|
|
50
|
+
const fileConfig: FileMaxLimitConfig = options.fileMaxLimit ?? {};
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
methodLimit: methodConfig.limit ?? 80,
|
|
54
|
+
methodMode: methodConfig.mode ?? 'NEW_AND_MODIFIED_METHODS',
|
|
55
|
+
methodDisableAllowed: methodConfig.disableAllowed ?? true,
|
|
56
|
+
fileLimit: fileConfig.limit ?? 900,
|
|
57
|
+
fileMode: fileConfig.mode ?? 'MODIFIED_FILES',
|
|
58
|
+
fileDisableAllowed: fileConfig.disableAllowed ?? true,
|
|
59
|
+
returnTypeMode: options.requireReturnTypeMode ?? 'OFF',
|
|
60
|
+
noInlineTypesMode: options.noInlineTypeLiteralsMode ?? 'OFF',
|
|
61
|
+
noAnyUnknownMode: options.noAnyUnknownMode ?? 'OFF',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
40
64
|
|
|
41
|
-
|
|
42
|
-
console.log(
|
|
43
|
-
console.log(`
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
console.log(`
|
|
48
|
-
console.log(` Modified files max: ${options.modifiedFilesMaxLines ?? 900} lines`);
|
|
49
|
-
console.log(` Require return types: ${returnTypeMode}`);
|
|
50
|
-
console.log(` No inline type literals: ${noInlineTypesMode}`);
|
|
51
|
-
console.log(` No any/unknown: ${noAnyUnknownMode}`);
|
|
65
|
+
function logConfig(config: ParsedConfig): void {
|
|
66
|
+
console.log('\n\ud83d\udccf Running Code Validations\n');
|
|
67
|
+
console.log(` Method limits: mode=${config.methodMode}, limit=${config.methodLimit}, disableAllowed=${config.methodDisableAllowed}`);
|
|
68
|
+
console.log(` File limits: mode=${config.fileMode}, limit=${config.fileLimit}, disableAllowed=${config.fileDisableAllowed}`);
|
|
69
|
+
console.log(` Require return types: ${config.returnTypeMode}`);
|
|
70
|
+
console.log(` No inline type literals: ${config.noInlineTypesMode}`);
|
|
71
|
+
console.log(` No any/unknown: ${config.noAnyUnknownMode}`);
|
|
52
72
|
console.log('');
|
|
73
|
+
}
|
|
53
74
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
function isAllOff(config: ParsedConfig): boolean {
|
|
76
|
+
return config.methodMode === 'OFF' && config.fileMode === 'OFF' &&
|
|
77
|
+
config.returnTypeMode === 'OFF' && config.noInlineTypesMode === 'OFF' &&
|
|
78
|
+
config.noAnyUnknownMode === 'OFF';
|
|
79
|
+
}
|
|
59
80
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
81
|
+
async function runMethodValidators(config: ParsedConfig, context: ExecutorContext): Promise<ExecutorResult[]> {
|
|
82
|
+
const results: ExecutorResult[] = [];
|
|
83
|
+
const runNew = config.methodMode === 'NEW_METHODS' || config.methodMode === 'NEW_AND_MODIFIED_METHODS';
|
|
84
|
+
const runModified = config.methodMode === 'NEW_AND_MODIFIED_METHODS' || config.methodMode === 'MODIFIED_FILES';
|
|
64
85
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
86
|
+
if (runNew) {
|
|
87
|
+
results.push(await runNewMethodsExecutor({
|
|
88
|
+
limit: config.methodLimit,
|
|
89
|
+
mode: config.methodMode, disableAllowed: config.methodDisableAllowed,
|
|
90
|
+
}, context));
|
|
91
|
+
}
|
|
92
|
+
if (runModified) {
|
|
93
|
+
results.push(await runModifiedMethodsExecutor({
|
|
94
|
+
limit: config.methodLimit, mode: config.methodMode, disableAllowed: config.methodDisableAllowed,
|
|
95
|
+
}, context));
|
|
96
|
+
}
|
|
97
|
+
return results;
|
|
98
|
+
}
|
|
69
99
|
|
|
70
|
-
|
|
100
|
+
export default async function runExecutor(
|
|
101
|
+
options: ValidateCodeOptions,
|
|
102
|
+
context: ExecutorContext
|
|
103
|
+
): Promise<ExecutorResult> {
|
|
104
|
+
const config = parseConfig(options);
|
|
71
105
|
|
|
72
|
-
|
|
106
|
+
if (isAllOff(config)) {
|
|
107
|
+
console.log('\n\u23ed\ufe0f Skipping all code validations (all modes: OFF)\n');
|
|
108
|
+
return { success: true };
|
|
109
|
+
}
|
|
73
110
|
|
|
74
|
-
|
|
111
|
+
logConfig(config);
|
|
75
112
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
113
|
+
const methodResults = await runMethodValidators(config, context);
|
|
114
|
+
const fileResult = await runModifiedFilesExecutor({
|
|
115
|
+
limit: config.fileLimit, mode: config.fileMode, disableAllowed: config.fileDisableAllowed,
|
|
116
|
+
}, context);
|
|
117
|
+
const returnTypesResult = await runReturnTypesExecutor({ mode: config.returnTypeMode }, context);
|
|
118
|
+
const noInlineTypesResult = await runNoInlineTypesExecutor({ mode: config.noInlineTypesMode }, context);
|
|
119
|
+
const noAnyUnknownResult = await runNoAnyUnknownExecutor({ mode: config.noAnyUnknownMode }, context);
|
|
83
120
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
console.log('\n❌ Some code validations failed\n');
|
|
88
|
-
}
|
|
121
|
+
const allSuccess = methodResults.every((r) => r.success) &&
|
|
122
|
+
fileResult.success && returnTypesResult.success &&
|
|
123
|
+
noInlineTypesResult.success && noAnyUnknownResult.success;
|
|
89
124
|
|
|
125
|
+
console.log(allSuccess ? '\n\u2705 All code validations passed\n' : '\n\u274c Some code validations failed\n');
|
|
90
126
|
return { success: allSuccess };
|
|
91
127
|
}
|
|
@@ -4,47 +4,66 @@
|
|
|
4
4
|
"description": "Combined validation for new methods, modified methods, and file sizes. Configure via targetDefaults in nx.json for runtime options (no cache issues).",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
7
|
-
"
|
|
8
|
-
"type": "
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
"methodMaxLimit": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"description": "Configuration for method line limit validation",
|
|
10
|
+
"properties": {
|
|
11
|
+
"limit": {
|
|
12
|
+
"type": "number",
|
|
13
|
+
"description": "Maximum lines allowed for methods",
|
|
14
|
+
"default": 80
|
|
15
|
+
},
|
|
16
|
+
"mode": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"enum": ["OFF", "NEW_METHODS", "NEW_AND_MODIFIED_METHODS", "MODIFIED_FILES"],
|
|
19
|
+
"description": "OFF: skip validation. NEW_METHODS: only new methods in diff. NEW_AND_MODIFIED_METHODS: new methods + methods with changes. MODIFIED_FILES: all methods in modified files.",
|
|
20
|
+
"default": "NEW_AND_MODIFIED_METHODS"
|
|
21
|
+
},
|
|
22
|
+
"disableAllowed": {
|
|
23
|
+
"type": "boolean",
|
|
24
|
+
"description": "Whether disable comments work. When false, no escape hatch (like old STRICT mode).",
|
|
25
|
+
"default": true
|
|
26
|
+
}
|
|
27
|
+
}
|
|
26
28
|
},
|
|
27
|
-
"
|
|
28
|
-
"type": "
|
|
29
|
-
"description": "
|
|
30
|
-
"
|
|
29
|
+
"fileMaxLimit": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"description": "Configuration for file line limit validation",
|
|
32
|
+
"properties": {
|
|
33
|
+
"limit": {
|
|
34
|
+
"type": "number",
|
|
35
|
+
"description": "Maximum lines for modified files",
|
|
36
|
+
"default": 900
|
|
37
|
+
},
|
|
38
|
+
"mode": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"enum": ["OFF", "MODIFIED_FILES"],
|
|
41
|
+
"description": "OFF: skip validation. MODIFIED_FILES: all code in modified files.",
|
|
42
|
+
"default": "MODIFIED_FILES"
|
|
43
|
+
},
|
|
44
|
+
"disableAllowed": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"description": "Whether disable comments work. When false, no escape hatch (like old STRICT mode).",
|
|
47
|
+
"default": true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
31
50
|
},
|
|
32
51
|
"requireReturnTypeMode": {
|
|
33
52
|
"type": "string",
|
|
34
|
-
"enum": ["OFF", "NEW_METHODS", "
|
|
35
|
-
"description": "OFF: skip return type validation. NEW_METHODS: only new methods in diff.
|
|
53
|
+
"enum": ["OFF", "NEW_METHODS", "NEW_AND_MODIFIED_METHODS", "MODIFIED_FILES"],
|
|
54
|
+
"description": "OFF: skip return type validation. NEW_METHODS: only new methods in diff. NEW_AND_MODIFIED_METHODS: new methods + methods with changes. MODIFIED_FILES: all methods in modified files.",
|
|
36
55
|
"default": "OFF"
|
|
37
56
|
},
|
|
38
57
|
"noInlineTypeLiteralsMode": {
|
|
39
58
|
"type": "string",
|
|
40
|
-
"enum": ["OFF", "NEW_METHODS", "
|
|
41
|
-
"description": "OFF: skip validation. NEW_METHODS: only new methods.
|
|
59
|
+
"enum": ["OFF", "NEW_METHODS", "NEW_AND_MODIFIED_METHODS", "MODIFIED_FILES"],
|
|
60
|
+
"description": "OFF: skip validation. NEW_METHODS: only new methods. NEW_AND_MODIFIED_METHODS: new + modified methods. MODIFIED_FILES: all in modified files. Disallows inline type literals like { x: number } - use named types instead.",
|
|
42
61
|
"default": "OFF"
|
|
43
62
|
},
|
|
44
63
|
"noAnyUnknownMode": {
|
|
45
64
|
"type": "string",
|
|
46
|
-
"enum": ["OFF", "MODIFIED_CODE", "MODIFIED_FILES"
|
|
47
|
-
"description": "OFF: skip validation. MODIFIED_CODE: only changed lines in diff. MODIFIED_FILES: all in modified files.
|
|
65
|
+
"enum": ["OFF", "MODIFIED_CODE", "MODIFIED_FILES"],
|
|
66
|
+
"description": "OFF: skip validation. MODIFIED_CODE: only changed lines in diff. MODIFIED_FILES: all in modified files. Disallows `any` and `unknown` TypeScript keywords.",
|
|
48
67
|
"default": "OFF"
|
|
49
68
|
}
|
|
50
69
|
},
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
* The disable expires after 1 month from the date specified.
|
|
14
14
|
*/
|
|
15
15
|
import type { ExecutorContext } from '@nx/devkit';
|
|
16
|
-
export type
|
|
16
|
+
export type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';
|
|
17
17
|
export interface ValidateModifiedFilesOptions {
|
|
18
|
-
|
|
19
|
-
mode?:
|
|
18
|
+
limit?: number;
|
|
19
|
+
mode?: FileMaxLimitMode;
|
|
20
|
+
disableAllowed?: boolean;
|
|
20
21
|
}
|
|
21
22
|
export interface ExecutorResult {
|
|
22
23
|
success: boolean;
|