@webpieces/code-rules 0.4.902 → 0.4.904
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 +6 -6
- package/src/configs/required-type-suffix-config.d.ts +9 -6
- package/src/configs/required-type-suffix-config.js +9 -5
- package/src/configs/required-type-suffix-config.js.map +1 -1
- package/src/rule-settings.js +2 -1
- package/src/rule-settings.js.map +1 -1
- package/src/validate-required-type-suffix.d.ts +4 -3
- package/src/validate-required-type-suffix.js +6 -3
- package/src/validate-required-type-suffix.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/code-rules",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.904",
|
|
4
4
|
"description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,19 +16,19 @@
|
|
|
16
16
|
"directory": "packages/tooling/code-rules"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/rules-config": "0.4.904",
|
|
20
20
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
25
|
-
"@webpieces/rules-sdk": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.904",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.904",
|
|
25
|
+
"@webpieces/rules-sdk": "0.4.904"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
31
|
+
"@webpieces/tooling-testkit": "0.4.904"
|
|
32
32
|
},
|
|
33
33
|
"exports": {
|
|
34
34
|
".": "./src/index.js",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SchemaShape, BaseRuleConfig } from
|
|
2
|
-
import { ModifiedCodeMode } from
|
|
1
|
+
import { SchemaShape, BaseRuleConfig } from '@webpieces/rules-sdk';
|
|
2
|
+
import { ModifiedCodeMode } from '@webpieces/rules-sdk';
|
|
3
3
|
/**
|
|
4
4
|
* One `required-type-suffix` entry: the path globs it covers and the suffixes a type exported from a
|
|
5
5
|
* file under them may end in. Data-only.
|
|
@@ -7,8 +7,10 @@ import { ModifiedCodeMode } from "@webpieces/rules-sdk";
|
|
|
7
7
|
export declare class RequiredTypeSuffixEntry {
|
|
8
8
|
/** Workspace-relative globs, e.g. `["libraries/apis/internal/**"]`. Non-empty. */
|
|
9
9
|
paths: string[];
|
|
10
|
-
/** Case-sensitive
|
|
10
|
+
/** Case-sensitive suffixes, retained even while this path is explicitly exempt. Non-empty. */
|
|
11
11
|
suffixes: string[];
|
|
12
|
+
/** Explicit per-path opt-out. Required so an exemption is a named, greppable decision. */
|
|
13
|
+
exempt: boolean;
|
|
12
14
|
static readonly SCHEMA: SchemaShape<RequiredTypeSuffixEntry>;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
@@ -23,11 +25,12 @@ export declare class RequiredTypeSuffixEntry {
|
|
|
23
25
|
* renamed type — so legacy names are grandfathered) | NEW_AND_MODIFIED_FILES (every exported type in a
|
|
24
26
|
* changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every exported type in each touched project / the
|
|
25
27
|
* whole repo — #1027).
|
|
26
|
-
* - `entries` — non-empty; each entry has non-empty `paths` and `suffixes
|
|
28
|
+
* - `entries` — non-empty; each entry has non-empty `paths` and `suffixes`, and an explicit `exempt` boolean. For example:
|
|
27
29
|
*
|
|
28
30
|
* "entries": [
|
|
29
|
-
* { "paths": ["libraries/apis/
|
|
30
|
-
* { "paths": ["libraries/
|
|
31
|
+
* { "paths": ["libraries/apis/partner/**"], "suffixes": ["Dto", "Api"], "exempt": true },
|
|
32
|
+
* { "paths": ["libraries/apis/internal/**"], "suffixes": ["Request", "Response", "Event", "Dto", "Api"], "exempt": false },
|
|
33
|
+
* { "paths": ["libraries/browser-node/fs-*-model/**"], "suffixes": ["Fs"], "exempt": false }
|
|
31
34
|
* ]
|
|
32
35
|
*
|
|
33
36
|
* OVERLAP — the FIRST MATCH in `entries` order wins; suffixes are never unioned. A file is governed by
|
|
@@ -10,11 +10,14 @@ const rules_sdk_2 = require("@webpieces/rules-sdk");
|
|
|
10
10
|
class RequiredTypeSuffixEntry {
|
|
11
11
|
/** Workspace-relative globs, e.g. `["libraries/apis/internal/**"]`. Non-empty. */
|
|
12
12
|
paths;
|
|
13
|
-
/** Case-sensitive
|
|
13
|
+
/** Case-sensitive suffixes, retained even while this path is explicitly exempt. Non-empty. */
|
|
14
14
|
suffixes;
|
|
15
|
+
/** Explicit per-path opt-out. Required so an exemption is a named, greppable decision. */
|
|
16
|
+
exempt;
|
|
15
17
|
static SCHEMA = {
|
|
16
18
|
paths: rules_sdk_1.FieldDef.nonEmptyStrings(),
|
|
17
|
-
suffixes: rules_sdk_1.FieldDef.nonEmptyStrings(),
|
|
19
|
+
suffixes: rules_sdk_1.FieldDef.nonEmptyStrings('To exempt this path, set exempt: true and retain a non-empty suffixes list; suffixes: [] is not an exemption.'),
|
|
20
|
+
exempt: new rules_sdk_1.FieldDef('boolean'),
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
exports.RequiredTypeSuffixEntry = RequiredTypeSuffixEntry;
|
|
@@ -30,11 +33,12 @@ exports.RequiredTypeSuffixEntry = RequiredTypeSuffixEntry;
|
|
|
30
33
|
* renamed type — so legacy names are grandfathered) | NEW_AND_MODIFIED_FILES (every exported type in a
|
|
31
34
|
* changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every exported type in each touched project / the
|
|
32
35
|
* whole repo — #1027).
|
|
33
|
-
* - `entries` — non-empty; each entry has non-empty `paths` and `suffixes
|
|
36
|
+
* - `entries` — non-empty; each entry has non-empty `paths` and `suffixes`, and an explicit `exempt` boolean. For example:
|
|
34
37
|
*
|
|
35
38
|
* "entries": [
|
|
36
|
-
* { "paths": ["libraries/apis/
|
|
37
|
-
* { "paths": ["libraries/
|
|
39
|
+
* { "paths": ["libraries/apis/partner/**"], "suffixes": ["Dto", "Api"], "exempt": true },
|
|
40
|
+
* { "paths": ["libraries/apis/internal/**"], "suffixes": ["Request", "Response", "Event", "Dto", "Api"], "exempt": false },
|
|
41
|
+
* { "paths": ["libraries/browser-node/fs-*-model/**"], "suffixes": ["Fs"], "exempt": false }
|
|
38
42
|
* ]
|
|
39
43
|
*
|
|
40
44
|
* OVERLAP — the FIRST MATCH in `entries` order wins; suffixes are never unioned. A file is governed by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"required-type-suffix-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/required-type-suffix-config.ts"],"names":[],"mappings":";;;AAAA,oDAA+F;AAC/F,oDAA6E;AAC7E;;;GAGG;AACH,MAAa,uBAAuB;IAChC,kFAAkF;IAClF,KAAK,CAAY;IACjB,
|
|
1
|
+
{"version":3,"file":"required-type-suffix-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/configs/required-type-suffix-config.ts"],"names":[],"mappings":";;;AAAA,oDAA+F;AAC/F,oDAA6E;AAC7E;;;GAGG;AACH,MAAa,uBAAuB;IAChC,kFAAkF;IAClF,KAAK,CAAY;IACjB,8FAA8F;IAC9F,QAAQ,CAAY;IACpB,0FAA0F;IAC1F,MAAM,CAAW;IAEjB,MAAM,CAAU,MAAM,GAAyC;QAC3D,KAAK,EAAE,oBAAQ,CAAC,eAAe,EAAE;QACjC,QAAQ,EAAE,oBAAQ,CAAC,eAAe,CAC9B,+GAA+G,CAClH;QACD,MAAM,EAAE,IAAI,oBAAQ,CAAC,SAAS,CAAC;KAClC,CAAC;;AAdN,0DAeC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,wBAAyB,SAAQ,0BAAc;IAExD,OAAO,CAA6B;IACpC,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA0C;QAC5D,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,+BAAmB,CAAC;QACjD,OAAO,EAAE,oBAAQ,CAAC,eAAe,CAAC,uBAAuB,CAAC,MAAM,CAAC;QACjE,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,4BAAgB;KACtB,CAAC;;AAVN,4DAWC","sourcesContent":["import { FieldDef, SchemaShape, BaseRuleConfig, BASE_RULE_SCHEMA } from '@webpieces/rules-sdk';\nimport { ModifiedCodeMode, MODIFIED_CODE_MODES } from '@webpieces/rules-sdk';\n/**\n * One `required-type-suffix` entry: the path globs it covers and the suffixes a type exported from a\n * file under them may end in. Data-only.\n */\nexport class RequiredTypeSuffixEntry {\n /** Workspace-relative globs, e.g. `[\"libraries/apis/internal/**\"]`. Non-empty. */\n paths!: string[];\n /** Case-sensitive suffixes, retained even while this path is explicitly exempt. Non-empty. */\n suffixes!: string[];\n /** Explicit per-path opt-out. Required so an exemption is a named, greppable decision. */\n exempt!: boolean;\n\n static readonly SCHEMA: SchemaShape<RequiredTypeSuffixEntry> = {\n paths: FieldDef.nonEmptyStrings(),\n suffixes: FieldDef.nonEmptyStrings(\n 'To exempt this path, set exempt: true and retain a non-empty suffixes list; suffixes: [] is not an exemption.',\n ),\n exempt: new FieldDef('boolean'),\n };\n}\n\n/**\n * `required-type-suffix` (#1037) — every EXPORTED `interface`, `class` (abstract too), `enum` and `type`\n * alias in a non-test `.ts` file under an entry's `paths` must end in one of that entry's `suffixes`\n * (plain, case-sensitive `endsWith`; the suffix alone is not a name). Why: the suffix tells a reader which\n * LAYER a type belongs to — a `…Dto` is on the wire, a `…Fs` is a Firestore document — where an\n * unsuffixed name reads the same as a server-internal or vendor type.\n *\n * Every field that decides behaviour is REQUIRED with no default (`.claude/rules/no-rule-defaults.md`):\n * - `mode` — OFF | NEW_AND_MODIFIED_CODE (only a type whose declaration line is new or changed — a new or\n * renamed type — so legacy names are grandfathered) | NEW_AND_MODIFIED_FILES (every exported type in a\n * changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every exported type in each touched project / the\n * whole repo — #1027).\n * - `entries` — non-empty; each entry has non-empty `paths` and `suffixes`, and an explicit `exempt` boolean. For example:\n *\n * \"entries\": [\n * { \"paths\": [\"libraries/apis/partner/**\"], \"suffixes\": [\"Dto\", \"Api\"], \"exempt\": true },\n * { \"paths\": [\"libraries/apis/internal/**\"], \"suffixes\": [\"Request\", \"Response\", \"Event\", \"Dto\", \"Api\"], \"exempt\": false },\n * { \"paths\": [\"libraries/browser-node/fs-*-model/**\"], \"suffixes\": [\"Fs\"], \"exempt\": false }\n * ]\n *\n * OVERLAP — the FIRST MATCH in `entries` order wins; suffixes are never unioned. A file is governed by\n * exactly one entry: the entries are read top to bottom, and the first one with a glob matching the file\n * decides its suffixes. ORDER MATTERS: a narrower entry must be listed BEFORE a broader one. With\n * `libraries/apis/internal/**` listed above `libraries/apis/**`, the narrower entry governs\n * `libraries/apis/internal/x/src/A.ts`; listed below it, the broader entry governs that file and the\n * narrower one never applies there. A failure names the governing entry's glob, so a reader can see\n * which entry won.\n *\n * `allowedPaths` exempts whole trees inside `paths`. The per-site escape hatch is\n * `// webpieces-disable required-type-suffix -- <reason>` on the declaration's line or the line above.\n */\nexport class RequiredTypeSuffixConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n entries!: RequiredTypeSuffixEntry[];\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<RequiredTypeSuffixConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n entries: FieldDef.nonEmptyObjects(RequiredTypeSuffixEntry.SCHEMA),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}
|
package/src/rule-settings.js
CHANGED
package/src/rule-settings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-settings.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-settings.ts"],"names":[],"mappings":";;;AAEA,oFAAoF;AACvE,QAAA,cAAc,GAA2C;IAClE,kBAAkB,EAAE;QAChB,OAAO,EAAE,EAAE;KACd;IACD,gBAAgB,EAAE;QACd,OAAO,EAAE,GAAG;KACf;IACD,qBAAqB,EAAE,EAAE;IACzB,yBAAyB,EAAE,EAAE;IAC7B,gBAAgB,EAAE,EAAE;IACpB,iBAAiB,EAAE,EAAE;IACrB,sBAAsB,EAAE,EAAE;IAC1B,kBAAkB,EAAE,EAAE;IACtB,gBAAgB,EAAE;QACd,eAAe,EAAE,IAAI;KACxB;IACD,qBAAqB,EAAE,EAAE;IACzB,yBAAyB,EAAE,EAAE;IAC7B,mCAAmC,EAAE,EAAE;IACvC,qBAAqB,EAAE,EAAE;IACzB,6CAA6C,EAAE,EAAE;IACjD,eAAe,EAAE;QACb,YAAY,EAAE,EAAE;KACnB;IACD,6BAA6B,EAAE,EAAE;IACjC,8BAA8B,EAAE,EAAE;IAClC,2BAA2B,EAAE,EAAE;IAC/B,iDAAiD,EAAE,EAAE;IACrD,eAAe,EAAE;QACb,YAAY,EAAE;YACV,SAAS;YACT,OAAO;YACP,SAAS;YACT,MAAM;YACN,SAAS;YACT,cAAc;SACjB;KACJ;IACD,UAAU,EAAE;QACR,YAAY,EAAE;YACV,QAAQ;YACR,KAAK;YACL,QAAQ;YACR,cAAc;YACd,KAAK;YACL,QAAQ;YACR,SAAS;YACT,YAAY;SACf;KACJ;IACD,sBAAsB,EAAE,EAAE;IAC1B,6BAA6B,EAAE,EAAE;IACjC,8BAA8B,EAAE,EAAE;IAClC,6BAA6B,EAAE,EAAE;IACjC,sBAAsB,EAAE,EAAE;IAC1B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,UAAU,EAAE;oBACR,UAAU;iBACb;gBACD,YAAY,EAAE;oBACV,SAAS;oBACT,SAAS;oBACT,OAAO;iBACV;aACJ;SACJ;KACJ;CACJ,CAAC","sourcesContent":["import { ConfigObject } from '@webpieces/rules-sdk';\n\n/** Optional knobs only. Required behaviour is always supplied by the repository. */\nexport const optionalTuning: Readonly<Record<string, ConfigObject>> = {\n \"max-method-lines\": {\n \"limit\": 80\n },\n \"max-file-lines\": {\n \"limit\": 900\n },\n \"require-return-type\": {},\n \"no-inline-type-literals\": {},\n \"no-any-unknown\": {},\n \"no-implicit-any\": {},\n \"prisma-validate-dtos\": {},\n \"prisma-converter\": {},\n \"no-destructure\": {\n \"allowTopLevel\": true\n },\n \"catch-error-pattern\": {},\n \"no-unmanaged-exceptions\": {},\n \"angular-no-direct-api-in-resolver\": {},\n \"no-symbol-di-tokens\": {},\n \"no-client-creation-outside-server-or-client\": {},\n \"no-custom-css\": {\n \"allowGlobs\": []\n },\n \"no-state-paths-in-templates\": {},\n \"no-process-exit-outside-main\": {},\n \"no-function-outside-class\": {},\n \"inject-annotation-not-needed-for-concrete-class\": {},\n \"framework-tag\": {\n \"knownTypes\": [\n \"browser\",\n \"react\",\n \"angular\",\n \"node\",\n \"express\",\n \"react-native\"\n ]\n },\n \"role-tag\": {\n \"knownTypes\": [\n \"server\",\n \"app\",\n \"bundle\",\n \"designed-lib\",\n \"lib\",\n \"client\",\n \"api-lib\",\n \"api-client\"\n ]\n },\n \"ensure-we-are-secure\": {},\n \"no-inline-import-in-api-lib\": {},\n \"one-enum-spelling-in-api-lib\": {},\n \"no-utility-types-in-api-lib\": {},\n \"required-type-suffix\": {},\n \"framework-tsconfig\": {},\n \"framework-packages\": {}\n};\n\n/** Written for review by setup/sync; never used as a loader fallback. */\nexport const recommendedSeeds: Readonly<Record<string, ConfigObject>> = {\n \"max-method-lines\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"max-file-lines\": {\n \"mode\": \"NEW_AND_MODIFIED_FILES\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"require-return-type\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-inline-type-literals\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-any-unknown\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-implicit-any\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"prisma-validate-dtos\": {\n \"mode\": \"MODIFIED_CLASS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"prisma-converter\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-destructure\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"catch-error-pattern\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-unmanaged-exceptions\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"angular-no-direct-api-in-resolver\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-symbol-di-tokens\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-client-creation-outside-server-or-client\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-custom-css\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-state-paths-in-templates\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-process-exit-outside-main\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-function-outside-class\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"inject-annotation-not-needed-for-concrete-class\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"framework-tag\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"role-tag\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"ensure-we-are-secure\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-inline-import-in-api-lib\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"one-enum-spelling-in-api-lib\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-utility-types-in-api-lib\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null,\n \"paths\": [\n \"libraries/apis/**\"\n ]\n },\n \"required-type-suffix\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null,\n \"entries\": [\n {\n \"paths\": [\n \"libraries/apis/**\"\n ],\n \"suffixes\": [\n \"Request\",\n \"Response\",\n \"Event\",\n \"Dto\",\n \"Api\"\n ]\n }\n ]\n },\n \"framework-tsconfig\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"framework-packages\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null,\n \"entries\": [\n {\n \"packages\": [\n \"@angular/*\"\n ],\n \"frameworks\": [\n \"angular\"\n ]\n },\n {\n \"packages\": [\n \"react\",\n \"react-native\",\n \"expo*\",\n \"@expo/*\",\n \"@sentry/react-native\"\n ],\n \"frameworks\": [\n \"react\",\n \"react-native\"\n ]\n },\n {\n \"packages\": [\n \"express\",\n \"firebase-admin\",\n \"googleapis\",\n \"google-auth-library\",\n \"@google-cloud/*\"\n ],\n \"frameworks\": [\n \"node\",\n \"express\"\n ]\n },\n {\n \"packages\": [\n \"firebase\"\n ],\n \"frameworks\": [\n \"browser\",\n \"angular\",\n \"react\"\n ]\n }\n ]\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"rule-settings.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-settings.ts"],"names":[],"mappings":";;;AAE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B,MAAM,EAAE,uBAAuB;QAC/B,uBAAuB,EAAE,CAAC;QAC1B,0BAA0B,EAAE,IAAI;QAChC,OAAO,EAAE;YACL,mBAAmB;SACtB;KACJ;IACD,sBAAsB,EAAE;QACpB,MAAM,EAAE,uBAAuB;QAC/B,uBAAuB,EAAE,CAAC;QAC1B,0BAA0B,EAAE,IAAI;QAChC,SAAS,EAAE;YACP;gBACI,OAAO,EAAE;oBACL,mBAAmB;iBACtB;gBACD,UAAU,EAAE;oBACR,SAAS;oBACT,UAAU;oBACV,OAAO;oBACP,KAAK;oBACL,KAAK;iBACR;gBACD,QAAQ,EAAE,KAAK;aAClB;SACJ;KACJ;IACD,oBAAoB,EAAE;QAClB,MAAM,EAAE,mBAAmB;QAC3B,uBAAuB,EAAE,CAAC;QAC1B,0BAA0B,EAAE,IAAI;KACnC;IACD,oBAAoB,EAAE;QAClB,MAAM,EAAE,mBAAmB;QAC3B,uBAAuB,EAAE,CAAC;QAC1B,0BAA0B,EAAE,IAAI;QAChC,SAAS,EAAE;YACP;gBACI,UAAU,EAAE;oBACR,YAAY;iBACf;gBACD,YAAY,EAAE;oBACV,SAAS;iBACZ;aACJ;YACD;gBACI,UAAU,EAAE;oBACR,OAAO;oBACP,cAAc;oBACd,OAAO;oBACP,SAAS;oBACT,sBAAsB;iBACzB;gBACD,YAAY,EAAE;oBACV,OAAO;oBACP,cAAc;iBACjB;aACJ;YACD;gBACI,UAAU,EAAE;oBACR,SAAS;oBACT,gBAAgB;oBAChB,YAAY;oBACZ,qBAAqB;oBACrB,iBAAiB;iBACpB;gBACD,YAAY,EAAE;oBACV,MAAM;oBACN,SAAS;iBACZ;aACJ;YACD;gBACI,UAAU,EAAE;oBACR,UAAU;iBACb;gBACD,YAAY,EAAE;oBACV,SAAS;oBACT,SAAS;oBACT,OAAO;iBACV;aACJ;SACJ;KACJ;CACJ,CAAC","sourcesContent":["import { ConfigObject } from '@webpieces/rules-sdk';\n\n/** Optional knobs only. Required behaviour is always supplied by the repository. */\nexport const optionalTuning: Readonly<Record<string, ConfigObject>> = {\n \"max-method-lines\": {\n \"limit\": 80\n },\n \"max-file-lines\": {\n \"limit\": 900\n },\n \"require-return-type\": {},\n \"no-inline-type-literals\": {},\n \"no-any-unknown\": {},\n \"no-implicit-any\": {},\n \"prisma-validate-dtos\": {},\n \"prisma-converter\": {},\n \"no-destructure\": {\n \"allowTopLevel\": true\n },\n \"catch-error-pattern\": {},\n \"no-unmanaged-exceptions\": {},\n \"angular-no-direct-api-in-resolver\": {},\n \"no-symbol-di-tokens\": {},\n \"no-client-creation-outside-server-or-client\": {},\n \"no-custom-css\": {\n \"allowGlobs\": []\n },\n \"no-state-paths-in-templates\": {},\n \"no-process-exit-outside-main\": {},\n \"no-function-outside-class\": {},\n \"inject-annotation-not-needed-for-concrete-class\": {},\n \"framework-tag\": {\n \"knownTypes\": [\n \"browser\",\n \"react\",\n \"angular\",\n \"node\",\n \"express\",\n \"react-native\"\n ]\n },\n \"role-tag\": {\n \"knownTypes\": [\n \"server\",\n \"app\",\n \"bundle\",\n \"designed-lib\",\n \"lib\",\n \"client\",\n \"api-lib\",\n \"api-client\"\n ]\n },\n \"ensure-we-are-secure\": {},\n \"no-inline-import-in-api-lib\": {},\n \"one-enum-spelling-in-api-lib\": {},\n \"no-utility-types-in-api-lib\": {},\n \"required-type-suffix\": {},\n \"framework-tsconfig\": {},\n \"framework-packages\": {}\n};\n\n/** Written for review by setup/sync; never used as a loader fallback. */\nexport const recommendedSeeds: Readonly<Record<string, ConfigObject>> = {\n \"max-method-lines\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"max-file-lines\": {\n \"mode\": \"NEW_AND_MODIFIED_FILES\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"require-return-type\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-inline-type-literals\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-any-unknown\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-implicit-any\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"prisma-validate-dtos\": {\n \"mode\": \"MODIFIED_CLASS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"prisma-converter\": {\n \"mode\": \"NEW_AND_MODIFIED_METHODS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-destructure\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"catch-error-pattern\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-unmanaged-exceptions\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"angular-no-direct-api-in-resolver\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-symbol-di-tokens\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-client-creation-outside-server-or-client\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-custom-css\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-state-paths-in-templates\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-process-exit-outside-main\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-function-outside-class\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"inject-annotation-not-needed-for-concrete-class\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"framework-tag\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"role-tag\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"ensure-we-are-secure\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-inline-import-in-api-lib\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"one-enum-spelling-in-api-lib\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"no-utility-types-in-api-lib\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null,\n \"paths\": [\n \"libraries/apis/**\"\n ]\n },\n \"required-type-suffix\": {\n \"mode\": \"NEW_AND_MODIFIED_CODE\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null,\n \"entries\": [\n {\n \"paths\": [\n \"libraries/apis/**\"\n ],\n \"suffixes\": [\n \"Request\",\n \"Response\",\n \"Event\",\n \"Dto\",\n \"Api\"\n ],\n \"exempt\": false\n }\n ]\n },\n \"framework-tsconfig\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null\n },\n \"framework-packages\": {\n \"mode\": \"MODIFIED_PROJECTS\",\n \"turnOffRuleUntilEpoch\": 0,\n \"turnOffRuleWhileOnBranch\": null,\n \"entries\": [\n {\n \"packages\": [\n \"@angular/*\"\n ],\n \"frameworks\": [\n \"angular\"\n ]\n },\n {\n \"packages\": [\n \"react\",\n \"react-native\",\n \"expo*\",\n \"@expo/*\",\n \"@sentry/react-native\"\n ],\n \"frameworks\": [\n \"react\",\n \"react-native\"\n ]\n },\n {\n \"packages\": [\n \"express\",\n \"firebase-admin\",\n \"googleapis\",\n \"google-auth-library\",\n \"@google-cloud/*\"\n ],\n \"frameworks\": [\n \"node\",\n \"express\"\n ]\n },\n {\n \"packages\": [\n \"firebase\"\n ],\n \"frameworks\": [\n \"browser\",\n \"angular\",\n \"react\"\n ]\n }\n ]\n }\n};\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `required-type-suffix` (#1037) — a type's name says which layer it belongs to.
|
|
3
3
|
*
|
|
4
|
-
* Configured as a list of entries, each pairing path globs with
|
|
4
|
+
* Configured as a list of entries, each pairing path globs with allowed suffixes and an explicit exemption:
|
|
5
|
+
* `exempt: true` skips suffix enforcement for the matching entry; `exempt: false` enforces its suffixes.
|
|
5
6
|
*
|
|
6
|
-
* { "paths": ["libraries/apis/internal/**"], "suffixes": ["Request", "Response", "Event", "Dto", "Api"] }
|
|
7
|
-
* { "paths": ["libraries/browser-node/fs-*-model/**"], "suffixes": ["Fs"] }
|
|
7
|
+
* { "paths": ["libraries/apis/internal/**"], "suffixes": ["Request", "Response", "Event", "Dto", "Api"], "exempt": false }
|
|
8
|
+
* { "paths": ["libraries/browser-node/fs-*-model/**"], "suffixes": ["Fs"], "exempt": false }
|
|
8
9
|
*
|
|
9
10
|
* Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under
|
|
10
11
|
* an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the
|
|
@@ -6,10 +6,11 @@ const rules_config_1 = require("@webpieces/rules-config");
|
|
|
6
6
|
/**
|
|
7
7
|
* `required-type-suffix` (#1037) — a type's name says which layer it belongs to.
|
|
8
8
|
*
|
|
9
|
-
* Configured as a list of entries, each pairing path globs with
|
|
9
|
+
* Configured as a list of entries, each pairing path globs with allowed suffixes and an explicit exemption:
|
|
10
|
+
* `exempt: true` skips suffix enforcement for the matching entry; `exempt: false` enforces its suffixes.
|
|
10
11
|
*
|
|
11
|
-
* { "paths": ["libraries/apis/internal/**"], "suffixes": ["Request", "Response", "Event", "Dto", "Api"] }
|
|
12
|
-
* { "paths": ["libraries/browser-node/fs-*-model/**"], "suffixes": ["Fs"] }
|
|
12
|
+
* { "paths": ["libraries/apis/internal/**"], "suffixes": ["Request", "Response", "Event", "Dto", "Api"], "exempt": false }
|
|
13
|
+
* { "paths": ["libraries/browser-node/fs-*-model/**"], "suffixes": ["Fs"], "exempt": false }
|
|
13
14
|
*
|
|
14
15
|
* Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under
|
|
15
16
|
* an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the
|
|
@@ -109,6 +110,8 @@ exports.SuffixRename = SuffixRename;
|
|
|
109
110
|
class ExportedTypeScanner {
|
|
110
111
|
rename = new SuffixRename();
|
|
111
112
|
scan(file, entry, glob) {
|
|
113
|
+
if (entry.exempt)
|
|
114
|
+
return [];
|
|
112
115
|
const sites = [];
|
|
113
116
|
const locals = new Map();
|
|
114
117
|
for (const statement of file.source.statements) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-required-type-suffix.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-required-type-suffix.ts"],"names":[],"mappings":";;;;AAAA,0DAA6E;AAC7E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,0DAAoE;AACpE,uFAG+C;AAC/C,yCAA2D;AAC3D,uDAAiC;AACjC,+DAAiF;AACjF,mEAA8D;AAC9D,6CAAyC;AAEzC,0GAA0G;AAC1G,MAAa,aAAa;IAET;IACA;IAFb,YACa,KAA8B,EAC9B,IAAY;QADZ,UAAK,GAAL,KAAK,CAAyB;QAC9B,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AALD,sCAKC;AAED;;;;GAIG;AACH,MAAa,iBAAiB;IAC1B,QAAQ,CACJ,OAAe,EACf,OAA2C;QAE3C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,KAAK,CAAC;IAChD,CAAC;IAED,4GAA4G;IAC5G,MAAM,CACF,OAAe,EACf,OAA2C;QAE3C,MAAM,KAAK,GAAG,IAAI,6BAAc,EAAE,CAAC,MAAM,CACrC,OAAO,EACP,OAAO,CAAC,GAAG,CACP,CAAC,KAA8B,EAAE,EAAE,CAAC,IAAI,iCAAkB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CACjF,CACJ,CAAC;QACF,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACxF,CAAC;CACJ;AArBD,8CAqBC;AAED,iGAAiG;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,2BAA2B,CAoCvC","sourcesContent":["import { FirstPathMatch, PathMatchCandidate } from '@webpieces/rules-config';\n/**\n * `required-type-suffix` (#1037) — a type's name says which layer it belongs to.\n *\n * Configured as a list of entries, each pairing path globs with the suffixes allowed there:\n *\n * { \"paths\": [\"libraries/apis/internal/**\"], \"suffixes\": [\"Request\", \"Response\", \"Event\", \"Dto\", \"Api\"] }\n * { \"paths\": [\"libraries/browser-node/fs-*-model/**\"], \"suffixes\": [\"Fs\"] }\n *\n * Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under\n * an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the\n * suffix alone is not a name (`FooDto` passes; `FooDTO` and `Dto` fail). A non-exported, file-local type\n * is not judged, and neither is an exported `const` (a DI token's `Symbol` holder is not a type). A type\n * exported through a local `export { Foo as FooDto }` list is judged by the name it is exported AS.\n *\n * Why: in review a `…Dto` is a wire type and a `…Fs` a Firestore document, while `TopNamePlaceInput` reads\n * the same as a server-internal or vendor type. The suffix is the one place the layer can be stated.\n *\n * Overlapping entries: the FIRST entry in config order whose paths match governs a file\n * ({@link SuffixEntryPicker}), so a narrower entry must be listed before a broader one; suffixes are never\n * unioned across entries.\n *\n * Under NEW_AND_MODIFIED_CODE only a declaration whose NAME line is new or changed is judged — a new type\n * or a renamed one — so legacy names are grandfathered and a repo with hundreds of them can convert slowly.\n */\n\nimport { DiffScope, matchesAnyGlob } from '@webpieces/rules-config';\nimport {\n RequiredTypeSuffixConfig,\n RequiredTypeSuffixEntry,\n} from './configs/required-type-suffix-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';\nimport { ScanScope } from './scan-scope';\n\n/** The entry that governs a file, and the glob of it that matched — named in every failure. Data-only. */\nexport class GoverningGlob {\n constructor(\n readonly entry: RequiredTypeSuffixEntry,\n readonly glob: string,\n ) {}\n}\n\n/**\n * Picks the ONE entry that governs a file: the FIRST entry, in config order, with a glob matching the\n * file. Order matters — to give a narrower directory stricter suffixes, list its entry ABOVE the broader\n * one; listed below, it never applies to the files the broader entry already covers.\n */\nexport class SuffixEntryPicker {\n entryFor(\n relFile: string,\n entries: readonly RequiredTypeSuffixEntry[],\n ): RequiredTypeSuffixEntry | undefined {\n return this.winner(relFile, entries)?.entry;\n }\n\n /** The first matching entry (and its matching glob) for `relFile`, or undefined when no entry covers it. */\n winner(\n relFile: string,\n entries: readonly RequiredTypeSuffixEntry[],\n ): GoverningGlob | undefined {\n const match = new FirstPathMatch().winner(\n relFile,\n entries.map(\n (entry: RequiredTypeSuffixEntry) => new PathMatchCandidate(entry.paths, entry),\n ),\n );\n return match === undefined ? undefined : new GoverningGlob(match.entry, match.glob);\n }\n}\n\n/** The rename a failure suggests: the name's layer-less tail swapped for each allowed suffix. */\nexport class SuffixRename {\n /**\n * Trailing words that name no layer, dropped before a suffix is appended (`TopNamePlaceInput` →\n * `TopNamePlaceDto`, not `TopNamePlaceInputDto`). Longest first, so `Object` wins over `Obj`.\n */\n private static readonly LAYERLESS_TAILS: readonly string[] = [\n 'Interface',\n 'Payload',\n 'Options',\n 'Object',\n 'Params',\n 'Output',\n 'Option',\n 'Record',\n 'Input',\n 'Model',\n 'Entry',\n 'Shape',\n 'Data',\n 'Info',\n 'Item',\n 'Type',\n 'Body',\n 'Row',\n 'Obj',\n ];\n\n /** Candidate names, one per allowed suffix, in the configured order. */\n candidates(name: string, suffixes: readonly string[]): string[] {\n const stem = this.stem(name, suffixes);\n return suffixes.map((suffix: string) => `${stem}${suffix}`);\n }\n\n private stem(name: string, suffixes: readonly string[]): string {\n // `FooDTO` → `Foo`: the suffix is there, in the wrong case.\n const wrongCase = suffixes.find(\n (s: string) => name.length > s.length && name.toLowerCase().endsWith(s.toLowerCase()),\n );\n if (wrongCase !== undefined) return name.slice(0, name.length - wrongCase.length);\n // `Dto` alone → `<Name>Dto`: there is no stem to keep.\n if (suffixes.includes(name)) return '<Name>';\n const tail = SuffixRename.LAYERLESS_TAILS.find(\n (t: string) => name.length > t.length && name.endsWith(t),\n );\n return tail === undefined ? name : name.slice(0, name.length - tail.length);\n }\n}\n\n/** Finds every exported type in one parsed file whose name does not end in the governing entry's suffixes. */\nexport class ExportedTypeScanner {\n private readonly rename = new SuffixRename();\n\n scan(file: ApiLibFile, entry: RequiredTypeSuffixEntry, glob: string): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n const locals = new Map<string, ts.DeclarationStatement>();\n for (const statement of file.source.statements) {\n const declared = this.typeDeclaration(statement);\n if (declared === undefined) continue;\n if (this.isExported(declared)) {\n const site = this.judge(\n file,\n declared,\n declared.name,\n declared.name?.getText(file.source) ?? '',\n entry,\n glob,\n );\n if (site !== undefined) sites.push(site);\n } else if (declared.name !== undefined) {\n locals.set(declared.name.getText(file.source), declared);\n }\n }\n sites.push(...this.exportListSites(file, locals, entry, glob));\n return sites.sort((a: ApiLibSite, b: ApiLibSite) => a.line - b.line);\n }\n\n /** `export { Local as Exported }` of a local type: judged by the exported name, at the specifier. */\n private exportListSites(\n file: ApiLibFile,\n locals: ReadonlyMap<string, ts.DeclarationStatement>,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n for (const statement of file.source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier !== undefined)\n continue;\n if (statement.exportClause === undefined || !ts.isNamedExports(statement.exportClause))\n continue;\n for (const element of statement.exportClause.elements) {\n const local = locals.get(\n (element.propertyName ?? element.name).getText(file.source),\n );\n if (local === undefined) continue;\n const site = this.judge(\n file,\n local,\n element.name,\n element.name.getText(file.source),\n entry,\n glob,\n );\n if (site !== undefined) sites.push(site);\n }\n }\n return sites;\n }\n\n private typeDeclaration(statement: ts.Statement): ts.DeclarationStatement | undefined {\n if (\n ts.isInterfaceDeclaration(statement) ||\n ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement) ||\n ts.isClassDeclaration(statement)\n ) {\n return statement;\n }\n return undefined;\n }\n\n private isExported(statement: ts.DeclarationStatement): boolean {\n const modifiers = ts.canHaveModifiers(statement) ? (ts.getModifiers(statement) ?? []) : [];\n return modifiers.some((m: ts.ModifierLike) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n\n private judge(\n file: ApiLibFile,\n declared: ts.DeclarationStatement,\n at: ts.Node | undefined,\n name: string,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite | undefined {\n // `export default class { … }` has no name to judge.\n if (at === undefined || name === '') return undefined;\n if (\n entry.suffixes.some(\n (suffix: string) => name.length > suffix.length && name.endsWith(suffix),\n )\n )\n return undefined;\n const kind = this.kindOf(declared);\n const allowed = entry.suffixes.join(' | ');\n const line = file.lineOf(at);\n const snippet = (file.source.text.split('\\n')[line - 1] ?? name)\n .replace(/\\s+/g, ' ')\n .trim();\n const what = `exported ${kind} \\`${name}\\` does not end in a suffix allowed under ${glob} (${allowed})`;\n const candidates = this.rename.candidates(name, entry.suffixes);\n const others = candidates\n .slice(1)\n .map((c: string) => `\\`${c}\\``)\n .join(' / ');\n const cure =\n `rename ${kind} \\`${name}\\` → \\`${candidates[0]}\\`` +\n (others === ''\n ? ''\n : ` (or ${others} — pick the suffix that names its layer, e.g. …Request for an endpoint body)`) +\n ` and update every reference. Allowed suffixes under ${glob}: ${allowed} — the suffix tells a reader ` +\n `which layer the type belongs to.`;\n return new ApiLibSite(line, snippet, what, cure);\n }\n\n private kindOf(declared: ts.DeclarationStatement): string {\n if (ts.isInterfaceDeclaration(declared)) return 'interface';\n if (ts.isEnumDeclaration(declared)) return 'enum';\n if (ts.isTypeAliasDeclaration(declared)) return 'type';\n return 'class';\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class RequiredTypeSuffixValidator extends ApiLibSourceRule<RequiredTypeSuffixConfig> {\n private readonly picker = new SuffixEntryPicker();\n private readonly scanner = new ExportedTypeScanner();\n\n constructor(\n config: RequiredTypeSuffixConfig,\n roleResolver: ProjectRoleResolver,\n diffScope: DiffScope,\n scanScope: ScanScope,\n ) {\n super(config, 'required-type-suffix', roleResolver, diffScope, scanScope);\n }\n\n protected sitesIn(file: ApiLibFile): ApiLibSite[] {\n const winner = this.picker.winner(file.relFile, this.config.entries);\n if (winner === undefined) return [];\n return this.scanner.scan(file, winner.entry, winner.glob);\n }\n\n /** Scoped by the configured entries' `paths` globs, not the role tag. */\n protected override isApiLibrarySource(_workspaceRoot: string, relFile: string): boolean {\n return this.picker.entryFor(relFile, this.config.entries) !== undefined;\n }\n\n protected override scopeLabel(): string {\n const paths = this.config.entries.flatMap((entry: RequiredTypeSuffixEntry) => entry.paths);\n return `a directory required-type-suffix governs (${paths.join(', ')})`;\n }\n\n protected why(): string {\n return (\n \"every exported interface / class / enum / type there must end in one of its path's allowed suffixes — \" +\n 'the suffix tells a reader which layer a type belongs to (a …Dto is on the wire, a …Fs is a Firestore ' +\n 'document), where an unsuffixed name reads the same as a server-internal or vendor type.'\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validate-required-type-suffix.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-required-type-suffix.ts"],"names":[],"mappings":";;;;AAAA,0DAA6E;AAC7E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,0DAAoE;AACpE,uFAG+C;AAC/C,yCAA2D;AAC3D,uDAAiC;AACjC,+DAAiF;AACjF,mEAA8D;AAC9D,6CAAyC;AAEzC,0GAA0G;AAC1G,MAAa,aAAa;IAET;IACA;IAFb,YACa,KAA8B,EAC9B,IAAY;QADZ,UAAK,GAAL,KAAK,CAAyB;QAC9B,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AALD,sCAKC;AAED;;;;GAIG;AACH,MAAa,iBAAiB;IAC1B,QAAQ,CACJ,OAAe,EACf,OAA2C;QAE3C,OAAO,IAAI,CAAC,MAAM,C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C,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;IAC5E,CAAC;IAEkB,UAAU;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3F,OAAO,6CAA6C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAC5E,CAAC;IAES,GAAG;QACT,OAAO,CACH,wGAAwG;YACxG,uGAAuG;YACvG,yFAAyF,CAC5F,CAAC;IACN,CAAC;CACJ,CAAA;AApCY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAMzB,sDAAwB;QAClB,2CAAmB;QACtB,wBAAS;QACT,sBAAS;GARf,2BAA2B,CAoCvC","sourcesContent":["import { FirstPathMatch, PathMatchCandidate } from '@webpieces/rules-config';\n/**\n * `required-type-suffix` (#1037) — a type's name says which layer it belongs to.\n *\n * Configured as a list of entries, each pairing path globs with allowed suffixes and an explicit exemption:\n * `exempt: true` skips suffix enforcement for the matching entry; `exempt: false` enforces its suffixes.\n *\n * { \"paths\": [\"libraries/apis/internal/**\"], \"suffixes\": [\"Request\", \"Response\", \"Event\", \"Dto\", \"Api\"], \"exempt\": false }\n * { \"paths\": [\"libraries/browser-node/fs-*-model/**\"], \"suffixes\": [\"Fs\"], \"exempt\": false }\n *\n * Every EXPORTED `interface`, `class` (abstract too), `enum` and `type` alias in a non-test `.ts` file under\n * an entry's paths must end in one of that entry's suffixes — a plain, case-sensitive `endsWith`, and the\n * suffix alone is not a name (`FooDto` passes; `FooDTO` and `Dto` fail). A non-exported, file-local type\n * is not judged, and neither is an exported `const` (a DI token's `Symbol` holder is not a type). A type\n * exported through a local `export { Foo as FooDto }` list is judged by the name it is exported AS.\n *\n * Why: in review a `…Dto` is a wire type and a `…Fs` a Firestore document, while `TopNamePlaceInput` reads\n * the same as a server-internal or vendor type. The suffix is the one place the layer can be stated.\n *\n * Overlapping entries: the FIRST entry in config order whose paths match governs a file\n * ({@link SuffixEntryPicker}), so a narrower entry must be listed before a broader one; suffixes are never\n * unioned across entries.\n *\n * Under NEW_AND_MODIFIED_CODE only a declaration whose NAME line is new or changed is judged — a new type\n * or a renamed one — so legacy names are grandfathered and a repo with hundreds of them can convert slowly.\n */\n\nimport { DiffScope, matchesAnyGlob } from '@webpieces/rules-config';\nimport {\n RequiredTypeSuffixConfig,\n RequiredTypeSuffixEntry,\n} from './configs/required-type-suffix-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';\nimport { ScanScope } from './scan-scope';\n\n/** The entry that governs a file, and the glob of it that matched — named in every failure. Data-only. */\nexport class GoverningGlob {\n constructor(\n readonly entry: RequiredTypeSuffixEntry,\n readonly glob: string,\n ) {}\n}\n\n/**\n * Picks the ONE entry that governs a file: the FIRST entry, in config order, with a glob matching the\n * file. Order matters — to give a narrower directory stricter suffixes, list its entry ABOVE the broader\n * one; listed below, it never applies to the files the broader entry already covers.\n */\nexport class SuffixEntryPicker {\n entryFor(\n relFile: string,\n entries: readonly RequiredTypeSuffixEntry[],\n ): RequiredTypeSuffixEntry | undefined {\n return this.winner(relFile, entries)?.entry;\n }\n\n /** The first matching entry (and its matching glob) for `relFile`, or undefined when no entry covers it. */\n winner(\n relFile: string,\n entries: readonly RequiredTypeSuffixEntry[],\n ): GoverningGlob | undefined {\n const match = new FirstPathMatch().winner(\n relFile,\n entries.map(\n (entry: RequiredTypeSuffixEntry) => new PathMatchCandidate(entry.paths, entry),\n ),\n );\n return match === undefined ? undefined : new GoverningGlob(match.entry, match.glob);\n }\n}\n\n/** The rename a failure suggests: the name's layer-less tail swapped for each allowed suffix. */\nexport class SuffixRename {\n /**\n * Trailing words that name no layer, dropped before a suffix is appended (`TopNamePlaceInput` →\n * `TopNamePlaceDto`, not `TopNamePlaceInputDto`). Longest first, so `Object` wins over `Obj`.\n */\n private static readonly LAYERLESS_TAILS: readonly string[] = [\n 'Interface',\n 'Payload',\n 'Options',\n 'Object',\n 'Params',\n 'Output',\n 'Option',\n 'Record',\n 'Input',\n 'Model',\n 'Entry',\n 'Shape',\n 'Data',\n 'Info',\n 'Item',\n 'Type',\n 'Body',\n 'Row',\n 'Obj',\n ];\n\n /** Candidate names, one per allowed suffix, in the configured order. */\n candidates(name: string, suffixes: readonly string[]): string[] {\n const stem = this.stem(name, suffixes);\n return suffixes.map((suffix: string) => `${stem}${suffix}`);\n }\n\n private stem(name: string, suffixes: readonly string[]): string {\n // `FooDTO` → `Foo`: the suffix is there, in the wrong case.\n const wrongCase = suffixes.find(\n (s: string) => name.length > s.length && name.toLowerCase().endsWith(s.toLowerCase()),\n );\n if (wrongCase !== undefined) return name.slice(0, name.length - wrongCase.length);\n // `Dto` alone → `<Name>Dto`: there is no stem to keep.\n if (suffixes.includes(name)) return '<Name>';\n const tail = SuffixRename.LAYERLESS_TAILS.find(\n (t: string) => name.length > t.length && name.endsWith(t),\n );\n return tail === undefined ? name : name.slice(0, name.length - tail.length);\n }\n}\n\n/** Finds every exported type in one parsed file whose name does not end in the governing entry's suffixes. */\nexport class ExportedTypeScanner {\n private readonly rename = new SuffixRename();\n\n scan(file: ApiLibFile, entry: RequiredTypeSuffixEntry, glob: string): ApiLibSite[] {\n if (entry.exempt) return [];\n const sites: ApiLibSite[] = [];\n const locals = new Map<string, ts.DeclarationStatement>();\n for (const statement of file.source.statements) {\n const declared = this.typeDeclaration(statement);\n if (declared === undefined) continue;\n if (this.isExported(declared)) {\n const site = this.judge(\n file,\n declared,\n declared.name,\n declared.name?.getText(file.source) ?? '',\n entry,\n glob,\n );\n if (site !== undefined) sites.push(site);\n } else if (declared.name !== undefined) {\n locals.set(declared.name.getText(file.source), declared);\n }\n }\n sites.push(...this.exportListSites(file, locals, entry, glob));\n return sites.sort((a: ApiLibSite, b: ApiLibSite) => a.line - b.line);\n }\n\n /** `export { Local as Exported }` of a local type: judged by the exported name, at the specifier. */\n private exportListSites(\n file: ApiLibFile,\n locals: ReadonlyMap<string, ts.DeclarationStatement>,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite[] {\n const sites: ApiLibSite[] = [];\n for (const statement of file.source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier !== undefined)\n continue;\n if (statement.exportClause === undefined || !ts.isNamedExports(statement.exportClause))\n continue;\n for (const element of statement.exportClause.elements) {\n const local = locals.get(\n (element.propertyName ?? element.name).getText(file.source),\n );\n if (local === undefined) continue;\n const site = this.judge(\n file,\n local,\n element.name,\n element.name.getText(file.source),\n entry,\n glob,\n );\n if (site !== undefined) sites.push(site);\n }\n }\n return sites;\n }\n\n private typeDeclaration(statement: ts.Statement): ts.DeclarationStatement | undefined {\n if (\n ts.isInterfaceDeclaration(statement) ||\n ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement) ||\n ts.isClassDeclaration(statement)\n ) {\n return statement;\n }\n return undefined;\n }\n\n private isExported(statement: ts.DeclarationStatement): boolean {\n const modifiers = ts.canHaveModifiers(statement) ? (ts.getModifiers(statement) ?? []) : [];\n return modifiers.some((m: ts.ModifierLike) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n\n private judge(\n file: ApiLibFile,\n declared: ts.DeclarationStatement,\n at: ts.Node | undefined,\n name: string,\n entry: RequiredTypeSuffixEntry,\n glob: string,\n ): ApiLibSite | undefined {\n // `export default class { … }` has no name to judge.\n if (at === undefined || name === '') return undefined;\n if (\n entry.suffixes.some(\n (suffix: string) => name.length > suffix.length && name.endsWith(suffix),\n )\n )\n return undefined;\n const kind = this.kindOf(declared);\n const allowed = entry.suffixes.join(' | ');\n const line = file.lineOf(at);\n const snippet = (file.source.text.split('\\n')[line - 1] ?? name)\n .replace(/\\s+/g, ' ')\n .trim();\n const what = `exported ${kind} \\`${name}\\` does not end in a suffix allowed under ${glob} (${allowed})`;\n const candidates = this.rename.candidates(name, entry.suffixes);\n const others = candidates\n .slice(1)\n .map((c: string) => `\\`${c}\\``)\n .join(' / ');\n const cure =\n `rename ${kind} \\`${name}\\` → \\`${candidates[0]}\\`` +\n (others === ''\n ? ''\n : ` (or ${others} — pick the suffix that names its layer, e.g. …Request for an endpoint body)`) +\n ` and update every reference. Allowed suffixes under ${glob}: ${allowed} — the suffix tells a reader ` +\n `which layer the type belongs to.`;\n return new ApiLibSite(line, snippet, what, cure);\n }\n\n private kindOf(declared: ts.DeclarationStatement): string {\n if (ts.isInterfaceDeclaration(declared)) return 'interface';\n if (ts.isEnumDeclaration(declared)) return 'enum';\n if (ts.isTypeAliasDeclaration(declared)) return 'type';\n return 'class';\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class RequiredTypeSuffixValidator extends ApiLibSourceRule<RequiredTypeSuffixConfig> {\n private readonly picker = new SuffixEntryPicker();\n private readonly scanner = new ExportedTypeScanner();\n\n constructor(\n config: RequiredTypeSuffixConfig,\n roleResolver: ProjectRoleResolver,\n diffScope: DiffScope,\n scanScope: ScanScope,\n ) {\n super(config, 'required-type-suffix', roleResolver, diffScope, scanScope);\n }\n\n protected sitesIn(file: ApiLibFile): ApiLibSite[] {\n const winner = this.picker.winner(file.relFile, this.config.entries);\n if (winner === undefined) return [];\n return this.scanner.scan(file, winner.entry, winner.glob);\n }\n\n /** Scoped by the configured entries' `paths` globs, not the role tag. */\n protected override isApiLibrarySource(_workspaceRoot: string, relFile: string): boolean {\n return this.picker.entryFor(relFile, this.config.entries) !== undefined;\n }\n\n protected override scopeLabel(): string {\n const paths = this.config.entries.flatMap((entry: RequiredTypeSuffixEntry) => entry.paths);\n return `a directory required-type-suffix governs (${paths.join(', ')})`;\n }\n\n protected why(): string {\n return (\n \"every exported interface / class / enum / type there must end in one of its path's allowed suffixes — \" +\n 'the suffix tells a reader which layer a type belongs to (a …Dto is on the wire, a …Fs is a Firestore ' +\n 'document), where an unsuffixed name reads the same as a server-internal or vendor type.'\n );\n }\n}\n"]}
|