@webpieces/dev-config 0.2.72 ā 0.2.74
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 +2 -0
- package/architecture/executors/validate-code/executor.js +6 -1
- package/architecture/executors/validate-code/executor.js.map +1 -1
- package/architecture/executors/validate-code/executor.ts +8 -1
- package/architecture/executors/validate-code/schema.json +8 -2
- package/architecture/executors/validate-no-inline-types/executor.d.ts +30 -0
- package/architecture/executors/validate-no-inline-types/executor.js +550 -0
- package/architecture/executors/validate-no-inline-types/executor.js.map +1 -0
- package/architecture/executors/validate-no-inline-types/executor.ts +649 -0
- package/architecture/executors/validate-no-inline-types/schema.json +15 -0
- package/architecture/executors/validate-return-types/executor.d.ts +4 -3
- package/architecture/executors/validate-return-types/executor.js +92 -14
- package/architecture/executors/validate-return-types/executor.js.map +1 -1
- package/architecture/executors/validate-return-types/executor.ts +106 -15
- package/architecture/executors/validate-return-types/schema.json +3 -3
- package/executors.json +5 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { ReturnTypeMode } from '../validate-return-types/executor';
|
|
3
|
+
import { NoInlineTypesMode } from '../validate-no-inline-types/executor';
|
|
3
4
|
export type ValidationMode = 'STRICT' | 'NORMAL' | 'OFF';
|
|
4
5
|
export interface ValidateCodeOptions {
|
|
5
6
|
mode?: ValidationMode;
|
|
@@ -8,6 +9,7 @@ export interface ValidateCodeOptions {
|
|
|
8
9
|
modifiedMethodsMaxLines?: number;
|
|
9
10
|
modifiedFilesMaxLines?: number;
|
|
10
11
|
requireReturnTypeMode?: ReturnTypeMode;
|
|
12
|
+
noInlineTypeLiteralsMode?: NoInlineTypesMode;
|
|
11
13
|
}
|
|
12
14
|
export interface ExecutorResult {
|
|
13
15
|
success: boolean;
|
|
@@ -6,6 +6,7 @@ const executor_1 = tslib_1.__importDefault(require("../validate-new-methods/exec
|
|
|
6
6
|
const executor_2 = tslib_1.__importDefault(require("../validate-modified-methods/executor"));
|
|
7
7
|
const executor_3 = tslib_1.__importDefault(require("../validate-modified-files/executor"));
|
|
8
8
|
const executor_4 = tslib_1.__importDefault(require("../validate-return-types/executor"));
|
|
9
|
+
const executor_5 = tslib_1.__importDefault(require("../validate-no-inline-types/executor"));
|
|
9
10
|
async function runExecutor(options, context) {
|
|
10
11
|
const mode = options.mode ?? 'NORMAL';
|
|
11
12
|
if (mode === 'OFF') {
|
|
@@ -13,6 +14,7 @@ async function runExecutor(options, context) {
|
|
|
13
14
|
return { success: true };
|
|
14
15
|
}
|
|
15
16
|
const returnTypeMode = options.requireReturnTypeMode ?? 'OFF';
|
|
17
|
+
const noInlineTypesMode = options.noInlineTypeLiteralsMode ?? 'OFF';
|
|
16
18
|
console.log('\nš Running Code Validations\n');
|
|
17
19
|
console.log(` Validation mode: ${mode}${mode === 'STRICT' ? ' (disable comments ignored for modified code)' : ''}`);
|
|
18
20
|
console.log(` New methods max: ${options.newMethodsMaxLines ?? 30} lines (soft limit)`);
|
|
@@ -22,16 +24,19 @@ async function runExecutor(options, context) {
|
|
|
22
24
|
console.log(` Modified methods max: ${options.modifiedMethodsMaxLines ?? 80} lines`);
|
|
23
25
|
console.log(` Modified files max: ${options.modifiedFilesMaxLines ?? 900} lines`);
|
|
24
26
|
console.log(` Require return types: ${returnTypeMode}`);
|
|
27
|
+
console.log(` No inline type literals: ${noInlineTypesMode}`);
|
|
25
28
|
console.log('');
|
|
26
29
|
// Run all three validators sequentially to avoid interleaved output
|
|
27
30
|
const newMethodsResult = await (0, executor_1.default)({ max: options.newMethodsMaxLines ?? 30, strictMax: options.strictNewMethodMaxLines, mode }, context);
|
|
28
31
|
const modifiedMethodsResult = await (0, executor_2.default)({ max: options.modifiedMethodsMaxLines ?? 80, mode }, context);
|
|
29
32
|
const modifiedFilesResult = await (0, executor_3.default)({ max: options.modifiedFilesMaxLines ?? 900, mode }, context);
|
|
30
33
|
const returnTypesResult = await (0, executor_4.default)({ mode: returnTypeMode }, context);
|
|
34
|
+
const noInlineTypesResult = await (0, executor_5.default)({ mode: noInlineTypesMode }, context);
|
|
31
35
|
const allSuccess = newMethodsResult.success &&
|
|
32
36
|
modifiedMethodsResult.success &&
|
|
33
37
|
modifiedFilesResult.success &&
|
|
34
|
-
returnTypesResult.success
|
|
38
|
+
returnTypesResult.success &&
|
|
39
|
+
noInlineTypesResult.success;
|
|
35
40
|
if (allSuccess) {
|
|
36
41
|
console.log('\nā
All code validations passed\n');
|
|
37
42
|
}
|
|
@@ -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":";;AAuBA,8BA4DC;;AAlFD,wFAAqE;AACrE,6FAA+E;AAC/E,2FAA2E;AAC3E,yFAA2F;AAC3F,4FAAmG;AAkBpF,KAAK,UAAU,WAAW,CACrC,OAA4B,EAC5B,OAAwB;IAExB,MAAM,IAAI,GAAmB,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC;IAEtD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAC;QAC3E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,MAAM,cAAc,GAAmB,OAAO,CAAC,qBAAqB,IAAI,KAAK,CAAC;IAC9E,MAAM,iBAAiB,GAAsB,OAAO,CAAC,wBAAwB,IAAI,KAAK,CAAC;IAEvF,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,+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AE1F,MAAM,mBAAmB,GAAG,MAAM,IAAA,kBAAwB,EAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,OAAO,CAAC,CAAC;IAEjG,MAAM,UAAU,GACZ,gBAAgB,CAAC,OAAO;QACxB,qBAAqB,CAAC,OAAO;QAC7B,mBAAmB,CAAC,OAAO;QAC3B,iBAAiB,CAAC,OAAO;QACzB,mBAAmB,CAAC,OAAO,CAAC;IAEhC,IAAI,UAAU,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IACtD,CAAC;IAED,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';\n\nexport type ValidationMode = 'STRICT' | 'NORMAL' | 'OFF';\n\nexport interface ValidateCodeOptions {\n mode?: ValidationMode;\n newMethodsMaxLines?: number;\n strictNewMethodMaxLines?: number;\n modifiedMethodsMaxLines?: number;\n modifiedFilesMaxLines?: number;\n requireReturnTypeMode?: ReturnTypeMode;\n noInlineTypeLiteralsMode?: NoInlineTypesMode;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\nexport default async function runExecutor(\n options: ValidateCodeOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const mode: ValidationMode = options.mode ?? 'NORMAL';\n\n if (mode === 'OFF') {\n console.log('\\nāļø Skipping all code validations (validationMode: OFF)\\n');\n return { success: true };\n }\n\n const returnTypeMode: ReturnTypeMode = options.requireReturnTypeMode ?? 'OFF';\n const noInlineTypesMode: NoInlineTypesMode = options.noInlineTypeLiteralsMode ?? 'OFF';\n\n console.log('\\nš Running Code Validations\\n');\n console.log(` Validation mode: ${mode}${mode === 'STRICT' ? ' (disable comments ignored for modified code)' : ''}`);\n console.log(` New methods max: ${options.newMethodsMaxLines ?? 30} lines (soft limit)`);\n if (options.strictNewMethodMaxLines) {\n console.log(` New methods max: ${options.strictNewMethodMaxLines} lines (hard limit, no escape)`);\n }\n console.log(` Modified methods max: ${options.modifiedMethodsMaxLines ?? 80} lines`);\n console.log(` Modified files max: ${options.modifiedFilesMaxLines ?? 900} lines`);\n console.log(` Require return types: ${returnTypeMode}`);\n console.log(` No inline type literals: ${noInlineTypesMode}`);\n console.log('');\n\n // Run all three validators sequentially to avoid interleaved output\n const newMethodsResult = await runNewMethodsExecutor(\n { max: options.newMethodsMaxLines ?? 30, strictMax: options.strictNewMethodMaxLines, mode },\n context\n );\n\n const modifiedMethodsResult = await runModifiedMethodsExecutor(\n { max: options.modifiedMethodsMaxLines ?? 80, mode },\n context\n );\n\n const modifiedFilesResult = await runModifiedFilesExecutor(\n { max: options.modifiedFilesMaxLines ?? 900, mode },\n context\n );\n\n const returnTypesResult = await runReturnTypesExecutor({ mode: returnTypeMode }, context);\n\n const noInlineTypesResult = await runNoInlineTypesExecutor({ mode: noInlineTypesMode }, context);\n\n const allSuccess =\n newMethodsResult.success &&\n modifiedMethodsResult.success &&\n modifiedFilesResult.success &&\n returnTypesResult.success &&\n noInlineTypesResult.success;\n\n if (allSuccess) {\n console.log('\\nā
All code validations passed\\n');\n } else {\n console.log('\\nā Some code validations failed\\n');\n }\n\n return { success: allSuccess };\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import runNewMethodsExecutor from '../validate-new-methods/executor';
|
|
|
3
3
|
import runModifiedMethodsExecutor from '../validate-modified-methods/executor';
|
|
4
4
|
import runModifiedFilesExecutor from '../validate-modified-files/executor';
|
|
5
5
|
import runReturnTypesExecutor, { ReturnTypeMode } from '../validate-return-types/executor';
|
|
6
|
+
import runNoInlineTypesExecutor, { NoInlineTypesMode } from '../validate-no-inline-types/executor';
|
|
6
7
|
|
|
7
8
|
export type ValidationMode = 'STRICT' | 'NORMAL' | 'OFF';
|
|
8
9
|
|
|
@@ -13,6 +14,7 @@ export interface ValidateCodeOptions {
|
|
|
13
14
|
modifiedMethodsMaxLines?: number;
|
|
14
15
|
modifiedFilesMaxLines?: number;
|
|
15
16
|
requireReturnTypeMode?: ReturnTypeMode;
|
|
17
|
+
noInlineTypeLiteralsMode?: NoInlineTypesMode;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export interface ExecutorResult {
|
|
@@ -31,6 +33,7 @@ export default async function runExecutor(
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
const returnTypeMode: ReturnTypeMode = options.requireReturnTypeMode ?? 'OFF';
|
|
36
|
+
const noInlineTypesMode: NoInlineTypesMode = options.noInlineTypeLiteralsMode ?? 'OFF';
|
|
34
37
|
|
|
35
38
|
console.log('\nš Running Code Validations\n');
|
|
36
39
|
console.log(` Validation mode: ${mode}${mode === 'STRICT' ? ' (disable comments ignored for modified code)' : ''}`);
|
|
@@ -41,6 +44,7 @@ export default async function runExecutor(
|
|
|
41
44
|
console.log(` Modified methods max: ${options.modifiedMethodsMaxLines ?? 80} lines`);
|
|
42
45
|
console.log(` Modified files max: ${options.modifiedFilesMaxLines ?? 900} lines`);
|
|
43
46
|
console.log(` Require return types: ${returnTypeMode}`);
|
|
47
|
+
console.log(` No inline type literals: ${noInlineTypesMode}`);
|
|
44
48
|
console.log('');
|
|
45
49
|
|
|
46
50
|
// Run all three validators sequentially to avoid interleaved output
|
|
@@ -61,11 +65,14 @@ export default async function runExecutor(
|
|
|
61
65
|
|
|
62
66
|
const returnTypesResult = await runReturnTypesExecutor({ mode: returnTypeMode }, context);
|
|
63
67
|
|
|
68
|
+
const noInlineTypesResult = await runNoInlineTypesExecutor({ mode: noInlineTypesMode }, context);
|
|
69
|
+
|
|
64
70
|
const allSuccess =
|
|
65
71
|
newMethodsResult.success &&
|
|
66
72
|
modifiedMethodsResult.success &&
|
|
67
73
|
modifiedFilesResult.success &&
|
|
68
|
-
returnTypesResult.success
|
|
74
|
+
returnTypesResult.success &&
|
|
75
|
+
noInlineTypesResult.success;
|
|
69
76
|
|
|
70
77
|
if (allSuccess) {
|
|
71
78
|
console.log('\nā
All code validations passed\n');
|
|
@@ -31,8 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"requireReturnTypeMode": {
|
|
33
33
|
"type": "string",
|
|
34
|
-
"enum": ["OFF", "
|
|
35
|
-
"description": "OFF: skip return type validation.
|
|
34
|
+
"enum": ["OFF", "NEW_METHODS", "MODIFIED_AND_NEW_METHODS", "MODIFIED_FILES", "ALL"],
|
|
35
|
+
"description": "OFF: skip return type validation. NEW_METHODS: only new methods in diff. MODIFIED_AND_NEW_METHODS: new methods + methods with changes. MODIFIED_FILES: all methods in modified files. ALL: all methods everywhere.",
|
|
36
|
+
"default": "OFF"
|
|
37
|
+
},
|
|
38
|
+
"noInlineTypeLiteralsMode": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"enum": ["OFF", "NEW_METHODS", "MODIFIED_AND_NEW_METHODS", "MODIFIED_FILES", "ALL"],
|
|
41
|
+
"description": "OFF: skip validation. NEW_METHODS: only new methods. MODIFIED_AND_NEW_METHODS: new + modified methods. MODIFIED_FILES: all in modified files. ALL: everywhere. Disallows inline type literals like { x: number } - use named types instead.",
|
|
36
42
|
"default": "OFF"
|
|
37
43
|
}
|
|
38
44
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate No Inline Types Executor
|
|
3
|
+
*
|
|
4
|
+
* Validates that inline type literals are not used - prefer named types/interfaces/classes.
|
|
5
|
+
* Instead of anonymous object types, use named types for clarity and reusability:
|
|
6
|
+
*
|
|
7
|
+
* BAD: function foo(arg: { x: number }) { }
|
|
8
|
+
* GOOD: function foo(arg: MyConfig) { }
|
|
9
|
+
*
|
|
10
|
+
* BAD: type Nullable = { x: number } | null;
|
|
11
|
+
* GOOD: type MyData = { x: number }; type Nullable = MyData | null;
|
|
12
|
+
*
|
|
13
|
+
* Modes:
|
|
14
|
+
* - OFF: Skip validation entirely
|
|
15
|
+
* - NEW_METHODS: Only validate inline types in new methods (detected via git diff)
|
|
16
|
+
* - MODIFIED_AND_NEW_METHODS: Validate in new methods + methods with changes in their line range
|
|
17
|
+
* - MODIFIED_FILES: Validate all inline types in modified files
|
|
18
|
+
* - ALL: Validate all inline types in all TypeScript files
|
|
19
|
+
*
|
|
20
|
+
* Escape hatch: Add webpieces-disable no-inline-types comment with justification
|
|
21
|
+
*/
|
|
22
|
+
import type { ExecutorContext } from '@nx/devkit';
|
|
23
|
+
export type NoInlineTypesMode = 'OFF' | 'NEW_METHODS' | 'MODIFIED_AND_NEW_METHODS' | 'MODIFIED_FILES' | 'ALL';
|
|
24
|
+
export interface ValidateNoInlineTypesOptions {
|
|
25
|
+
mode?: NoInlineTypesMode;
|
|
26
|
+
}
|
|
27
|
+
export interface ExecutorResult {
|
|
28
|
+
success: boolean;
|
|
29
|
+
}
|
|
30
|
+
export default function runExecutor(options: ValidateNoInlineTypesOptions, context: ExecutorContext): Promise<ExecutorResult>;
|