@webpieces/code-rules 0.0.1
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/LICENSE +373 -0
- package/jest.config.ts +20 -0
- package/package.json +23 -0
- package/project.json +22 -0
- package/src/cli.ts +17 -0
- package/src/diff-utils.ts +129 -0
- package/src/from-shared-config.ts +118 -0
- package/src/index.ts +14 -0
- package/src/validate-catch-error-pattern.ts +639 -0
- package/src/validate-code.ts +491 -0
- package/src/validate-dtos.ts +697 -0
- package/src/validate-modified-files.ts +579 -0
- package/src/validate-modified-methods.ts +812 -0
- package/src/validate-new-methods.ts +594 -0
- package/src/validate-no-any-unknown.ts +552 -0
- package/src/validate-no-destructure.ts +588 -0
- package/src/validate-no-direct-api-resolver.ts +676 -0
- package/src/validate-no-implicit-any.ts +378 -0
- package/src/validate-no-inline-types.ts +787 -0
- package/src/validate-no-unmanaged-exceptions.ts +431 -0
- package/src/validate-prisma-converters.ts +830 -0
- package/src/validate-return-types.ts +532 -0
- package/tsconfig.json +22 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +14 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter: map @webpieces/rules-config ResolvedConfig -> legacy ValidateCodeOptions.
|
|
3
|
+
*
|
|
4
|
+
* We don't want to rewrite the 11 sub-executors in this PR, so this file
|
|
5
|
+
* takes the shared webpieces.config.json entries (kebab-case rule names)
|
|
6
|
+
* and reconstructs the camelCase ValidateCodeOptions shape the executor
|
|
7
|
+
* already understands.
|
|
8
|
+
*
|
|
9
|
+
* Mapping of canonical kebab-case rule name -> ValidateCodeOptions field:
|
|
10
|
+
* max-method-lines -> methodMaxLimit
|
|
11
|
+
* max-file-lines -> fileMaxLimit
|
|
12
|
+
* require-return-type -> requireReturnType
|
|
13
|
+
* no-inline-type-literals -> noInlineTypeLiterals
|
|
14
|
+
* no-any-unknown -> noAnyUnknown
|
|
15
|
+
* no-implicit-any -> noImplicitAny
|
|
16
|
+
* validate-dtos -> validateDtos
|
|
17
|
+
* prisma-converter -> prismaConverter
|
|
18
|
+
* no-destructure -> noDestructure
|
|
19
|
+
* catch-error-pattern -> catchErrorPattern
|
|
20
|
+
* no-unmanaged-exceptions -> noUnmanagedExceptions
|
|
21
|
+
* no-direct-api-in-resolver -> noDirectApiInResolver
|
|
22
|
+
*
|
|
23
|
+
* A rule entry with enabled:false is surfaced as mode:'OFF' so the
|
|
24
|
+
* downstream executor short-circuits the same way it did before.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import type { ResolvedConfig, ResolvedRuleConfig } from '@webpieces/rules-config';
|
|
28
|
+
import type { ValidateCodeOptions } from './validate-code';
|
|
29
|
+
|
|
30
|
+
// webpieces-disable no-any-unknown -- coerces opaque option values pulled from JSON
|
|
31
|
+
function opt<T>(rule: ResolvedRuleConfig | undefined, key: string): T | undefined {
|
|
32
|
+
if (!rule) return undefined;
|
|
33
|
+
const value = rule.options[key];
|
|
34
|
+
if (value === undefined) return undefined;
|
|
35
|
+
return value as T;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function modeOrOff<T extends string>(rule: ResolvedRuleConfig | undefined): T | undefined {
|
|
39
|
+
if (!rule) return undefined;
|
|
40
|
+
if (rule.enabled === false) return 'OFF' as T;
|
|
41
|
+
const mode = rule.options['mode'];
|
|
42
|
+
return (mode as T) ?? undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function toValidateCodeOptions(shared: ResolvedConfig): ValidateCodeOptions {
|
|
46
|
+
const r = (name: string): ResolvedRuleConfig | undefined => shared.rules.get(name);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
methodMaxLimit: {
|
|
50
|
+
limit: opt<number>(r('max-method-lines'), 'limit'),
|
|
51
|
+
mode: modeOrOff(r('max-method-lines')),
|
|
52
|
+
disableAllowed: opt<boolean>(r('max-method-lines'), 'disableAllowed'),
|
|
53
|
+
ignoreModifiedUntilEpoch: opt<number>(r('max-method-lines'), 'ignoreModifiedUntilEpoch'),
|
|
54
|
+
},
|
|
55
|
+
fileMaxLimit: {
|
|
56
|
+
limit: opt<number>(r('max-file-lines'), 'limit'),
|
|
57
|
+
mode: modeOrOff(r('max-file-lines')),
|
|
58
|
+
disableAllowed: opt<boolean>(r('max-file-lines'), 'disableAllowed'),
|
|
59
|
+
ignoreModifiedUntilEpoch: opt<number>(r('max-file-lines'), 'ignoreModifiedUntilEpoch'),
|
|
60
|
+
},
|
|
61
|
+
requireReturnType: {
|
|
62
|
+
mode: modeOrOff(r('require-return-type')),
|
|
63
|
+
disableAllowed: opt<boolean>(r('require-return-type'), 'disableAllowed'),
|
|
64
|
+
ignoreModifiedUntilEpoch: opt<number>(r('require-return-type'), 'ignoreModifiedUntilEpoch'),
|
|
65
|
+
},
|
|
66
|
+
noInlineTypeLiterals: {
|
|
67
|
+
mode: modeOrOff(r('no-inline-type-literals')),
|
|
68
|
+
disableAllowed: opt<boolean>(r('no-inline-type-literals'), 'disableAllowed'),
|
|
69
|
+
ignoreModifiedUntilEpoch: opt<number>(r('no-inline-type-literals'), 'ignoreModifiedUntilEpoch'),
|
|
70
|
+
},
|
|
71
|
+
noAnyUnknown: {
|
|
72
|
+
mode: modeOrOff(r('no-any-unknown')),
|
|
73
|
+
disableAllowed: opt<boolean>(r('no-any-unknown'), 'disableAllowed'),
|
|
74
|
+
ignoreModifiedUntilEpoch: opt<number>(r('no-any-unknown'), 'ignoreModifiedUntilEpoch'),
|
|
75
|
+
},
|
|
76
|
+
noImplicitAny: {
|
|
77
|
+
mode: modeOrOff(r('no-implicit-any')),
|
|
78
|
+
disableAllowed: opt<boolean>(r('no-implicit-any'), 'disableAllowed'),
|
|
79
|
+
ignoreModifiedUntilEpoch: opt<number>(r('no-implicit-any'), 'ignoreModifiedUntilEpoch'),
|
|
80
|
+
},
|
|
81
|
+
validateDtos: {
|
|
82
|
+
mode: modeOrOff(r('validate-dtos')),
|
|
83
|
+
disableAllowed: opt<boolean>(r('validate-dtos'), 'disableAllowed'),
|
|
84
|
+
prismaSchemaPath: opt<string>(r('validate-dtos'), 'prismaSchemaPath'),
|
|
85
|
+
dtoSourcePaths: opt<string[]>(r('validate-dtos'), 'dtoSourcePaths'),
|
|
86
|
+
ignoreModifiedUntilEpoch: opt<number>(r('validate-dtos'), 'ignoreModifiedUntilEpoch'),
|
|
87
|
+
},
|
|
88
|
+
prismaConverter: {
|
|
89
|
+
mode: modeOrOff(r('prisma-converter')),
|
|
90
|
+
disableAllowed: opt<boolean>(r('prisma-converter'), 'disableAllowed'),
|
|
91
|
+
schemaPath: opt<string>(r('prisma-converter'), 'schemaPath'),
|
|
92
|
+
convertersPaths: opt<string[]>(r('prisma-converter'), 'convertersPaths'),
|
|
93
|
+
enforcePaths: opt<string[]>(r('prisma-converter'), 'enforcePaths'),
|
|
94
|
+
ignoreModifiedUntilEpoch: opt<number>(r('prisma-converter'), 'ignoreModifiedUntilEpoch'),
|
|
95
|
+
},
|
|
96
|
+
noDestructure: {
|
|
97
|
+
mode: modeOrOff(r('no-destructure')),
|
|
98
|
+
disableAllowed: opt<boolean>(r('no-destructure'), 'disableAllowed'),
|
|
99
|
+
ignoreModifiedUntilEpoch: opt<number>(r('no-destructure'), 'ignoreModifiedUntilEpoch'),
|
|
100
|
+
},
|
|
101
|
+
catchErrorPattern: {
|
|
102
|
+
mode: modeOrOff(r('catch-error-pattern')),
|
|
103
|
+
disableAllowed: opt<boolean>(r('catch-error-pattern'), 'disableAllowed'),
|
|
104
|
+
ignoreModifiedUntilEpoch: opt<number>(r('catch-error-pattern'), 'ignoreModifiedUntilEpoch'),
|
|
105
|
+
},
|
|
106
|
+
noUnmanagedExceptions: {
|
|
107
|
+
mode: modeOrOff(r('no-unmanaged-exceptions')),
|
|
108
|
+
disableAllowed: opt<boolean>(r('no-unmanaged-exceptions'), 'disableAllowed'),
|
|
109
|
+
ignoreModifiedUntilEpoch: opt<number>(r('no-unmanaged-exceptions'), 'ignoreModifiedUntilEpoch'),
|
|
110
|
+
},
|
|
111
|
+
noDirectApiInResolver: {
|
|
112
|
+
mode: modeOrOff(r('no-direct-api-in-resolver')),
|
|
113
|
+
disableAllowed: opt<boolean>(r('no-direct-api-in-resolver'), 'disableAllowed'),
|
|
114
|
+
ignoreModifiedUntilEpoch: opt<number>(r('no-direct-api-in-resolver'), 'ignoreModifiedUntilEpoch'),
|
|
115
|
+
enforcePaths: opt<string[]>(r('no-direct-api-in-resolver'), 'enforcePaths'),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { default as validateNoAnyUnknown } from './validate-no-any-unknown';
|
|
2
|
+
export { default as validateNewMethods } from './validate-new-methods';
|
|
3
|
+
export { default as validateModifiedMethods } from './validate-modified-methods';
|
|
4
|
+
export { default as validateModifiedFiles } from './validate-modified-files';
|
|
5
|
+
export { default as validateReturnTypes } from './validate-return-types';
|
|
6
|
+
export { default as validateNoInlineTypes } from './validate-no-inline-types';
|
|
7
|
+
export { default as validateNoImplicitAny } from './validate-no-implicit-any';
|
|
8
|
+
export { default as validateCatchErrorPattern } from './validate-catch-error-pattern';
|
|
9
|
+
export { default as validateNoUnmanagedExceptions } from './validate-no-unmanaged-exceptions';
|
|
10
|
+
export { default as validateNoDestructure } from './validate-no-destructure';
|
|
11
|
+
export { default as validateNoDirectApiResolver } from './validate-no-direct-api-resolver';
|
|
12
|
+
export { default as validateDtos } from './validate-dtos';
|
|
13
|
+
export { default as validatePrismaConverters } from './validate-prisma-converters';
|
|
14
|
+
export { default as validateCode } from './validate-code';
|