@webpieces/code-rules 0.4.811 → 0.4.813
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/package.json +2 -2
- package/src/api-lib-enum-index.d.ts +46 -0
- package/src/api-lib-enum-index.js +158 -0
- package/src/api-lib-enum-index.js.map +1 -0
- package/src/api-lib-enum-text.d.ts +27 -0
- package/src/api-lib-enum-text.js +77 -0
- package/src/api-lib-enum-text.js.map +1 -0
- package/src/api-lib-source-rule.d.ts +70 -0
- package/src/api-lib-source-rule.js +156 -0
- package/src/api-lib-source-rule.js.map +1 -0
- package/src/code-rules-config-table.js +2 -0
- package/src/code-rules-config-table.js.map +1 -1
- package/src/code-rules-engine.d.ts +5 -1
- package/src/code-rules-engine.js +12 -2
- package/src/code-rules-engine.js.map +1 -1
- package/src/index.d.ts +5 -0
- package/src/index.js +14 -1
- package/src/index.js.map +1 -1
- package/src/validate-no-inline-import-in-api-lib.d.ts +38 -0
- package/src/validate-no-inline-import-in-api-lib.js +96 -0
- package/src/validate-no-inline-import-in-api-lib.js.map +1 -0
- package/src/validate-one-enum-spelling-in-api-lib.d.ts +61 -0
- package/src/validate-one-enum-spelling-in-api-lib.js +255 -0
- package/src/validate-one-enum-spelling-in-api-lib.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"code-rules-config-table.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-config-table.ts"],"names":[],"mappings":";;;AAAA,0DA2BiC;AAKjC;;;;;GAKG;AACU,QAAA,eAAe,GAAqE;IAC7F,CAAC,mCAAoB,EAAE,kBAAkB,CAAC;IAC1C,CAAC,iCAAkB,EAAE,gBAAgB,CAAC;IACtC,CAAC,sCAAuB,EAAE,qBAAqB,CAAC;IAChD,CAAC,yCAA0B,EAAE,yBAAyB,CAAC;IACvD,CAAC,iCAAkB,EAAE,gBAAgB,CAAC;IACtC,CAAC,kCAAmB,EAAE,iBAAiB,CAAC;IACxC,CAAC,uCAAwB,EAAE,sBAAsB,CAAC;IAClD,CAAC,oCAAqB,EAAE,kBAAkB,CAAC;IAC3C,CAAC,kCAAmB,EAAE,gBAAgB,CAAC;IACvC,CAAC,sCAAuB,EAAE,qBAAqB,CAAC;IAChD,CAAC,0CAA2B,EAAE,yBAAyB,CAAC;IACxD,CAAC,iDAAkC,EAAE,mCAAmC,CAAC;IACzE,CAAC,qCAAsB,EAAE,qBAAqB,CAAC;IAC/C,CAAC,0DAA2C,EAAE,6CAA6C,CAAC;IAC5F,CAAC,gCAAiB,EAAE,eAAe,CAAC;IACpC,CAAC,4CAA6B,EAAE,6BAA6B,CAAC;IAC9D,CAAC,6CAA8B,EAAE,8BAA8B,CAAC;IAChE,CAAC,2CAA4B,EAAE,2BAA2B,CAAC;IAC3D;QACI,8DAA+C;QAC/C,iDAAiD;KACpD;IACD,CAAC,iCAAkB,EAAE,eAAe,CAAC;IACrC,CAAC,4BAAa,EAAE,UAAU,CAAC;IAC3B,CAAC,sCAAuB,EAAE,sBAAsB,CAAC;IACjD,CAAC,2CAA4B,EAAE,6BAA6B,CAAC;IAC7D,CAAC,4CAA6B,EAAE,8BAA8B,CAAC;CAClE,CAAC","sourcesContent":["import {\n BaseRuleConfig,\n WebpiecesRulesConfig,\n MaxMethodLinesConfig,\n MaxFileLinesConfig,\n RequireReturnTypeConfig,\n NoInlineTypeLiteralsConfig,\n NoAnyUnknownConfig,\n NoImplicitAnyConfig,\n PrismaValidateDtosConfig,\n PrismaConverterConfig,\n NoDestructureConfig,\n CatchErrorPatternConfig,\n NoUnmanagedExceptionsConfig,\n AngularNoDirectApiInResolverConfig,\n NoSymbolDiTokensConfig,\n NoClientCreationOutsideServerOrClientConfig,\n NoCustomCssConfig,\n NoStatePathsInTemplatesConfig,\n NoProcessExitOutsideMainConfig,\n NoFunctionOutsideClassConfig,\n InjectAnnotationNotNeededForConcreteClassConfig,\n FrameworkTagConfig,\n RoleTagConfig,\n EnsureWeAreSecureConfig,\n NoInlineImportInApiLibConfig,\n OneEnumSpellingInApiLibConfig,\n} from '@webpieces/rules-config';\n\n/** A rule config class usable as an inversify inject-by-type token. */\nexport type ConfigCtor = new () => BaseRuleConfig;\n\n/**\n * The 1:1 table of `[config class, webpieces.config.json rule key]`. The composition root iterates it\n * to bind each rule's config into the container (`bind(ConfigClass).toConstantValue(config[key] ??\n * new ConfigClass())`), so every `@provideSingleton` validator injects its config by type. Data only\n * — the binding loop lives inline in the bin (an inline loop, exempt from no-function-outside-class).\n */\nexport const CONFIG_BINDINGS: ReadonlyArray<readonly [ConfigCtor, keyof WebpiecesRulesConfig]> = [\n [MaxMethodLinesConfig, 'max-method-lines'],\n [MaxFileLinesConfig, 'max-file-lines'],\n [RequireReturnTypeConfig, 'require-return-type'],\n [NoInlineTypeLiteralsConfig, 'no-inline-type-literals'],\n [NoAnyUnknownConfig, 'no-any-unknown'],\n [NoImplicitAnyConfig, 'no-implicit-any'],\n [PrismaValidateDtosConfig, 'prisma-validate-dtos'],\n [PrismaConverterConfig, 'prisma-converter'],\n [NoDestructureConfig, 'no-destructure'],\n [CatchErrorPatternConfig, 'catch-error-pattern'],\n [NoUnmanagedExceptionsConfig, 'no-unmanaged-exceptions'],\n [AngularNoDirectApiInResolverConfig, 'angular-no-direct-api-in-resolver'],\n [NoSymbolDiTokensConfig, 'no-symbol-di-tokens'],\n [NoClientCreationOutsideServerOrClientConfig, 'no-client-creation-outside-server-or-client'],\n [NoCustomCssConfig, 'no-custom-css'],\n [NoStatePathsInTemplatesConfig, 'no-state-paths-in-templates'],\n [NoProcessExitOutsideMainConfig, 'no-process-exit-outside-main'],\n [NoFunctionOutsideClassConfig, 'no-function-outside-class'],\n [\n InjectAnnotationNotNeededForConcreteClassConfig,\n 'inject-annotation-not-needed-for-concrete-class',\n ],\n [FrameworkTagConfig, 'framework-tag'],\n [RoleTagConfig, 'role-tag'],\n [EnsureWeAreSecureConfig, 'ensure-we-are-secure'],\n [NoInlineImportInApiLibConfig, 'no-inline-import-in-api-lib'],\n [OneEnumSpellingInApiLibConfig, 'one-enum-spelling-in-api-lib'],\n];\n"]}
|
|
@@ -24,6 +24,8 @@ import { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-i
|
|
|
24
24
|
import { FrameworkTagValidator } from './validate-framework-tag';
|
|
25
25
|
import { RoleTagValidator } from './validate-role-tag';
|
|
26
26
|
import { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';
|
|
27
|
+
import { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';
|
|
28
|
+
import { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';
|
|
27
29
|
/**
|
|
28
30
|
* Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config
|
|
29
31
|
* is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph
|
|
@@ -57,7 +59,9 @@ export declare class CodeRulesEngine {
|
|
|
57
59
|
private readonly frameworkTag;
|
|
58
60
|
private readonly roleTag;
|
|
59
61
|
private readonly ensureWeAreSecure;
|
|
60
|
-
|
|
62
|
+
private readonly noInlineImportInApiLib;
|
|
63
|
+
private readonly oneEnumSpellingInApiLib;
|
|
64
|
+
constructor(workspace: WorkspaceRoot, reporter: RuleReporter, matchRules: MatchRulesHolder, matchChecker: MatchRulesChecker, maxMethodLines: MaxMethodLinesValidator, maxFileLines: MaxFileLinesValidator, requireReturnType: RequireReturnTypeValidator, noInlineTypeLiterals: NoInlineTypeLiteralsValidator, noAnyUnknown: NoAnyUnknownValidator, noImplicitAny: NoImplicitAnyValidator, prismaValidateDtos: PrismaValidateDtosValidator, prismaConverter: PrismaConverterValidator, noDestructure: NoDestructureValidator, catchErrorPattern: CatchErrorPatternValidator, noUnmanagedExceptions: NoUnmanagedExceptionsValidator, noDirectApiResolver: NoDirectApiResolverValidator, noSymbolDiTokens: NoSymbolDiTokensValidator, noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator, noCustomCss: NoCustomCssValidator, noStatePathsInTemplates: NoStatePathsInTemplatesValidator, noProcessExitOutsideMain: NoProcessExitOutsideMainValidator, noFunctionOutsideClass: NoFunctionOutsideClassValidator, injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator, frameworkTag: FrameworkTagValidator, roleTag: RoleTagValidator, ensureWeAreSecure: EnsureWeAreSecureValidator, noInlineImportInApiLib: NoInlineImportInApiLibValidator, oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator);
|
|
61
65
|
/** The injected built-in validators, in run order. */
|
|
62
66
|
private builtIns;
|
|
63
67
|
/**
|
package/src/code-rules-engine.js
CHANGED
|
@@ -29,6 +29,8 @@ const validate_inject_annotation_not_needed_for_concrete_class_1 = require("./va
|
|
|
29
29
|
const validate_framework_tag_1 = require("./validate-framework-tag");
|
|
30
30
|
const validate_role_tag_1 = require("./validate-role-tag");
|
|
31
31
|
const validate_ensure_we_are_secure_1 = require("./validate-ensure-we-are-secure");
|
|
32
|
+
const validate_no_inline_import_in_api_lib_1 = require("./validate-no-inline-import-in-api-lib");
|
|
33
|
+
const validate_one_enum_spelling_in_api_lib_1 = require("./validate-one-enum-spelling-in-api-lib");
|
|
32
34
|
/**
|
|
33
35
|
* Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config
|
|
34
36
|
* is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph
|
|
@@ -62,8 +64,10 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
62
64
|
frameworkTag;
|
|
63
65
|
roleTag;
|
|
64
66
|
ensureWeAreSecure;
|
|
67
|
+
noInlineImportInApiLib;
|
|
68
|
+
oneEnumSpellingInApiLib;
|
|
65
69
|
// webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field
|
|
66
|
-
constructor(workspace, reporter, matchRules, matchChecker, maxMethodLines, maxFileLines, requireReturnType, noInlineTypeLiterals, noAnyUnknown, noImplicitAny, prismaValidateDtos, prismaConverter, noDestructure, catchErrorPattern, noUnmanagedExceptions, noDirectApiResolver, noSymbolDiTokens, noClientCreationOutsideServerOrClient, noCustomCss, noStatePathsInTemplates, noProcessExitOutsideMain, noFunctionOutsideClass, injectAnnotationNotNeeded, frameworkTag, roleTag, ensureWeAreSecure) {
|
|
70
|
+
constructor(workspace, reporter, matchRules, matchChecker, maxMethodLines, maxFileLines, requireReturnType, noInlineTypeLiterals, noAnyUnknown, noImplicitAny, prismaValidateDtos, prismaConverter, noDestructure, catchErrorPattern, noUnmanagedExceptions, noDirectApiResolver, noSymbolDiTokens, noClientCreationOutsideServerOrClient, noCustomCss, noStatePathsInTemplates, noProcessExitOutsideMain, noFunctionOutsideClass, injectAnnotationNotNeeded, frameworkTag, roleTag, ensureWeAreSecure, noInlineImportInApiLib, oneEnumSpellingInApiLib) {
|
|
67
71
|
this.workspace = workspace;
|
|
68
72
|
this.reporter = reporter;
|
|
69
73
|
this.matchRules = matchRules;
|
|
@@ -90,6 +94,8 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
90
94
|
this.frameworkTag = frameworkTag;
|
|
91
95
|
this.roleTag = roleTag;
|
|
92
96
|
this.ensureWeAreSecure = ensureWeAreSecure;
|
|
97
|
+
this.noInlineImportInApiLib = noInlineImportInApiLib;
|
|
98
|
+
this.oneEnumSpellingInApiLib = oneEnumSpellingInApiLib;
|
|
93
99
|
}
|
|
94
100
|
/** The injected built-in validators, in run order. */
|
|
95
101
|
builtIns() {
|
|
@@ -116,6 +122,8 @@ let CodeRulesEngine = class CodeRulesEngine {
|
|
|
116
122
|
this.frameworkTag,
|
|
117
123
|
this.roleTag,
|
|
118
124
|
this.ensureWeAreSecure,
|
|
125
|
+
this.noInlineImportInApiLib,
|
|
126
|
+
this.oneEnumSpellingInApiLib,
|
|
119
127
|
];
|
|
120
128
|
}
|
|
121
129
|
/**
|
|
@@ -184,6 +192,8 @@ exports.CodeRulesEngine = CodeRulesEngine = tslib_1.__decorate([
|
|
|
184
192
|
validate_inject_annotation_not_needed_for_concrete_class_1.InjectAnnotationNotNeededForConcreteClassValidator,
|
|
185
193
|
validate_framework_tag_1.FrameworkTagValidator,
|
|
186
194
|
validate_role_tag_1.RoleTagValidator,
|
|
187
|
-
validate_ensure_we_are_secure_1.EnsureWeAreSecureValidator
|
|
195
|
+
validate_ensure_we_are_secure_1.EnsureWeAreSecureValidator,
|
|
196
|
+
validate_no_inline_import_in_api_lib_1.NoInlineImportInApiLibValidator,
|
|
197
|
+
validate_one_enum_spelling_in_api_lib_1.OneEnumSpellingInApiLibValidator])
|
|
188
198
|
], CodeRulesEngine);
|
|
189
199
|
//# sourceMappingURL=code-rules-engine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-rules-engine.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-engine.ts"],"names":[],"mappings":";;;;AACA,yCAA2D;AAE3D,qDAA0E;AAC1E,mDAA+C;AAC/C,6DAAuE;AACvE,iEAA2D;AAC3D,2EAAsE;AACtE,uEAAkE;AAClE,mEAAqE;AACrE,yEAA2E;AAC3E,uEAAkE;AAClE,yEAAoE;AACpE,mDAA8D;AAC9D,6EAAwE;AACxE,uEAAmE;AACnE,iFAA4E;AAC5E,yFAAoF;AACpF,uFAAiF;AACjF,iFAA2E;AAC3E,iIAAwH;AACxH,qEAAgE;AAChE,iGAA0F;AAC1F,mGAA4F;AAC5F,6FAAuF;AACvF,yIAAgI;AAChI,qEAAiE;AACjE,2DAAuD;AACvD,mFAA6E;AAE7E;;;;;GAKG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAGH;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IA3BrB,4GAA4G;IAC5G,YACqB,SAAwB,EACxB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QAChC,8DAA4B;QAC/B,wDAAyB;QACJ,qGAA8C;QACxE,6CAAoB;QACR,uEAAgC;QAC/B,yEAAiC;QACnC,oEAA+B;QAC5B,6GAAkD;QAC/D,8CAAqB;QAC1B,oCAAgB;QACN,0DAA0B;GA5BzD,eAAe,CAoG3B","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { CodeValidator, ExecutorResult, RuleRun } from './code-validator';\nimport { RuleReporter } from './rule-reporter';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { MatchRulesChecker } from './validate-match-rules';\nimport { MaxMethodLinesValidator } from './validate-modified-methods';\nimport { MaxFileLinesValidator } from './validate-modified-files';\nimport { RequireReturnTypeValidator } from './validate-return-types';\nimport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nimport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nimport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nimport { PrismaValidateDtosValidator } from './validate-dtos';\nimport { PrismaConverterValidator } from './validate-prisma-converters';\nimport { NoDestructureValidator } from './validate-no-destructure';\nimport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nimport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nimport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nimport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nimport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nimport { NoCustomCssValidator } from './validate-no-custom-css';\nimport { NoStatePathsInTemplatesValidator } from './validate-no-state-paths-in-templates';\nimport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nimport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nimport { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-inject-annotation-not-needed-for-concrete-class';\nimport { FrameworkTagValidator } from './validate-framework-tag';\nimport { RoleTagValidator } from './validate-role-tag';\nimport { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';\n\n/**\n * Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config\n * is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph\n * draws. The per-entry match-rules validators are the one exception — they are config-per-instance,\n * so they are built from the injected {@link MatchRulesHolder}.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesEngine {\n // webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field\n constructor(\n private readonly workspace: WorkspaceRoot,\n private readonly reporter: RuleReporter,\n private readonly matchRules: MatchRulesHolder,\n private readonly matchChecker: MatchRulesChecker,\n private readonly maxMethodLines: MaxMethodLinesValidator,\n private readonly maxFileLines: MaxFileLinesValidator,\n private readonly requireReturnType: RequireReturnTypeValidator,\n private readonly noInlineTypeLiterals: NoInlineTypeLiteralsValidator,\n private readonly noAnyUnknown: NoAnyUnknownValidator,\n private readonly noImplicitAny: NoImplicitAnyValidator,\n private readonly prismaValidateDtos: PrismaValidateDtosValidator,\n private readonly prismaConverter: PrismaConverterValidator,\n private readonly noDestructure: NoDestructureValidator,\n private readonly catchErrorPattern: CatchErrorPatternValidator,\n private readonly noUnmanagedExceptions: NoUnmanagedExceptionsValidator,\n private readonly noDirectApiResolver: NoDirectApiResolverValidator,\n private readonly noSymbolDiTokens: NoSymbolDiTokensValidator,\n private readonly noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator,\n private readonly noCustomCss: NoCustomCssValidator,\n private readonly noStatePathsInTemplates: NoStatePathsInTemplatesValidator,\n private readonly noProcessExitOutsideMain: NoProcessExitOutsideMainValidator,\n private readonly noFunctionOutsideClass: NoFunctionOutsideClassValidator,\n private readonly injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator,\n private readonly frameworkTag: FrameworkTagValidator,\n private readonly roleTag: RoleTagValidator,\n private readonly ensureWeAreSecure: EnsureWeAreSecureValidator,\n ) {}\n\n /** The injected built-in validators, in run order. */\n private builtIns(): CodeValidator<BaseRuleConfig>[] {\n return [\n this.maxMethodLines,\n this.maxFileLines,\n this.requireReturnType,\n this.noInlineTypeLiterals,\n this.noAnyUnknown,\n this.noImplicitAny,\n this.prismaValidateDtos,\n this.prismaConverter,\n this.noDestructure,\n this.catchErrorPattern,\n this.noUnmanagedExceptions,\n this.noDirectApiResolver,\n this.noSymbolDiTokens,\n this.noClientCreationOutsideServerOrClient,\n this.noCustomCss,\n this.noStatePathsInTemplates,\n this.noProcessExitOutsideMain,\n this.noFunctionOutsideClass,\n this.injectAnnotationNotNeeded,\n this.frameworkTag,\n this.roleTag,\n this.ensureWeAreSecure,\n ];\n }\n\n /**\n * Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected\n * match-rule check per configured entry that is active. Built as {@link RuleRun} value objects\n * (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.\n */\n private activeRuns(root: string): RuleRun[] {\n const runs: RuleRun[] = [];\n for (const v of this.builtIns()) {\n if (v.shouldRun()) runs.push(new RuleRun(v.name, () => v.run(root)));\n }\n for (const mr of this.matchRules.rules) {\n if (this.matchChecker.shouldRun(mr))\n runs.push(new RuleRun(mr.name, () => this.matchChecker.runForConfig(mr, root)));\n }\n return runs;\n }\n\n /**\n * Run all configured code validators against the workspace. A validator runs only when\n * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives\n * in {@link RuleReporter} so one validator can never abort the rest.\n */\n async run(): Promise<ExecutorResult> {\n const runs = this.activeRuns(this.workspace.path);\n if (runs.length === 0) {\n console.log('\\n⏭️ Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\n📏 Running Code Validations\\n');\n console.log(` Active rules: ${runs.map((r: RuleRun) => r.name).join(', ')}`);\n console.log('');\n\n const result = await this.reporter.runValidators(runs);\n console.log(\n result.success\n ? '\\n✅ All code validations passed\\n'\n : '\\n❌ Some code validations failed\\n',\n );\n return result;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"code-rules-engine.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-engine.ts"],"names":[],"mappings":";;;;AACA,yCAA2D;AAE3D,qDAA0E;AAC1E,mDAA+C;AAC/C,6DAAuE;AACvE,iEAA2D;AAC3D,2EAAsE;AACtE,uEAAkE;AAClE,mEAAqE;AACrE,yEAA2E;AAC3E,uEAAkE;AAClE,yEAAoE;AACpE,mDAA8D;AAC9D,6EAAwE;AACxE,uEAAmE;AACnE,iFAA4E;AAC5E,yFAAoF;AACpF,uFAAiF;AACjF,iFAA2E;AAC3E,iIAAwH;AACxH,qEAAgE;AAChE,iGAA0F;AAC1F,mGAA4F;AAC5F,6FAAuF;AACvF,yIAAgI;AAChI,qEAAiE;AACjE,2DAAuD;AACvD,mFAA6E;AAC7E,iGAAyF;AACzF,mGAA2F;AAE3F;;;;;GAKG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAGH;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IA7BrB,4GAA4G;IAC5G,YACqB,SAAwB,EACxB,QAAsB,EACtB,UAA4B,EAC5B,YAA+B,EAC/B,cAAuC,EACvC,YAAmC,EACnC,iBAA6C,EAC7C,oBAAmD,EACnD,YAAmC,EACnC,aAAqC,EACrC,kBAA+C,EAC/C,eAAyC,EACzC,aAAqC,EACrC,iBAA6C,EAC7C,qBAAqD,EACrD,mBAAiD,EACjD,gBAA2C,EAC3C,qCAAqF,EACrF,WAAiC,EACjC,uBAAyD,EACzD,wBAA2D,EAC3D,sBAAuD,EACvD,yBAA6E,EAC7E,YAAmC,EACnC,OAAyB,EACzB,iBAA6C,EAC7C,sBAAuD,EACvD,uBAAyD;QA3BzD,cAAS,GAAT,SAAS,CAAe;QACxB,aAAQ,GAAR,QAAQ,CAAc;QACtB,eAAU,GAAV,UAAU,CAAkB;QAC5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B,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;YACtE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEhB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CACP,MAAM,CAAC,OAAO;YACV,CAAC,CAAC,mCAAmC;YACrC,CAAC,CAAC,oCAAoC,CAC7C,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ,CAAA;AAxGY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIL,kCAAa;QACd,4BAAY;QACV,qCAAgB;QACd,wCAAiB;QACf,mDAAuB;QACzB,+CAAqB;QAChB,kDAA0B;QACvB,wDAA6B;QACrC,+CAAqB;QACpB,iDAAsB;QACjB,2CAA2B;QAC9B,qDAAwB;QAC1B,gDAAsB;QAClB,yDAA0B;QACtB,iEAA8B;QAChC,8DAA4B;QAC/B,wDAAyB;QACJ,qGAA8C;QACxE,6CAAoB;QACR,uEAAgC;QAC/B,yEAAiC;QACnC,oEAA+B;QAC5B,6GAAkD;QAC/D,8CAAqB;QAC1B,oCAAgB;QACN,0DAA0B;QACrB,sEAA+B;QAC9B,wEAAgC;GA9BrE,eAAe,CAwG3B","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { CodeValidator, ExecutorResult, RuleRun } from './code-validator';\nimport { RuleReporter } from './rule-reporter';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { MatchRulesChecker } from './validate-match-rules';\nimport { MaxMethodLinesValidator } from './validate-modified-methods';\nimport { MaxFileLinesValidator } from './validate-modified-files';\nimport { RequireReturnTypeValidator } from './validate-return-types';\nimport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nimport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nimport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nimport { PrismaValidateDtosValidator } from './validate-dtos';\nimport { PrismaConverterValidator } from './validate-prisma-converters';\nimport { NoDestructureValidator } from './validate-no-destructure';\nimport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nimport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nimport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nimport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nimport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nimport { NoCustomCssValidator } from './validate-no-custom-css';\nimport { NoStatePathsInTemplatesValidator } from './validate-no-state-paths-in-templates';\nimport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nimport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nimport { InjectAnnotationNotNeededForConcreteClassValidator } from './validate-inject-annotation-not-needed-for-concrete-class';\nimport { FrameworkTagValidator } from './validate-framework-tag';\nimport { RoleTagValidator } from './validate-role-tag';\nimport { EnsureWeAreSecureValidator } from './validate-ensure-we-are-secure';\nimport { NoInlineImportInApiLibValidator } from './validate-no-inline-import-in-api-lib';\nimport { OneEnumSpellingInApiLibValidator } from './validate-one-enum-spelling-in-api-lib';\n\n/**\n * Owns running the code-rules suite. Every built-in validator is injected as a singleton (its config\n * is bound in the container at bootstrap), so this class IS the code-rules DI DAG the design graph\n * draws. The per-entry match-rules validators are the one exception — they are config-per-instance,\n * so they are built from the injected {@link MatchRulesHolder}.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CodeRulesEngine {\n // webpieces-disable max-lines-new-methods -- the built-in validator set is flat; each is one injected field\n constructor(\n private readonly workspace: WorkspaceRoot,\n private readonly reporter: RuleReporter,\n private readonly matchRules: MatchRulesHolder,\n private readonly matchChecker: MatchRulesChecker,\n private readonly maxMethodLines: MaxMethodLinesValidator,\n private readonly maxFileLines: MaxFileLinesValidator,\n private readonly requireReturnType: RequireReturnTypeValidator,\n private readonly noInlineTypeLiterals: NoInlineTypeLiteralsValidator,\n private readonly noAnyUnknown: NoAnyUnknownValidator,\n private readonly noImplicitAny: NoImplicitAnyValidator,\n private readonly prismaValidateDtos: PrismaValidateDtosValidator,\n private readonly prismaConverter: PrismaConverterValidator,\n private readonly noDestructure: NoDestructureValidator,\n private readonly catchErrorPattern: CatchErrorPatternValidator,\n private readonly noUnmanagedExceptions: NoUnmanagedExceptionsValidator,\n private readonly noDirectApiResolver: NoDirectApiResolverValidator,\n private readonly noSymbolDiTokens: NoSymbolDiTokensValidator,\n private readonly noClientCreationOutsideServerOrClient: NoClientCreationOutsideServerOrClientValidator,\n private readonly noCustomCss: NoCustomCssValidator,\n private readonly noStatePathsInTemplates: NoStatePathsInTemplatesValidator,\n private readonly noProcessExitOutsideMain: NoProcessExitOutsideMainValidator,\n private readonly noFunctionOutsideClass: NoFunctionOutsideClassValidator,\n private readonly injectAnnotationNotNeeded: InjectAnnotationNotNeededForConcreteClassValidator,\n private readonly frameworkTag: FrameworkTagValidator,\n private readonly roleTag: RoleTagValidator,\n private readonly ensureWeAreSecure: EnsureWeAreSecureValidator,\n private readonly noInlineImportInApiLib: NoInlineImportInApiLibValidator,\n private readonly oneEnumSpellingInApiLib: OneEnumSpellingInApiLibValidator,\n ) {}\n\n /** The injected built-in validators, in run order. */\n private builtIns(): CodeValidator<BaseRuleConfig>[] {\n return [\n this.maxMethodLines,\n this.maxFileLines,\n this.requireReturnType,\n this.noInlineTypeLiterals,\n this.noAnyUnknown,\n this.noImplicitAny,\n this.prismaValidateDtos,\n this.prismaConverter,\n this.noDestructure,\n this.catchErrorPattern,\n this.noUnmanagedExceptions,\n this.noDirectApiResolver,\n this.noSymbolDiTokens,\n this.noClientCreationOutsideServerOrClient,\n this.noCustomCss,\n this.noStatePathsInTemplates,\n this.noProcessExitOutsideMain,\n this.noFunctionOutsideClass,\n this.injectAnnotationNotNeeded,\n this.frameworkTag,\n this.roleTag,\n this.ensureWeAreSecure,\n this.noInlineImportInApiLib,\n this.oneEnumSpellingInApiLib,\n ];\n }\n\n /**\n * Every ACTIVE run: an injected built-in validator whose `shouldRun()` is true, or an injected\n * match-rule check per configured entry that is active. Built as {@link RuleRun} value objects\n * (name + thunk) so NO DAG member is `new`-ed — the validators and the checker are injected.\n */\n private activeRuns(root: string): RuleRun[] {\n const runs: RuleRun[] = [];\n for (const v of this.builtIns()) {\n if (v.shouldRun()) runs.push(new RuleRun(v.name, () => v.run(root)));\n }\n for (const mr of this.matchRules.rules) {\n if (this.matchChecker.shouldRun(mr))\n runs.push(new RuleRun(mr.name, () => this.matchChecker.runForConfig(mr, root)));\n }\n return runs;\n }\n\n /**\n * Run all configured code validators against the workspace. A validator runs only when\n * `shouldRun()` is true (mode not OFF and no branch/epoch escape hatch). Per-run isolation lives\n * in {@link RuleReporter} so one validator can never abort the rest.\n */\n async run(): Promise<ExecutorResult> {\n const runs = this.activeRuns(this.workspace.path);\n if (runs.length === 0) {\n console.log('\\n⏭️ Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n console.log('\\n📏 Running Code Validations\\n');\n console.log(` Active rules: ${runs.map((r: RuleRun) => r.name).join(', ')}`);\n console.log('');\n\n const result = await this.reporter.runValidators(runs);\n console.log(\n result.success\n ? '\\n✅ All code validations passed\\n'\n : '\\n❌ Some code validations failed\\n',\n );\n return result;\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export { InjectAnnotationNotNeededForConcreteClassValidator, findRedundantInject
|
|
|
20
20
|
export { FrameworkTagValidator } from './validate-framework-tag';
|
|
21
21
|
export { RoleTagValidator } from './validate-role-tag';
|
|
22
22
|
export { EnsureWeAreSecureValidator, SecurityContractViolation, auditSecurityContracts, findDirectlyChangedProjectRoots, } from './validate-ensure-we-are-secure';
|
|
23
|
+
export { ApiLibFile, ApiLibSite } from './api-lib-source-rule';
|
|
24
|
+
export { NoInlineImportInApiLibValidator, InlineImportScanner } from './validate-no-inline-import-in-api-lib';
|
|
25
|
+
export { OneEnumSpellingInApiLibValidator, EnumSpellingScanner } from './validate-one-enum-spelling-in-api-lib';
|
|
26
|
+
export { ApiLibEnumIndex } from './api-lib-enum-index';
|
|
27
|
+
export { EnumText } from './api-lib-enum-text';
|
|
23
28
|
export { PrismaValidateDtosValidator } from './validate-dtos';
|
|
24
29
|
export { PrismaConverterValidator } from './validate-prisma-converters';
|
|
25
30
|
export { default as validateCode } from './validate-code';
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReactNativeCompatibility = exports.validateCode = exports.PrismaConverterValidator = exports.PrismaValidateDtosValidator = exports.findDirectlyChangedProjectRoots = exports.auditSecurityContracts = exports.SecurityContractViolation = exports.EnsureWeAreSecureValidator = exports.RoleTagValidator = exports.FrameworkTagValidator = exports.findRedundantInjectInSource = exports.InjectAnnotationNotNeededForConcreteClassValidator = exports.NoFunctionOutsideClassValidator = exports.NoProcessExitOutsideMainValidator = exports.ProjectRoleResolver = exports.StatePathViolation = exports.StatePathHit = exports.NoStatePathsInTemplatesValidator = exports.NoClientCreationOutsideServerOrClientValidator = exports.NoSymbolDiTokensValidator = exports.NoDirectApiResolverValidator = exports.NoDestructureValidator = exports.NoUnmanagedExceptionsValidator = exports.CatchErrorPatternValidator = exports.NoInlineTypeLiteralsValidator = exports.RequireReturnTypeValidator = exports.MaxFileLinesValidator = exports.runNewMethods = exports.runModifiedMethods = exports.MaxMethodLinesValidator = exports.NoImplicitAnyValidator = exports.NoAnyUnknownValidator = exports.CodeValidator = void 0;
|
|
3
|
+
exports.ReactNativeCompatibility = exports.validateCode = exports.PrismaConverterValidator = exports.PrismaValidateDtosValidator = exports.EnumText = exports.ApiLibEnumIndex = exports.EnumSpellingScanner = exports.OneEnumSpellingInApiLibValidator = exports.InlineImportScanner = exports.NoInlineImportInApiLibValidator = exports.ApiLibSite = exports.ApiLibFile = exports.findDirectlyChangedProjectRoots = exports.auditSecurityContracts = exports.SecurityContractViolation = exports.EnsureWeAreSecureValidator = exports.RoleTagValidator = exports.FrameworkTagValidator = exports.findRedundantInjectInSource = exports.InjectAnnotationNotNeededForConcreteClassValidator = exports.NoFunctionOutsideClassValidator = exports.NoProcessExitOutsideMainValidator = exports.ProjectRoleResolver = exports.StatePathViolation = exports.StatePathHit = exports.NoStatePathsInTemplatesValidator = exports.NoClientCreationOutsideServerOrClientValidator = exports.NoSymbolDiTokensValidator = exports.NoDirectApiResolverValidator = exports.NoDestructureValidator = exports.NoUnmanagedExceptionsValidator = exports.CatchErrorPatternValidator = exports.NoInlineTypeLiteralsValidator = exports.RequireReturnTypeValidator = exports.MaxFileLinesValidator = exports.runNewMethods = exports.runModifiedMethods = exports.MaxMethodLinesValidator = exports.NoImplicitAnyValidator = exports.NoAnyUnknownValidator = exports.CodeValidator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var code_validator_1 = require("./code-validator");
|
|
6
6
|
Object.defineProperty(exports, "CodeValidator", { enumerable: true, get: function () { return code_validator_1.CodeValidator; } });
|
|
@@ -53,6 +53,19 @@ Object.defineProperty(exports, "EnsureWeAreSecureValidator", { enumerable: true,
|
|
|
53
53
|
Object.defineProperty(exports, "SecurityContractViolation", { enumerable: true, get: function () { return validate_ensure_we_are_secure_1.SecurityContractViolation; } });
|
|
54
54
|
Object.defineProperty(exports, "auditSecurityContracts", { enumerable: true, get: function () { return validate_ensure_we_are_secure_1.auditSecurityContracts; } });
|
|
55
55
|
Object.defineProperty(exports, "findDirectlyChangedProjectRoots", { enumerable: true, get: function () { return validate_ensure_we_are_secure_1.findDirectlyChangedProjectRoots; } });
|
|
56
|
+
var api_lib_source_rule_1 = require("./api-lib-source-rule");
|
|
57
|
+
Object.defineProperty(exports, "ApiLibFile", { enumerable: true, get: function () { return api_lib_source_rule_1.ApiLibFile; } });
|
|
58
|
+
Object.defineProperty(exports, "ApiLibSite", { enumerable: true, get: function () { return api_lib_source_rule_1.ApiLibSite; } });
|
|
59
|
+
var validate_no_inline_import_in_api_lib_1 = require("./validate-no-inline-import-in-api-lib");
|
|
60
|
+
Object.defineProperty(exports, "NoInlineImportInApiLibValidator", { enumerable: true, get: function () { return validate_no_inline_import_in_api_lib_1.NoInlineImportInApiLibValidator; } });
|
|
61
|
+
Object.defineProperty(exports, "InlineImportScanner", { enumerable: true, get: function () { return validate_no_inline_import_in_api_lib_1.InlineImportScanner; } });
|
|
62
|
+
var validate_one_enum_spelling_in_api_lib_1 = require("./validate-one-enum-spelling-in-api-lib");
|
|
63
|
+
Object.defineProperty(exports, "OneEnumSpellingInApiLibValidator", { enumerable: true, get: function () { return validate_one_enum_spelling_in_api_lib_1.OneEnumSpellingInApiLibValidator; } });
|
|
64
|
+
Object.defineProperty(exports, "EnumSpellingScanner", { enumerable: true, get: function () { return validate_one_enum_spelling_in_api_lib_1.EnumSpellingScanner; } });
|
|
65
|
+
var api_lib_enum_index_1 = require("./api-lib-enum-index");
|
|
66
|
+
Object.defineProperty(exports, "ApiLibEnumIndex", { enumerable: true, get: function () { return api_lib_enum_index_1.ApiLibEnumIndex; } });
|
|
67
|
+
var api_lib_enum_text_1 = require("./api-lib-enum-text");
|
|
68
|
+
Object.defineProperty(exports, "EnumText", { enumerable: true, get: function () { return api_lib_enum_text_1.EnumText; } });
|
|
56
69
|
var validate_dtos_1 = require("./validate-dtos");
|
|
57
70
|
Object.defineProperty(exports, "PrismaValidateDtosValidator", { enumerable: true, get: function () { return validate_dtos_1.PrismaValidateDtosValidator; } });
|
|
58
71
|
var validate_prisma_converters_1 = require("./validate-prisma-converters");
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/index.ts"],"names":[],"mappings":";;;;AAAA,mDAAiE;AAAxD,+GAAA,aAAa,OAAA;AAEtB,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,yEAA0F;AAAjF,oIAAA,uBAAuB,OAAA;AAAE,+HAAA,kBAAkB,OAAA;AACpD,+DAAuD;AAA9C,qHAAA,aAAa,OAAA;AACtB,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,iEAAqE;AAA5D,mIAAA,0BAA0B,OAAA;AACnC,uEAA2E;AAAlE,yIAAA,6BAA6B,OAAA;AACtC,+EAA4E;AAAnE,0IAAA,0BAA0B,OAAA;AACnC,uFAAoF;AAA3E,kJAAA,8BAA8B,OAAA;AACvC,qEAAmE;AAA1D,iIAAA,sBAAsB,OAAA;AAC/B,qFAAiF;AAAxE,+IAAA,4BAA4B,OAAA;AACrC,+EAA2E;AAAlE,yIAAA,yBAAyB,OAAA;AAClC,+HAAwH;AAA/G,sLAAA,8CAA8C,OAAA;AACvD,+FAIgD;AAH5C,wJAAA,gCAAgC,OAAA;AAChC,oIAAA,YAAY,OAAA;AACZ,0IAAA,kBAAkB,OAAA;AAEtB,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,iGAA4F;AAAnF,0JAAA,iCAAiC,OAAA;AAC1C,2FAAuF;AAA9E,qJAAA,+BAA+B,OAAA;AACxC,uIAGoE;AAFhE,8LAAA,kDAAkD,OAAA;AAClD,uKAAA,2BAA2B,OAAA;AAE/B,mEAAiE;AAAxD,+HAAA,qBAAqB,OAAA;AAC9B,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,iFAKyC;AAJrC,2IAAA,0BAA0B,OAAA;AAC1B,0IAAA,yBAAyB,OAAA;AACzB,uIAAA,sBAAsB,OAAA;AACtB,gJAAA,+BAA+B,OAAA;AAEnC,iDAA8D;AAArD,4HAAA,2BAA2B,OAAA;AACpC,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,iDAA0D;AAAjD,sIAAA,OAAO,OAAgB;AAEhC,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA","sourcesContent":["export { CodeValidator, ExecutorResult } from './code-validator';\n\nexport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nexport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nexport { MaxMethodLinesValidator, runModifiedMethods } from './validate-modified-methods';\nexport { runNewMethods } from './validate-new-methods';\nexport { MaxFileLinesValidator } from './validate-modified-files';\nexport { RequireReturnTypeValidator } from './validate-return-types';\nexport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nexport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nexport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nexport { NoDestructureValidator } from './validate-no-destructure';\nexport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nexport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nexport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nexport {\n NoStatePathsInTemplatesValidator,\n StatePathHit,\n StatePathViolation,\n} from './validate-no-state-paths-in-templates';\nexport { ProjectRoleResolver } from './project-role-resolver';\nexport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nexport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nexport {\n InjectAnnotationNotNeededForConcreteClassValidator,\n findRedundantInjectInSource,\n} from './validate-inject-annotation-not-needed-for-concrete-class';\nexport { FrameworkTagValidator } from './validate-framework-tag';\nexport { RoleTagValidator } from './validate-role-tag';\nexport {\n EnsureWeAreSecureValidator,\n SecurityContractViolation,\n auditSecurityContracts,\n findDirectlyChangedProjectRoots,\n} from './validate-ensure-we-are-secure';\nexport { PrismaValidateDtosValidator } from './validate-dtos';\nexport { PrismaConverterValidator } from './validate-prisma-converters';\nexport { default as validateCode } from './validate-code';\n\nexport { ReactNativeCompatibility } from './react-native-compatibility';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/index.ts"],"names":[],"mappings":";;;;AAAA,mDAAiE;AAAxD,+GAAA,aAAa,OAAA;AAEtB,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,yEAA0F;AAAjF,oIAAA,uBAAuB,OAAA;AAAE,+HAAA,kBAAkB,OAAA;AACpD,+DAAuD;AAA9C,qHAAA,aAAa,OAAA;AACtB,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAC9B,iEAAqE;AAA5D,mIAAA,0BAA0B,OAAA;AACnC,uEAA2E;AAAlE,yIAAA,6BAA6B,OAAA;AACtC,+EAA4E;AAAnE,0IAAA,0BAA0B,OAAA;AACnC,uFAAoF;AAA3E,kJAAA,8BAA8B,OAAA;AACvC,qEAAmE;AAA1D,iIAAA,sBAAsB,OAAA;AAC/B,qFAAiF;AAAxE,+IAAA,4BAA4B,OAAA;AACrC,+EAA2E;AAAlE,yIAAA,yBAAyB,OAAA;AAClC,+HAAwH;AAA/G,sLAAA,8CAA8C,OAAA;AACvD,+FAIgD;AAH5C,wJAAA,gCAAgC,OAAA;AAChC,oIAAA,YAAY,OAAA;AACZ,0IAAA,kBAAkB,OAAA;AAEtB,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,iGAA4F;AAAnF,0JAAA,iCAAiC,OAAA;AAC1C,2FAAuF;AAA9E,qJAAA,+BAA+B,OAAA;AACxC,uIAGoE;AAFhE,8LAAA,kDAAkD,OAAA;AAClD,uKAAA,2BAA2B,OAAA;AAE/B,mEAAiE;AAAxD,+HAAA,qBAAqB,OAAA;AAC9B,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AACzB,iFAKyC;AAJrC,2IAAA,0BAA0B,OAAA;AAC1B,0IAAA,yBAAyB,OAAA;AACzB,uIAAA,sBAAsB,OAAA;AACtB,gJAAA,+BAA+B,OAAA;AAEnC,6DAA+D;AAAtD,iHAAA,UAAU,OAAA;AAAE,iHAAA,UAAU,OAAA;AAC/B,+FAA8G;AAArG,uJAAA,+BAA+B,OAAA;AAAE,2IAAA,mBAAmB,OAAA;AAC7D,iGAAgH;AAAvG,yJAAA,gCAAgC,OAAA;AAAE,4IAAA,mBAAmB,OAAA;AAC9D,2DAAuD;AAA9C,qHAAA,eAAe,OAAA;AACxB,yDAA+C;AAAtC,6GAAA,QAAQ,OAAA;AACjB,iDAA8D;AAArD,4HAAA,2BAA2B,OAAA;AACpC,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,iDAA0D;AAAjD,sIAAA,OAAO,OAAgB;AAEhC,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA","sourcesContent":["export { CodeValidator, ExecutorResult } from './code-validator';\n\nexport { NoAnyUnknownValidator } from './validate-no-any-unknown';\nexport { NoImplicitAnyValidator } from './validate-no-implicit-any';\nexport { MaxMethodLinesValidator, runModifiedMethods } from './validate-modified-methods';\nexport { runNewMethods } from './validate-new-methods';\nexport { MaxFileLinesValidator } from './validate-modified-files';\nexport { RequireReturnTypeValidator } from './validate-return-types';\nexport { NoInlineTypeLiteralsValidator } from './validate-no-inline-types';\nexport { CatchErrorPatternValidator } from './validate-catch-error-pattern';\nexport { NoUnmanagedExceptionsValidator } from './validate-no-unmanaged-exceptions';\nexport { NoDestructureValidator } from './validate-no-destructure';\nexport { NoDirectApiResolverValidator } from './validate-no-direct-api-resolver';\nexport { NoSymbolDiTokensValidator } from './validate-no-symbol-di-tokens';\nexport { NoClientCreationOutsideServerOrClientValidator } from './validate-no-client-creation-outside-server-or-client';\nexport {\n NoStatePathsInTemplatesValidator,\n StatePathHit,\n StatePathViolation,\n} from './validate-no-state-paths-in-templates';\nexport { ProjectRoleResolver } from './project-role-resolver';\nexport { NoProcessExitOutsideMainValidator } from './validate-no-process-exit-outside-main';\nexport { NoFunctionOutsideClassValidator } from './validate-no-function-outside-class';\nexport {\n InjectAnnotationNotNeededForConcreteClassValidator,\n findRedundantInjectInSource,\n} from './validate-inject-annotation-not-needed-for-concrete-class';\nexport { FrameworkTagValidator } from './validate-framework-tag';\nexport { RoleTagValidator } from './validate-role-tag';\nexport {\n EnsureWeAreSecureValidator,\n SecurityContractViolation,\n auditSecurityContracts,\n findDirectlyChangedProjectRoots,\n} from './validate-ensure-we-are-secure';\nexport { ApiLibFile, ApiLibSite } from './api-lib-source-rule';\nexport { NoInlineImportInApiLibValidator, InlineImportScanner } from './validate-no-inline-import-in-api-lib';\nexport { OneEnumSpellingInApiLibValidator, EnumSpellingScanner } from './validate-one-enum-spelling-in-api-lib';\nexport { ApiLibEnumIndex } from './api-lib-enum-index';\nexport { EnumText } from './api-lib-enum-text';\nexport { PrismaValidateDtosValidator } from './validate-dtos';\nexport { PrismaConverterValidator } from './validate-prisma-converters';\nexport { default as validateCode } from './validate-code';\n\nexport { ReactNativeCompatibility } from './react-native-compatibility';\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `no-inline-import-in-api-lib` (#1023) — an API imports at the top of the file, only.
|
|
3
|
+
*
|
|
4
|
+
* In every `role:api-lib` project this refuses:
|
|
5
|
+
*
|
|
6
|
+
* activeAiProvider?: import('@myorg/company-core').AiProvider; // an import() TYPE node
|
|
7
|
+
* const mod = await import('./heavy'); // a dynamic import() EXPRESSION
|
|
8
|
+
*
|
|
9
|
+
* and prints the replacement:
|
|
10
|
+
*
|
|
11
|
+
* import { AiProvider } from '@myorg/company-core';
|
|
12
|
+
* activeAiProvider?: AiProvider;
|
|
13
|
+
*
|
|
14
|
+
* Why: an api library is the contract every client, server and document generator reads. An inline
|
|
15
|
+
* `import()` hides a cross-library dependency inside a field's type, where no reader of the file's
|
|
16
|
+
* imports — human, architecture graph or generator — sees it, and a dynamic import in a contract is
|
|
17
|
+
* runtime behaviour in a file that should carry none.
|
|
18
|
+
*/
|
|
19
|
+
import { DiffScope, NoInlineImportInApiLibConfig } from '@webpieces/rules-config';
|
|
20
|
+
import { ApiLibFile, ApiLibSite, ApiLibSourceRule } from './api-lib-source-rule';
|
|
21
|
+
import { ProjectRoleResolver } from './project-role-resolver';
|
|
22
|
+
/** Finds every inline `import()` in one parsed file. */
|
|
23
|
+
export declare class InlineImportScanner {
|
|
24
|
+
scan(file: ApiLibFile): ApiLibSite[];
|
|
25
|
+
/** `import('m').A.B` → `import { A } from 'm';` and `A.B` in its place. */
|
|
26
|
+
private typeSite;
|
|
27
|
+
private expressionSite;
|
|
28
|
+
private specifierOf;
|
|
29
|
+
private entityText;
|
|
30
|
+
/** A PascalCase namespace name for a module specifier: `@myorg/company-core` → `CompanyCore`. */
|
|
31
|
+
private namespaceFor;
|
|
32
|
+
}
|
|
33
|
+
export declare class NoInlineImportInApiLibValidator extends ApiLibSourceRule<NoInlineImportInApiLibConfig> {
|
|
34
|
+
private readonly scanner;
|
|
35
|
+
constructor(config: NoInlineImportInApiLibConfig, roleResolver: ProjectRoleResolver, diffScope: DiffScope);
|
|
36
|
+
protected sitesIn(file: ApiLibFile): ApiLibSite[];
|
|
37
|
+
protected why(): string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `no-inline-import-in-api-lib` (#1023) — an API imports at the top of the file, only.
|
|
4
|
+
*
|
|
5
|
+
* In every `role:api-lib` project this refuses:
|
|
6
|
+
*
|
|
7
|
+
* activeAiProvider?: import('@myorg/company-core').AiProvider; // an import() TYPE node
|
|
8
|
+
* const mod = await import('./heavy'); // a dynamic import() EXPRESSION
|
|
9
|
+
*
|
|
10
|
+
* and prints the replacement:
|
|
11
|
+
*
|
|
12
|
+
* import { AiProvider } from '@myorg/company-core';
|
|
13
|
+
* activeAiProvider?: AiProvider;
|
|
14
|
+
*
|
|
15
|
+
* Why: an api library is the contract every client, server and document generator reads. An inline
|
|
16
|
+
* `import()` hides a cross-library dependency inside a field's type, where no reader of the file's
|
|
17
|
+
* imports — human, architecture graph or generator — sees it, and a dynamic import in a contract is
|
|
18
|
+
* runtime behaviour in a file that should carry none.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.NoInlineImportInApiLibValidator = exports.InlineImportScanner = void 0;
|
|
22
|
+
const tslib_1 = require("tslib");
|
|
23
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
24
|
+
const inversify_1 = require("inversify");
|
|
25
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
26
|
+
const api_lib_source_rule_1 = require("./api-lib-source-rule");
|
|
27
|
+
const project_role_resolver_1 = require("./project-role-resolver");
|
|
28
|
+
/** Finds every inline `import()` in one parsed file. */
|
|
29
|
+
class InlineImportScanner {
|
|
30
|
+
scan(file) {
|
|
31
|
+
const sites = [];
|
|
32
|
+
const visit = (node) => {
|
|
33
|
+
if (ts.isImportTypeNode(node))
|
|
34
|
+
sites.push(this.typeSite(file, node));
|
|
35
|
+
else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
36
|
+
sites.push(this.expressionSite(file, node));
|
|
37
|
+
}
|
|
38
|
+
ts.forEachChild(node, visit);
|
|
39
|
+
};
|
|
40
|
+
visit(file.source);
|
|
41
|
+
return sites;
|
|
42
|
+
}
|
|
43
|
+
/** `import('m').A.B` → `import { A } from 'm';` and `A.B` in its place. */
|
|
44
|
+
typeSite(file, node) {
|
|
45
|
+
const specifier = this.specifierOf(node);
|
|
46
|
+
const qualifier = node.qualifier === undefined ? undefined : this.entityText(node.qualifier);
|
|
47
|
+
const first = qualifier?.split('.')[0];
|
|
48
|
+
const what = 'an import() TYPE — an API imports at the top of the file, only';
|
|
49
|
+
if (first === undefined) {
|
|
50
|
+
return file.site(node, what, `add \`import * as ${this.namespaceFor(specifier)} from '${specifier}';\` at the top of the file and ` +
|
|
51
|
+
`write \`${node.isTypeOf ? 'typeof ' : ''}${this.namespaceFor(specifier)}\` here.`);
|
|
52
|
+
}
|
|
53
|
+
return file.site(node, what, `add \`import { ${first} } from '${specifier}';\` at the top of the file and write ` +
|
|
54
|
+
`\`${node.isTypeOf ? 'typeof ' : ''}${qualifier}\` here instead of \`${node.getText(file.source)}\`.`);
|
|
55
|
+
}
|
|
56
|
+
expressionSite(file, node) {
|
|
57
|
+
const argument = node.arguments[0];
|
|
58
|
+
const specifier = argument !== undefined && ts.isStringLiteralLike(argument) ? argument.text : '<module>';
|
|
59
|
+
return file.site(node, 'a dynamic import() EXPRESSION — an API loads nothing lazily; it imports at the top of the file, only', `replace it with a static \`import { … } from '${specifier}';\` at the top of the file, naming what is used.`);
|
|
60
|
+
}
|
|
61
|
+
specifierOf(node) {
|
|
62
|
+
const argument = node.argument;
|
|
63
|
+
if (ts.isLiteralTypeNode(argument) && ts.isStringLiteral(argument.literal))
|
|
64
|
+
return argument.literal.text;
|
|
65
|
+
return argument.getText();
|
|
66
|
+
}
|
|
67
|
+
entityText(name) {
|
|
68
|
+
return ts.isIdentifier(name) ? name.text : `${this.entityText(name.left)}.${name.right.text}`;
|
|
69
|
+
}
|
|
70
|
+
/** A PascalCase namespace name for a module specifier: `@myorg/company-core` → `CompanyCore`. */
|
|
71
|
+
namespaceFor(specifier) {
|
|
72
|
+
const last = specifier.split('/').pop() ?? specifier;
|
|
73
|
+
return last.split(/[^A-Za-z0-9]+/).filter((part) => part !== '')
|
|
74
|
+
.map((part) => part[0].toUpperCase() + part.slice(1)).join('') || 'Module';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.InlineImportScanner = InlineImportScanner;
|
|
78
|
+
let NoInlineImportInApiLibValidator = class NoInlineImportInApiLibValidator extends api_lib_source_rule_1.ApiLibSourceRule {
|
|
79
|
+
scanner = new InlineImportScanner();
|
|
80
|
+
constructor(config, roleResolver, diffScope) {
|
|
81
|
+
super(config, rules_config_1.RULE_NAMES.NO_INLINE_IMPORT_IN_API_LIB, roleResolver, diffScope);
|
|
82
|
+
}
|
|
83
|
+
sitesIn(file) {
|
|
84
|
+
return this.scanner.scan(file);
|
|
85
|
+
}
|
|
86
|
+
why() {
|
|
87
|
+
return 'an API imports at the top of the file, only — an inline import() hides a cross-library dependency ' +
|
|
88
|
+
'from every reader of the contract\'s imports, and a dynamic one is runtime behaviour in a contract.';
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.NoInlineImportInApiLibValidator = NoInlineImportInApiLibValidator;
|
|
92
|
+
exports.NoInlineImportInApiLibValidator = NoInlineImportInApiLibValidator = tslib_1.__decorate([
|
|
93
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
94
|
+
tslib_1.__metadata("design:paramtypes", [rules_config_1.NoInlineImportInApiLibConfig, project_role_resolver_1.ProjectRoleResolver, rules_config_1.DiffScope])
|
|
95
|
+
], NoInlineImportInApiLibValidator);
|
|
96
|
+
//# sourceMappingURL=validate-no-inline-import-in-api-lib.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-no-inline-import-in-api-lib.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-no-inline-import-in-api-lib.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;AAEH,0DAA8F;AAC9F,yCAA2D;AAC3D,uDAAiC;AACjC,+DAAiF;AACjF,mEAA8D;AAE9D,wDAAwD;AACxD,MAAa,mBAAmB;IAC5B,IAAI,CAAC,IAAgB;QACjB,MAAM,KAAK,GAAiB,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,CAAC,IAAa,EAAQ,EAAE;YAClC,I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B;QAClC,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,SAAS,CAAC;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;aACnE,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC;IAC5F,CAAC;CACJ;AArDD,kDAqDC;AAGM,IAAM,+BAA+B,GAArC,MAAM,+BAAgC,SAAQ,sCAA8C;IAC9E,OAAO,GAAG,IAAI,mBAAmB,EAAE,CAAC;IAErD,YAAY,MAAoC,EAAE,YAAiC,EAAE,SAAoB;QACrG,KAAK,CAAC,MAAM,EAAE,yBAAU,CAAC,2BAA2B,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;IACnF,CAAC;IAES,OAAO,CAAC,IAAgB;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAES,GAAG;QACT,OAAO,oGAAoG;YACvG,qGAAqG,CAAC;IAC9G,CAAC;CACJ,CAAA;AAfY,0EAA+B;0CAA/B,+BAA+B;IAD3C,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIjB,2CAA4B,EAAgB,2CAAmB,EAAa,wBAAS;GAHhG,+BAA+B,CAe3C","sourcesContent":["/**\n * `no-inline-import-in-api-lib` (#1023) — an API imports at the top of the file, only.\n *\n * In every `role:api-lib` project this refuses:\n *\n * activeAiProvider?: import('@myorg/company-core').AiProvider; // an import() TYPE node\n * const mod = await import('./heavy'); // a dynamic import() EXPRESSION\n *\n * and prints the replacement:\n *\n * import { AiProvider } from '@myorg/company-core';\n * activeAiProvider?: AiProvider;\n *\n * Why: an api library is the contract every client, server and document generator reads. An inline\n * `import()` hides a cross-library dependency inside a field's type, where no reader of the file's\n * imports — human, architecture graph or generator — sees it, and a dynamic import in a contract is\n * runtime behaviour in a file that should carry none.\n */\n\nimport { DiffScope, NoInlineImportInApiLibConfig, RULE_NAMES } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport * as ts from 'typescript';\nimport { ApiLibFile, ApiLibSite, ApiLibSourceRule } from './api-lib-source-rule';\nimport { ProjectRoleResolver } from './project-role-resolver';\n\n/** Finds every inline `import()` in one parsed file. */\nexport class InlineImportScanner {\n scan(file: ApiLibFile): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n const visit = (node: ts.Node): void => {\n if (ts.isImportTypeNode(node)) sites.push(this.typeSite(file, node));\n else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {\n sites.push(this.expressionSite(file, node));\n }\n ts.forEachChild(node, visit);\n };\n visit(file.source);\n return sites;\n }\n\n /** `import('m').A.B` → `import { A } from 'm';` and `A.B` in its place. */\n private typeSite(file: ApiLibFile, node: ts.ImportTypeNode): ApiLibSite {\n const specifier = this.specifierOf(node);\n const qualifier = node.qualifier === undefined ? undefined : this.entityText(node.qualifier);\n const first = qualifier?.split('.')[0];\n const what = 'an import() TYPE — an API imports at the top of the file, only';\n if (first === undefined) {\n return file.site(node, what,\n `add \\`import * as ${this.namespaceFor(specifier)} from '${specifier}';\\` at the top of the file and ` +\n `write \\`${node.isTypeOf ? 'typeof ' : ''}${this.namespaceFor(specifier)}\\` here.`);\n }\n return file.site(node, what,\n `add \\`import { ${first} } from '${specifier}';\\` at the top of the file and write ` +\n `\\`${node.isTypeOf ? 'typeof ' : ''}${qualifier}\\` here instead of \\`${node.getText(file.source)}\\`.`);\n }\n\n private expressionSite(file: ApiLibFile, node: ts.CallExpression): ApiLibSite {\n const argument = node.arguments[0];\n const specifier = argument !== undefined && ts.isStringLiteralLike(argument) ? argument.text : '<module>';\n return file.site(node, 'a dynamic import() EXPRESSION — an API loads nothing lazily; it imports at the top of the file, only',\n `replace it with a static \\`import { … } from '${specifier}';\\` at the top of the file, naming what is used.`);\n }\n\n private specifierOf(node: ts.ImportTypeNode): string {\n const argument = node.argument;\n if (ts.isLiteralTypeNode(argument) && ts.isStringLiteral(argument.literal)) return argument.literal.text;\n return argument.getText();\n }\n\n private entityText(name: ts.EntityName): string {\n return ts.isIdentifier(name) ? name.text : `${this.entityText(name.left)}.${name.right.text}`;\n }\n\n /** A PascalCase namespace name for a module specifier: `@myorg/company-core` → `CompanyCore`. */\n private namespaceFor(specifier: string): string {\n const last = specifier.split('/').pop() ?? specifier;\n return last.split(/[^A-Za-z0-9]+/).filter((part: string) => part !== '')\n .map((part: string) => part[0]!.toUpperCase() + part.slice(1)).join('') || 'Module';\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class NoInlineImportInApiLibValidator extends ApiLibSourceRule<NoInlineImportInApiLibConfig> {\n private readonly scanner = new InlineImportScanner();\n\n constructor(config: NoInlineImportInApiLibConfig, roleResolver: ProjectRoleResolver, diffScope: DiffScope) {\n super(config, RULE_NAMES.NO_INLINE_IMPORT_IN_API_LIB, roleResolver, diffScope);\n }\n\n protected sitesIn(file: ApiLibFile): ApiLibSite[] {\n return this.scanner.scan(file);\n }\n\n protected why(): string {\n return 'an API imports at the top of the file, only — an inline import() hides a cross-library dependency ' +\n 'from every reader of the contract\\'s imports, and a dynamic one is runtime behaviour in a contract.';\n }\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `one-enum-spelling-in-api-lib` (#1023) — ONE spelling for a fixed set of string values in an API:
|
|
3
|
+
*
|
|
4
|
+
* export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }
|
|
5
|
+
* gender!: SpeakerGender; // the enum
|
|
6
|
+
* mode: VoiceMode.RANDOM; // one member (a union discriminator)
|
|
7
|
+
* mode: VoiceMode.A | VoiceMode.B; // a union of members
|
|
8
|
+
*
|
|
9
|
+
* In every `role:api-lib` project this refuses, each with a cure that PRINTS the enum to write:
|
|
10
|
+
*
|
|
11
|
+
* type LessonType = 'story' | 'lesson'; kind?: 'audio' | 'slot'; (a 2+ string-literal union)
|
|
12
|
+
* gender!: (typeof SPEAKER_GENDERS)[number]; key: keyof typeof LABELS;
|
|
13
|
+
* mode: 'random'; (a single literal used as a union discriminator)
|
|
14
|
+
* enum Level { LOW, HIGH } enum Mixed { A = 'a', B = 2 } const enum Tone { … }
|
|
15
|
+
*
|
|
16
|
+
* Why ONE spelling: two ways to write a closed set means every reader, reviewer and the document
|
|
17
|
+
* generator has to understand both, and the derived spellings (`(typeof X)[number]`, a `string` field
|
|
18
|
+
* whose legal values live in some array) are exactly the ones the generator does not read — they can
|
|
19
|
+
* only be supported later, deliberately, if ever. A numeric enum puts NUMBERS on the wire, which no
|
|
20
|
+
* partner reading `gender: 1` can interpret. The generator itself keeps supporting literal unions;
|
|
21
|
+
* this rule is what forbids new ones in an api library.
|
|
22
|
+
*/
|
|
23
|
+
import { DiffScope, OneEnumSpellingInApiLibConfig } from '@webpieces/rules-config';
|
|
24
|
+
import { ApiLibEnumIndex } from './api-lib-enum-index';
|
|
25
|
+
import { ApiLibFile, ApiLibSite, ApiLibSourceRule } from './api-lib-source-rule';
|
|
26
|
+
import { ProjectRoleResolver } from './project-role-resolver';
|
|
27
|
+
/** Finds every non-enum spelling of a closed string set in one parsed file. */
|
|
28
|
+
export declare class EnumSpellingScanner {
|
|
29
|
+
scan(file: ApiLibFile, index: ApiLibEnumIndex): ApiLibSite[];
|
|
30
|
+
private siteAt;
|
|
31
|
+
/** `'a' | 'b'` — two or more string-literal branches, anywhere a type is written. */
|
|
32
|
+
private literalUnion;
|
|
33
|
+
/** `mode: 'random'` on a branch of a union — a discriminator, which is one enum member. */
|
|
34
|
+
private singleLiteral;
|
|
35
|
+
/** `(typeof X)[number]` — the values live in a runtime list; the enum IS that list. */
|
|
36
|
+
private typeofIndex;
|
|
37
|
+
/** `keyof typeof X` — the values are an object's keys; the enum states them. */
|
|
38
|
+
private keyofTypeof;
|
|
39
|
+
/** A `const`, numeric, heterogeneous or uninitialised enum. */
|
|
40
|
+
private badEnum;
|
|
41
|
+
/** The declaration a written type belongs to — climbing through arrays, parens, unions and generics. */
|
|
42
|
+
private holderOf;
|
|
43
|
+
/** The nearest enclosing named interface, class, type alias or function. */
|
|
44
|
+
private ownerOf;
|
|
45
|
+
/**
|
|
46
|
+
* When the holder is a property of a union BRANCH that every branch declares, it discriminates the
|
|
47
|
+
* union: the enum is named for the union and property, and holds every branch's values.
|
|
48
|
+
*/
|
|
49
|
+
private discriminatorOf;
|
|
50
|
+
/** The string literals a property type spells: `'a'` or `'a' | 'b'`. */
|
|
51
|
+
private literalValues;
|
|
52
|
+
private enumNameFor;
|
|
53
|
+
}
|
|
54
|
+
export declare class OneEnumSpellingInApiLibValidator extends ApiLibSourceRule<OneEnumSpellingInApiLibConfig> {
|
|
55
|
+
private readonly scanner;
|
|
56
|
+
/** One index per api-library directory, per run: the union and its branches are in different files. */
|
|
57
|
+
private readonly indexes;
|
|
58
|
+
constructor(config: OneEnumSpellingInApiLibConfig, roleResolver: ProjectRoleResolver, diffScope: DiffScope);
|
|
59
|
+
protected sitesIn(file: ApiLibFile): ApiLibSite[];
|
|
60
|
+
protected why(): string;
|
|
61
|
+
}
|