@webpieces/rules-config 0.4.814 → 0.4.815
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 +1 -1
- package/src/api-lib-spelling-configs.d.ts +3 -2
- package/src/api-lib-spelling-configs.js +3 -2
- package/src/api-lib-spelling-configs.js.map +1 -1
- package/src/diff-scope.d.ts +34 -5
- package/src/diff-scope.js +72 -7
- package/src/diff-scope.js.map +1 -1
- package/src/file-scope.d.ts +79 -0
- package/src/file-scope.js +221 -0
- package/src/file-scope.js.map +1 -0
- package/src/index.d.ts +5 -3
- package/src/index.js +13 -6
- package/src/index.js.map +1 -1
- package/src/no-client-creation-config.js +1 -1
- package/src/no-client-creation-config.js.map +1 -1
- package/src/no-utility-types-config.d.ts +2 -1
- package/src/no-utility-types-config.js +2 -1
- package/src/no-utility-types-config.js.map +1 -1
- package/src/rule-configs.d.ts +14 -10
- package/src/rule-configs.js +22 -15
- package/src/rule-configs.js.map +1 -1
- package/src/rule-schemas.d.ts +6 -0
- package/src/rule-schemas.js +10 -0
- package/src/rule-schemas.js.map +1 -1
- package/src/seed-entry.js +9 -4
- package/src/seed-entry.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/rules-config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.815",
|
|
4
4
|
"description": "Shared webpieces.config.json loader. Single source of truth for validation rule configuration consumed by @webpieces/ai-hook-rules, @webpieces/code-rules, and @webpieces/nx-webpieces-rules.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,7 +8,8 @@ import { BaseRuleConfig, ModifiedCodeMode } from './rule-configs';
|
|
|
8
8
|
*
|
|
9
9
|
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
|
|
10
10
|
* NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
|
|
11
|
-
* occurrence in a changed file)
|
|
11
|
+
* occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in each touched
|
|
12
|
+
* project / the whole repo — #1027). `allowedPaths` exempts whole trees. The per-site escape hatch is
|
|
12
13
|
* `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
|
|
13
14
|
*/
|
|
14
15
|
export declare class NoInlineImportInApiLibConfig extends BaseRuleConfig {
|
|
@@ -29,7 +30,7 @@ export declare class NoInlineImportInApiLibConfig extends BaseRuleConfig {
|
|
|
29
30
|
* The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's
|
|
30
31
|
* mode grandfathers. This rule is what forbids NEW ones in an api library.
|
|
31
32
|
*
|
|
32
|
-
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same
|
|
33
|
+
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same five
|
|
33
34
|
* values as above; `allowedPaths` and the per-site disable work the same way.
|
|
34
35
|
*/
|
|
35
36
|
export declare class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {
|
|
@@ -11,7 +11,8 @@ const rule_configs_1 = require("./rule-configs");
|
|
|
11
11
|
*
|
|
12
12
|
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
|
|
13
13
|
* NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
|
|
14
|
-
* occurrence in a changed file)
|
|
14
|
+
* occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in each touched
|
|
15
|
+
* project / the whole repo — #1027). `allowedPaths` exempts whole trees. The per-site escape hatch is
|
|
15
16
|
* `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
|
|
16
17
|
*/
|
|
17
18
|
class NoInlineImportInApiLibConfig extends rule_configs_1.BaseRuleConfig {
|
|
@@ -36,7 +37,7 @@ exports.NoInlineImportInApiLibConfig = NoInlineImportInApiLibConfig;
|
|
|
36
37
|
* The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's
|
|
37
38
|
* mode grandfathers. This rule is what forbids NEW ones in an api library.
|
|
38
39
|
*
|
|
39
|
-
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same
|
|
40
|
+
* `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same five
|
|
40
41
|
* values as above; `allowedPaths` and the per-site disable work the same way.
|
|
41
42
|
*/
|
|
42
43
|
class OneEnumSpellingInApiLibConfig extends rule_configs_1.BaseRuleConfig {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-lib-spelling-configs.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/api-lib-spelling-configs.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AACpD,iDAAyG;AAEzG
|
|
1
|
+
{"version":3,"file":"api-lib-spelling-configs.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/api-lib-spelling-configs.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AACpD,iDAAyG;AAEzG;;;;;;;;;;;GAWG;AACH,MAAa,4BAA6B,SAAQ,6BAAc;IAE5D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA8C;QAChE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,kCAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,+BAAgB;KACtB,CAAC;;AARN,oEASC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,6BAA8B,SAAQ,6BAAc;IAE7D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA+C;QACjE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,kCAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,+BAAgB;KACtB,CAAC;;AARN,sEASC","sourcesContent":["import { FieldDef, SchemaShape } from './field-def';\nimport { BaseRuleConfig, BASE_RULE_SCHEMA, ModifiedCodeMode, MODIFIED_CODE_MODES } from './rule-configs';\n\n/**\n * `no-inline-import-in-api-lib` (#1023) — in every `role:api-lib` project, refuse an `import('…')`\n * TYPE node (`activeAiProvider?: import('@myorg/company-core').AiProvider`) and a dynamic `import()`\n * EXPRESSION. An API imports at the top of the file, only: an inline import hides a cross-library\n * dependency from every reader of the contract and from the tools that read its imports.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |\n * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every\n * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in each touched\n * project / the whole repo — #1027). `allowedPaths` exempts whole trees. The per-site escape hatch is\n * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.\n */\nexport class NoInlineImportInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<NoInlineImportInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n\n/**\n * `one-enum-spelling-in-api-lib` (#1023) — in every `role:api-lib` project, a fixed set of string\n * values has ONE spelling: a string `enum` whose every member is explicitly initialised with a string\n * literal (`export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }`), used as the enum, one\n * member of it, or a union of its members. Refused, each with a cure that prints the enum to write:\n * a string-literal union of two or more members (in a type alias, a field or a parameter),\n * `(typeof X)[number]`, `keyof typeof X`, a single string-literal type used as a union discriminator,\n * and a numeric, heterogeneous, `const` or non-initialised enum (a numeric enum puts numbers on the\n * wire).\n *\n * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's\n * mode grandfathers. This rule is what forbids NEW ones in an api library.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same five\n * values as above; `allowedPaths` and the per-site disable work the same way.\n */\nexport class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<OneEnumSpellingInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}
|
package/src/diff-scope.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting
|
|
7
7
|
* {@link DiffScope} over follow-up PRs, then the delegators are removed.
|
|
8
8
|
*/
|
|
9
|
+
import { FileScope } from './file-scope';
|
|
9
10
|
/** A git diff range: the base ref to compare against and an optional head (else the working tree). */
|
|
10
11
|
export declare class DiffRange {
|
|
11
12
|
base?: string;
|
|
@@ -26,18 +27,46 @@ export declare class ChangedFilesOptions {
|
|
|
26
27
|
includeDeletions?: boolean;
|
|
27
28
|
}
|
|
28
29
|
export declare class DiffScope {
|
|
29
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The {@link FileScope} the current async call chain runs inside. AsyncLocalStorage rather than a
|
|
32
|
+
* field, because the free-function delegators below and every injected instance must see the SAME
|
|
33
|
+
* scope, and because the scope must never leak past the one rule run that set it.
|
|
34
|
+
*/
|
|
35
|
+
private static readonly active;
|
|
36
|
+
/**
|
|
37
|
+
* Run `work` with every getChangedFiles / getFileDiff call inside it answering for `scope` — the
|
|
38
|
+
* one switch the whole-scope modes (#1027) and the debug run's `--projects` are built on.
|
|
39
|
+
*/
|
|
40
|
+
within<T>(scope: FileScope, work: () => Promise<T>): Promise<T>;
|
|
41
|
+
/** The scope the caller is running inside; plain DIFF outside any {@link within}. */
|
|
42
|
+
currentScope(): FileScope;
|
|
43
|
+
/**
|
|
44
|
+
* Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. Under
|
|
45
|
+
* RUN_EVERY_TIME the base is irrelevant to the file set, so an undetectable one falls back to HEAD
|
|
46
|
+
* rather than making the rule skip.
|
|
47
|
+
*/
|
|
30
48
|
detectBase(workspaceRoot: string): string | null;
|
|
49
|
+
private detectMergeBase;
|
|
31
50
|
/** Resolve the diff range a rule should compare against (honors nx's NX_BASE / NX_HEAD). */
|
|
32
51
|
resolveBase(workspaceRoot: string): DiffRange;
|
|
33
52
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
53
|
+
* The files a rule judges. Outside any {@link within} (and for the gate's plain diff scope) these are
|
|
54
|
+
* the changed files between base and head (or base→working-tree when head is omitted), untracked
|
|
55
|
+
* files unioned in for the working-tree case. Inside a widened {@link FileScope} they are the files
|
|
56
|
+
* that scope selects — see file-scope.ts. `tsOnly` (default true) restricts to *.ts/*.tsx and drops
|
|
57
|
+
* test files, in every scope. Deletions are excluded (`--diff-filter=d`).
|
|
37
58
|
*/
|
|
38
59
|
getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[];
|
|
39
|
-
|
|
60
|
+
private everyChangedFile;
|
|
61
|
+
private diffFiles;
|
|
62
|
+
/**
|
|
63
|
+
* Diff content for a single file (synthetic all-added diff for an untracked file with no head). Inside
|
|
64
|
+
* a whole-scope {@link FileScope} every file is judged WHOLE, so the diff is the synthetic all-added
|
|
65
|
+
* one for every file — a line- or method-scoped rule then sees the entire file as new.
|
|
66
|
+
*/
|
|
40
67
|
getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string;
|
|
68
|
+
private allAddedDiff;
|
|
69
|
+
private realFileDiff;
|
|
41
70
|
/** Added/changed line numbers (the `+` lines per hunk) — basis of NEW_AND_MODIFIED_CODE scoping. */
|
|
42
71
|
getChangedLineNumbers(diffContent: string): Set<number>;
|
|
43
72
|
/** Method names whose signature line is a `+` addition in the diff — the basis of "NEW" methods. */
|
package/src/diff-scope.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting
|
|
8
8
|
* {@link DiffScope} over follow-up PRs, then the delegators are removed.
|
|
9
9
|
*/
|
|
10
|
+
var DiffScope_1;
|
|
10
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
12
|
exports.DiffScope = exports.ChangedFilesOptions = exports.DiffRange = void 0;
|
|
12
13
|
exports.detectBase = detectBase;
|
|
@@ -18,10 +19,12 @@ exports.findNewMethodSignaturesInDiff = findNewMethodSignaturesInDiff;
|
|
|
18
19
|
exports.hasChangesInRange = hasChangesInRange;
|
|
19
20
|
exports.isNewOrModified = isNewOrModified;
|
|
20
21
|
const tslib_1 = require("tslib");
|
|
22
|
+
const async_hooks_1 = require("async_hooks");
|
|
21
23
|
const child_process_1 = require("child_process");
|
|
22
24
|
const fs = tslib_1.__importStar(require("fs"));
|
|
23
25
|
const path = tslib_1.__importStar(require("path"));
|
|
24
26
|
const inversify_1 = require("inversify");
|
|
27
|
+
const file_scope_1 = require("./file-scope");
|
|
25
28
|
const to_error_1 = require("./to-error");
|
|
26
29
|
/** A git diff range: the base ref to compare against and an optional head (else the working tree). */
|
|
27
30
|
class DiffRange {
|
|
@@ -45,8 +48,36 @@ class ChangedFilesOptions {
|
|
|
45
48
|
}
|
|
46
49
|
exports.ChangedFilesOptions = ChangedFilesOptions;
|
|
47
50
|
let DiffScope = class DiffScope {
|
|
48
|
-
|
|
51
|
+
static { DiffScope_1 = this; }
|
|
52
|
+
/**
|
|
53
|
+
* The {@link FileScope} the current async call chain runs inside. AsyncLocalStorage rather than a
|
|
54
|
+
* field, because the free-function delegators below and every injected instance must see the SAME
|
|
55
|
+
* scope, and because the scope must never leak past the one rule run that set it.
|
|
56
|
+
*/
|
|
57
|
+
static active = new async_hooks_1.AsyncLocalStorage();
|
|
58
|
+
/**
|
|
59
|
+
* Run `work` with every getChangedFiles / getFileDiff call inside it answering for `scope` — the
|
|
60
|
+
* one switch the whole-scope modes (#1027) and the debug run's `--projects` are built on.
|
|
61
|
+
*/
|
|
62
|
+
within(scope, work) {
|
|
63
|
+
return DiffScope_1.active.run(scope, work);
|
|
64
|
+
}
|
|
65
|
+
/** The scope the caller is running inside; plain DIFF outside any {@link within}. */
|
|
66
|
+
currentScope() {
|
|
67
|
+
return DiffScope_1.active.getStore() ?? file_scope_1.FileScope.DIFF;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. Under
|
|
71
|
+
* RUN_EVERY_TIME the base is irrelevant to the file set, so an undetectable one falls back to HEAD
|
|
72
|
+
* rather than making the rule skip.
|
|
73
|
+
*/
|
|
49
74
|
detectBase(workspaceRoot) {
|
|
75
|
+
const detected = this.detectMergeBase(workspaceRoot);
|
|
76
|
+
if (detected === null && this.currentScope().kind === 'RUN_EVERY_TIME')
|
|
77
|
+
return 'HEAD';
|
|
78
|
+
return detected;
|
|
79
|
+
}
|
|
80
|
+
detectMergeBase(workspaceRoot) {
|
|
50
81
|
for (const ref of ['origin/main', 'main']) {
|
|
51
82
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
52
83
|
try {
|
|
@@ -74,12 +105,29 @@ let DiffScope = class DiffScope {
|
|
|
74
105
|
return range;
|
|
75
106
|
}
|
|
76
107
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
108
|
+
* The files a rule judges. Outside any {@link within} (and for the gate's plain diff scope) these are
|
|
109
|
+
* the changed files between base and head (or base→working-tree when head is omitted), untracked
|
|
110
|
+
* files unioned in for the working-tree case. Inside a widened {@link FileScope} they are the files
|
|
111
|
+
* that scope selects — see file-scope.ts. `tsOnly` (default true) restricts to *.ts/*.tsx and drops
|
|
112
|
+
* test files, in every scope. Deletions are excluded (`--diff-filter=d`).
|
|
80
113
|
*/
|
|
81
|
-
// webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths
|
|
82
114
|
getChangedFiles(workspaceRoot, base, head, opts) {
|
|
115
|
+
const scope = this.currentScope();
|
|
116
|
+
const diffFiles = this.diffFiles(workspaceRoot, base, head, opts);
|
|
117
|
+
if (scope.isPlainDiff())
|
|
118
|
+
return diffFiles;
|
|
119
|
+
const tsOnly = opts?.tsOnly ?? true;
|
|
120
|
+
return new file_scope_1.ScopedFileSelector().select(workspaceRoot, scope, diffFiles, () => this.diffFiles(workspaceRoot, base, head, this.everyChangedFile()), tsOnly ? ['*.ts', '*.tsx'] : [], (f) => !tsOnly || !this.isTestFile(f));
|
|
121
|
+
}
|
|
122
|
+
// "Which projects did the diff touch" counts ANY changed file — a project.json, a README — not only
|
|
123
|
+
// the files the rule itself judges.
|
|
124
|
+
everyChangedFile() {
|
|
125
|
+
const opts = new ChangedFilesOptions();
|
|
126
|
+
opts.tsOnly = false;
|
|
127
|
+
return opts;
|
|
128
|
+
}
|
|
129
|
+
// webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths
|
|
130
|
+
diffFiles(workspaceRoot, base, head, opts) {
|
|
83
131
|
const tsOnly = opts?.tsOnly ?? true;
|
|
84
132
|
const glob = tsOnly ? " -- '*.ts' '*.tsx'" : '';
|
|
85
133
|
const keep = (f) => f.length > 0 && (!tsOnly || !this.isTestFile(f));
|
|
@@ -119,8 +167,25 @@ let DiffScope = class DiffScope {
|
|
|
119
167
|
return [];
|
|
120
168
|
}
|
|
121
169
|
}
|
|
122
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Diff content for a single file (synthetic all-added diff for an untracked file with no head). Inside
|
|
172
|
+
* a whole-scope {@link FileScope} every file is judged WHOLE, so the diff is the synthetic all-added
|
|
173
|
+
* one for every file — a line- or method-scoped rule then sees the entire file as new.
|
|
174
|
+
*/
|
|
123
175
|
getFileDiff(workspaceRoot, file, base, head) {
|
|
176
|
+
if (this.currentScope().isWhole())
|
|
177
|
+
return this.allAddedDiff(workspaceRoot, file);
|
|
178
|
+
return this.realFileDiff(workspaceRoot, file, base, head);
|
|
179
|
+
}
|
|
180
|
+
allAddedDiff(workspaceRoot, file) {
|
|
181
|
+
const fullPath = path.join(workspaceRoot, file);
|
|
182
|
+
if (!fs.existsSync(fullPath))
|
|
183
|
+
return '';
|
|
184
|
+
const lines = fs.readFileSync(fullPath, 'utf-8').split('\n');
|
|
185
|
+
// A real hunk header, so getChangedLineNumbers numbers the lines from 1 like any git diff.
|
|
186
|
+
return [`@@ -0,0 +1,${lines.length} @@`, ...lines.map((l) => `+${l}`)].join('\n');
|
|
187
|
+
}
|
|
188
|
+
realFileDiff(workspaceRoot, file, base, head) {
|
|
124
189
|
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
125
190
|
try {
|
|
126
191
|
const diffTarget = head ? `${base} ${head}` : base;
|
|
@@ -221,7 +286,7 @@ let DiffScope = class DiffScope {
|
|
|
221
286
|
}
|
|
222
287
|
};
|
|
223
288
|
exports.DiffScope = DiffScope;
|
|
224
|
-
exports.DiffScope = DiffScope = tslib_1.__decorate([
|
|
289
|
+
exports.DiffScope = DiffScope = DiffScope_1 = tslib_1.__decorate([
|
|
225
290
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
|
|
226
291
|
], DiffScope);
|
|
227
292
|
// Temporary migration delegators to DiffScope — removed once consumers inject it.
|
package/src/diff-scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff-scope.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/diff-scope.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAqOH,gCAEC;AAGD,kCAEC;AAGD,0CAEC;AAGD,kCAEC;AAGD,sDAEC;AAGD,sEAEC;AAGD,8CAEC;AAGD,0CAQC;;AA9QD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,yCAAqC;AAErC,sGAAsG;AACtG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,CAAC,eAAe,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,gIAAgI;AAChI,SAAgB,WAAW,CAAC,aAAqB,EAAE,IAAY,EAAE,IAAY,EAAE,IAAa;IACxF,OAAO,YAAY,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACrE,CAAC;AAED,gIAAgI;AAChI,SAAgB,qBAAqB,CAAC,WAAmB;IACrD,OAAO,YAAY,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;AAC3D,CAAC;AAED,gIAAgI;AAChI,SAAgB,6BAA6B,CAAC,WAAmB;IAC7D,OAAO,YAAY,CAAC,6BAA6B,CAAC,WAAW,CAAC,CAAC;AACnE,CAAC;AAED,gIAAgI;AAChI,SAAgB,iBAAiB,CAAC,SAAiB,EAAE,OAAe,EAAE,YAAyB;IAC3F,OAAO,YAAY,CAAC,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAC5E,CAAC;AAED,gIAAgI;AAChI,SAAgB,eAAe,CAC3B,IAAY,EACZ,SAAiB,EACjB,OAAe,EACf,YAAyB,EACzB,cAA2B;IAE3B,OAAO,YAAY,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;AAChG,CAAC","sourcesContent":["/**\n * Shared git-diff + diff-scoping service for ALL rule validators (code-rules) and nx executors\n * (nx-webpieces-rules). Centralized here in rules-config because it is the one package both depend on.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it can be injected and appear in the rules-config DI design. Free-function\n * delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting\n * {@link DiffScope} over follow-up PRs, then the delegators are removed.\n */\n\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { toError } from './to-error';\n\n/** A git diff range: the base ref to compare against and an optional head (else the working tree). */\nexport class DiffRange {\n base?: string;\n head?: string;\n}\n\n/** Options for getChangedFiles. `tsOnly` (default true) restricts to *.ts/*.tsx and drops test files. */\nexport class ChangedFilesOptions {\n tsOnly?: boolean;\n /**\n * Include DELETED files in the result. Default false, which is `--diff-filter=d` — the historical\n * behavior, kept as the default so every existing caller is byte-identical.\n *\n * The default is right for lint validators (you cannot lint a file that is gone) and WRONG for checklist\n * matching: a PR that DELETES a migration, an auth check or a terraform rule changed exactly the thing a\n * checklist exists to catch, and dropping it from the changed-file set means the checklist never fires\n * and no reviewer is ever asked. The review flow sets this true.\n */\n includeDeletions?: boolean;\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class DiffScope {\n /** Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. */\n detectBase(workspaceRoot: string): string | null {\n for (const ref of ['origin/main', 'main']) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const merged = execSync(`git merge-base HEAD ${ref}`, {\n cwd: workspaceRoot, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n if (merged) return merged;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — try the next ref\n }\n }\n return null;\n }\n\n /** Resolve the diff range a rule should compare against (honors nx's NX_BASE / NX_HEAD). */\n resolveBase(workspaceRoot: string): DiffRange {\n const range = new DiffRange();\n range.base = process.env['NX_BASE'];\n range.head = process.env['NX_HEAD'];\n if (!range.base) {\n range.base = this.detectBase(workspaceRoot) ?? undefined;\n }\n return range;\n }\n\n /**\n * Changed files between base and head (or base→working-tree when head is omitted). Untracked files\n * are unioned in for the working-tree case. `tsOnly` (default true) restricts to *.ts/*.tsx and\n * drops test files. Deletions are excluded (`--diff-filter=d`).\n */\n // webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths\n getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n const tsOnly = opts?.tsOnly ?? true;\n const glob = tsOnly ? \" -- '*.ts' '*.tsx'\" : '';\n const keep = (f: string): boolean => f.length > 0 && (!tsOnly || !this.isTestFile(f));\n // Deletions are excluded by default (see ChangedFilesOptions.includeDeletions) — the review flow\n // opts in, every lint validator keeps the historical filter.\n const filter = opts?.includeDeletions === true ? '' : ' --diff-filter=d';\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const output = execSync(`git diff --name-only${filter} ${diffTarget}${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const changedFiles = output.trim().split('\\n').filter(keep);\n\n // Working-tree comparison (no head): also include untracked files, as nx affected does.\n if (!head) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const untrackedOutput = execSync(`git ls-files --others --exclude-standard${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const untrackedFiles = untrackedOutput.trim().split('\\n').filter(keep);\n return Array.from(new Set([...changedFiles, ...untrackedFiles]));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — ls-files failure falls back to the tracked list\n return changedFiles;\n }\n }\n\n return changedFiles;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns an empty list\n return [];\n }\n }\n\n /** Diff content for a single file (synthetic all-added diff for an untracked file with no head). */\n getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const diff = execSync(`git diff ${diffTarget} -- \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n\n if (!diff && !head) {\n const fullPath = path.join(workspaceRoot, file);\n if (fs.existsSync(fullPath)) {\n const isUntracked = execSync(`git ls-files --others --exclude-standard \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n }).trim();\n\n if (isUntracked) {\n const content = fs.readFileSync(fullPath, 'utf-8');\n return content.split('\\n').map((l: string) => `+${l}`).join('\\n');\n }\n }\n }\n\n return diff;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns no diff\n return '';\n }\n }\n\n /** Added/changed line numbers (the `+` lines per hunk) — basis of NEW_AND_MODIFIED_CODE scoping. */\n getChangedLineNumbers(diffContent: string): Set<number> {\n const changedLines = new Set<number>();\n const lines = diffContent.split('\\n');\n let currentLine = 0;\n\n for (const line of lines) {\n const hunkMatch = line.match(/^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@/);\n if (hunkMatch) {\n currentLine = parseInt(hunkMatch[1], 10);\n continue;\n }\n\n if (line.startsWith('+') && !line.startsWith('+++')) {\n changedLines.add(currentLine);\n currentLine++;\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n // Deletions don't advance the new-file line counter.\n } else {\n currentLine++;\n }\n }\n\n return changedLines;\n }\n\n /** Method names whose signature line is a `+` addition in the diff — the basis of \"NEW\" methods. */\n findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n const newMethods = new Set<string>();\n const lines = diffContent.split('\\n');\n\n const patterns = [\n /^\\+\\s*(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s+)?function/,\n /^\\+\\s*(?:(?:public|private|protected)\\s+)?(?:static\\s+)?(?:async\\s+)?(\\w+)\\s*\\(/,\n ];\n\n for (const line of lines) {\n if (line.startsWith('+') && !line.startsWith('+++')) {\n for (const pattern of patterns) {\n const match = line.match(pattern);\n if (match) {\n const methodName = match[1];\n if (methodName && !['if', 'for', 'while', 'switch', 'catch', 'constructor'].includes(methodName)) {\n newMethods.add(methodName);\n }\n break;\n }\n }\n }\n }\n\n return newMethods;\n }\n\n /** True if any line in [startLine, endLine] is in the changedLines set. */\n hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n for (let line = startLine; line <= endLine; line++) {\n if (changedLines.has(line)) {\n return true;\n }\n }\n return false;\n }\n\n /** True if a node (method/function) is newly added or has any changed line in its range. */\n isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n ): boolean {\n if (newMethodNames.has(name)) return true;\n return this.hasChangesInRange(startLine, endLine, changedLines);\n }\n\n // A file is \"a test file\" (excluded from diff-scoped rules) when it is a .spec/.test file or lives\n // under a __tests__/ directory.\n private isTestFile(file: string): boolean {\n return file.includes('.spec.ts') || file.includes('.test.ts') || file.includes('__tests__/');\n }\n}\n\n// Temporary migration delegators to DiffScope — removed once consumers inject it.\nconst diffScopeSvc = new DiffScope();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function detectBase(workspaceRoot: string): string | null {\n return diffScopeSvc.detectBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function resolveBase(workspaceRoot: string): DiffRange {\n return diffScopeSvc.resolveBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n return diffScopeSvc.getChangedFiles(workspaceRoot, base, head, opts);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n return diffScopeSvc.getFileDiff(workspaceRoot, file, base, head);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedLineNumbers(diffContent: string): Set<number> {\n return diffScopeSvc.getChangedLineNumbers(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n return diffScopeSvc.findNewMethodSignaturesInDiff(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n return diffScopeSvc.hasChangesInRange(startLine, endLine, changedLines);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n): boolean {\n return diffScopeSvc.isNewOrModified(name, startLine, endLine, changedLines, newMethodNames);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"diff-scope.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/diff-scope.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;AA+SH,gCAEC;AAGD,kCAEC;AAGD,0CAEC;AAGD,kCAEC;AAGD,sDAEC;AAGD,sEAEC;AAGD,8CAEC;AAGD,0CAQC;;AAxVD,6CAAgD;AAChD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,6CAA6D;AAC7D,yCAAqC;AAErC,sGAAsG;AACtG,MAAa,SAAS;IAClB,IAAI,CAAU;IACd,IAAI,CAAU;CACjB;AAHD,8BAGC;AAED,yGAAyG;AACzG,MAAa,mBAAmB;IAC5B,MAAM,CAAW;IACjB;;;;;;;;OAQG;IACH,gBAAgB,CAAW;CAC9B;AAZD,kDAYC;AAGM,IAAM,SAAS,GAAf,MAAM,SAAS;;IAClB;;;;OAIG;IACK,MAAM,CAAU,MAAM,GAAG,IAAI,+BAAiB,EAAa,CAAC;IAEpE;;;OAGG;IACH,MAAM,CAAI,KAAgB,EAAE,IAAsB;QAC9C,OAAO,WAAS,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;I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AAS,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAC5E,CAAC;AAED,gIAAgI;AAChI,SAAgB,eAAe,CAC3B,IAAY,EACZ,SAAiB,EACjB,OAAe,EACf,YAAyB,EACzB,cAA2B;IAE3B,OAAO,YAAY,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;AAChG,CAAC","sourcesContent":["/**\n * Shared git-diff + diff-scoping service for ALL rule validators (code-rules) and nx executors\n * (nx-webpieces-rules). Centralized here in rules-config because it is the one package both depend on.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it can be injected and appear in the rules-config DI design. Free-function\n * delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting\n * {@link DiffScope} over follow-up PRs, then the delegators are removed.\n */\n\nimport { AsyncLocalStorage } from 'async_hooks';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { FileScope, ScopedFileSelector } from './file-scope';\nimport { toError } from './to-error';\n\n/** A git diff range: the base ref to compare against and an optional head (else the working tree). */\nexport class DiffRange {\n base?: string;\n head?: string;\n}\n\n/** Options for getChangedFiles. `tsOnly` (default true) restricts to *.ts/*.tsx and drops test files. */\nexport class ChangedFilesOptions {\n tsOnly?: boolean;\n /**\n * Include DELETED files in the result. Default false, which is `--diff-filter=d` — the historical\n * behavior, kept as the default so every existing caller is byte-identical.\n *\n * The default is right for lint validators (you cannot lint a file that is gone) and WRONG for checklist\n * matching: a PR that DELETES a migration, an auth check or a terraform rule changed exactly the thing a\n * checklist exists to catch, and dropping it from the changed-file set means the checklist never fires\n * and no reviewer is ever asked. The review flow sets this true.\n */\n includeDeletions?: boolean;\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class DiffScope {\n /**\n * The {@link FileScope} the current async call chain runs inside. AsyncLocalStorage rather than a\n * field, because the free-function delegators below and every injected instance must see the SAME\n * scope, and because the scope must never leak past the one rule run that set it.\n */\n private static readonly active = new AsyncLocalStorage<FileScope>();\n\n /**\n * Run `work` with every getChangedFiles / getFileDiff call inside it answering for `scope` — the\n * one switch the whole-scope modes (#1027) and the debug run's `--projects` are built on.\n */\n within<T>(scope: FileScope, work: () => Promise<T>): Promise<T> {\n return DiffScope.active.run(scope, work);\n }\n\n /** The scope the caller is running inside; plain DIFF outside any {@link within}. */\n currentScope(): FileScope {\n return DiffScope.active.getStore() ?? FileScope.DIFF;\n }\n\n /**\n * Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. Under\n * RUN_EVERY_TIME the base is irrelevant to the file set, so an undetectable one falls back to HEAD\n * rather than making the rule skip.\n */\n detectBase(workspaceRoot: string): string | null {\n const detected = this.detectMergeBase(workspaceRoot);\n if (detected === null && this.currentScope().kind === 'RUN_EVERY_TIME') return 'HEAD';\n return detected;\n }\n\n private detectMergeBase(workspaceRoot: string): string | null {\n for (const ref of ['origin/main', 'main']) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const merged = execSync(`git merge-base HEAD ${ref}`, {\n cwd: workspaceRoot, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n if (merged) return merged;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — try the next ref\n }\n }\n return null;\n }\n\n /** Resolve the diff range a rule should compare against (honors nx's NX_BASE / NX_HEAD). */\n resolveBase(workspaceRoot: string): DiffRange {\n const range = new DiffRange();\n range.base = process.env['NX_BASE'];\n range.head = process.env['NX_HEAD'];\n if (!range.base) {\n range.base = this.detectBase(workspaceRoot) ?? undefined;\n }\n return range;\n }\n\n /**\n * The files a rule judges. Outside any {@link within} (and for the gate's plain diff scope) these are\n * the changed files between base and head (or base→working-tree when head is omitted), untracked\n * files unioned in for the working-tree case. Inside a widened {@link FileScope} they are the files\n * that scope selects — see file-scope.ts. `tsOnly` (default true) restricts to *.ts/*.tsx and drops\n * test files, in every scope. Deletions are excluded (`--diff-filter=d`).\n */\n getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n const scope = this.currentScope();\n const diffFiles = this.diffFiles(workspaceRoot, base, head, opts);\n if (scope.isPlainDiff()) return diffFiles;\n const tsOnly = opts?.tsOnly ?? true;\n return new ScopedFileSelector().select(\n workspaceRoot,\n scope,\n diffFiles,\n () => this.diffFiles(workspaceRoot, base, head, this.everyChangedFile()),\n tsOnly ? ['*.ts', '*.tsx'] : [],\n (f: string) => !tsOnly || !this.isTestFile(f),\n );\n }\n\n // \"Which projects did the diff touch\" counts ANY changed file — a project.json, a README — not only\n // the files the rule itself judges.\n private everyChangedFile(): ChangedFilesOptions {\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n return opts;\n }\n\n // webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths\n private diffFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n const tsOnly = opts?.tsOnly ?? true;\n const glob = tsOnly ? \" -- '*.ts' '*.tsx'\" : '';\n const keep = (f: string): boolean => f.length > 0 && (!tsOnly || !this.isTestFile(f));\n // Deletions are excluded by default (see ChangedFilesOptions.includeDeletions) — the review flow\n // opts in, every lint validator keeps the historical filter.\n const filter = opts?.includeDeletions === true ? '' : ' --diff-filter=d';\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const output = execSync(`git diff --name-only${filter} ${diffTarget}${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const changedFiles = output.trim().split('\\n').filter(keep);\n\n // Working-tree comparison (no head): also include untracked files, as nx affected does.\n if (!head) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const untrackedOutput = execSync(`git ls-files --others --exclude-standard${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const untrackedFiles = untrackedOutput.trim().split('\\n').filter(keep);\n return Array.from(new Set([...changedFiles, ...untrackedFiles]));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — ls-files failure falls back to the tracked list\n return changedFiles;\n }\n }\n\n return changedFiles;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns an empty list\n return [];\n }\n }\n\n /**\n * Diff content for a single file (synthetic all-added diff for an untracked file with no head). Inside\n * a whole-scope {@link FileScope} every file is judged WHOLE, so the diff is the synthetic all-added\n * one for every file — a line- or method-scoped rule then sees the entire file as new.\n */\n getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n if (this.currentScope().isWhole()) return this.allAddedDiff(workspaceRoot, file);\n return this.realFileDiff(workspaceRoot, file, base, head);\n }\n\n private allAddedDiff(workspaceRoot: string, file: string): string {\n const fullPath = path.join(workspaceRoot, file);\n if (!fs.existsSync(fullPath)) return '';\n const lines = fs.readFileSync(fullPath, 'utf-8').split('\\n');\n // A real hunk header, so getChangedLineNumbers numbers the lines from 1 like any git diff.\n return [`@@ -0,0 +1,${lines.length} @@`, ...lines.map((l: string) => `+${l}`)].join('\\n');\n }\n\n private realFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const diff = execSync(`git diff ${diffTarget} -- \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n\n if (!diff && !head) {\n const fullPath = path.join(workspaceRoot, file);\n if (fs.existsSync(fullPath)) {\n const isUntracked = execSync(`git ls-files --others --exclude-standard \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n }).trim();\n\n if (isUntracked) {\n const content = fs.readFileSync(fullPath, 'utf-8');\n return content.split('\\n').map((l: string) => `+${l}`).join('\\n');\n }\n }\n }\n\n return diff;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns no diff\n return '';\n }\n }\n\n /** Added/changed line numbers (the `+` lines per hunk) — basis of NEW_AND_MODIFIED_CODE scoping. */\n getChangedLineNumbers(diffContent: string): Set<number> {\n const changedLines = new Set<number>();\n const lines = diffContent.split('\\n');\n let currentLine = 0;\n\n for (const line of lines) {\n const hunkMatch = line.match(/^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@/);\n if (hunkMatch) {\n currentLine = parseInt(hunkMatch[1], 10);\n continue;\n }\n\n if (line.startsWith('+') && !line.startsWith('+++')) {\n changedLines.add(currentLine);\n currentLine++;\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n // Deletions don't advance the new-file line counter.\n } else {\n currentLine++;\n }\n }\n\n return changedLines;\n }\n\n /** Method names whose signature line is a `+` addition in the diff — the basis of \"NEW\" methods. */\n findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n const newMethods = new Set<string>();\n const lines = diffContent.split('\\n');\n\n const patterns = [\n /^\\+\\s*(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s+)?function/,\n /^\\+\\s*(?:(?:public|private|protected)\\s+)?(?:static\\s+)?(?:async\\s+)?(\\w+)\\s*\\(/,\n ];\n\n for (const line of lines) {\n if (line.startsWith('+') && !line.startsWith('+++')) {\n for (const pattern of patterns) {\n const match = line.match(pattern);\n if (match) {\n const methodName = match[1];\n if (methodName && !['if', 'for', 'while', 'switch', 'catch', 'constructor'].includes(methodName)) {\n newMethods.add(methodName);\n }\n break;\n }\n }\n }\n }\n\n return newMethods;\n }\n\n /** True if any line in [startLine, endLine] is in the changedLines set. */\n hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n for (let line = startLine; line <= endLine; line++) {\n if (changedLines.has(line)) {\n return true;\n }\n }\n return false;\n }\n\n /** True if a node (method/function) is newly added or has any changed line in its range. */\n isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n ): boolean {\n if (newMethodNames.has(name)) return true;\n return this.hasChangesInRange(startLine, endLine, changedLines);\n }\n\n // A file is \"a test file\" (excluded from diff-scoped rules) when it is a .spec/.test file or lives\n // under a __tests__/ directory.\n private isTestFile(file: string): boolean {\n return file.includes('.spec.ts') || file.includes('.test.ts') || file.includes('__tests__/');\n }\n}\n\n// Temporary migration delegators to DiffScope — removed once consumers inject it.\nconst diffScopeSvc = new DiffScope();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function detectBase(workspaceRoot: string): string | null {\n return diffScopeSvc.detectBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function resolveBase(workspaceRoot: string): DiffRange {\n return diffScopeSvc.resolveBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n return diffScopeSvc.getChangedFiles(workspaceRoot, base, head, opts);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n return diffScopeSvc.getFileDiff(workspaceRoot, file, base, head);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedLineNumbers(diffContent: string): Set<number> {\n return diffScopeSvc.getChangedLineNumbers(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n return diffScopeSvc.findNewMethodSignaturesInDiff(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n return diffScopeSvc.hasChangesInRange(startLine, endLine, changedLines);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n): boolean {\n return diffScopeSvc.isNewOrModified(name, startLine, endLine, changedLines, newMethodNames);\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The FILE SET a diff-scoped rule judges — the one central place the whole-scope modes of #1027
|
|
3
|
+
* (`MODIFIED_PROJECTS`, `RUN_EVERY_TIME`) and the debug run's `--projects` filter are implemented.
|
|
4
|
+
*
|
|
5
|
+
* Every diff-scoped validator asks `DiffScope.getChangedFiles` which files to look at and
|
|
6
|
+
* `DiffScope.getFileDiff` which lines changed. Both consult the {@link FileScope} the caller is
|
|
7
|
+
* running inside (`diffScope.within(scope, work)`), so the widening happens ONCE, here, and no rule
|
|
8
|
+
* carries its own copy of it:
|
|
9
|
+
*
|
|
10
|
+
* DIFF — today's behaviour: the files the diff changed.
|
|
11
|
+
* MODIFIED_PROJECTS — those files PLUS every file of every project any changed file belongs to.
|
|
12
|
+
* RUN_EVERY_TIME — every file in the repo (tracked + untracked, honouring .gitignore).
|
|
13
|
+
*
|
|
14
|
+
* Under both whole-scope kinds every file is judged WHOLE: `getFileDiff` reports every line as added,
|
|
15
|
+
* so a rule's line- or method-scoped logic sees the entire file as new. A widening can therefore never
|
|
16
|
+
* report LESS than the diff-scoped mode it replaces.
|
|
17
|
+
*
|
|
18
|
+
* `projectRoots`, when set, keeps only files whose owning project (nearest `project.json`) is one of
|
|
19
|
+
* those roots. It is what `--projects` on the debug run compiles to; the gate never sets it.
|
|
20
|
+
*/
|
|
21
|
+
import { WholeScopeMode } from './rule-configs';
|
|
22
|
+
export type FileScopeKind = 'DIFF' | WholeScopeMode;
|
|
23
|
+
/** Which files a rule run judges. Data-only; see the file comment. */
|
|
24
|
+
export declare class FileScope {
|
|
25
|
+
readonly kind: FileScopeKind;
|
|
26
|
+
/** Repo-relative project roots to keep ('.' = a project at the repo root), or null = all. */
|
|
27
|
+
readonly projectRoots: readonly string[] | null;
|
|
28
|
+
static readonly DIFF: FileScope;
|
|
29
|
+
constructor(kind: FileScopeKind,
|
|
30
|
+
/** Repo-relative project roots to keep ('.' = a project at the repo root), or null = all. */
|
|
31
|
+
projectRoots: readonly string[] | null);
|
|
32
|
+
/** True when this is exactly today's diff scope — no widening, no project filter. */
|
|
33
|
+
isPlainDiff(): boolean;
|
|
34
|
+
/** True for MODIFIED_PROJECTS / RUN_EVERY_TIME: every selected file is judged whole. */
|
|
35
|
+
isWhole(): boolean;
|
|
36
|
+
}
|
|
37
|
+
/** The two questions every consumer of the whole-scope modes asks about a mode string. */
|
|
38
|
+
export declare class WholeScopeModes {
|
|
39
|
+
/** True when `mode` is one of the two whole-scope modes. */
|
|
40
|
+
isWholeScopeMode(mode: string | undefined): mode is WholeScopeMode;
|
|
41
|
+
/**
|
|
42
|
+
* The per-file mode a rule runs with while its FILE SET is widened, or null when the rule's mode
|
|
43
|
+
* set has no diff-scoped mode at all (a PROJECT_MODES / STRUCTURAL_MODES rule, whose own
|
|
44
|
+
* `MODIFIED_PROJECTS` / `RUN_EVERY_TIME` it implements itself and which must not be rewritten).
|
|
45
|
+
*/
|
|
46
|
+
wholeFileJudgeMode(modeSet: readonly string[]): string | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Maps files to the nx project that owns them (the nearest ancestor holding a `project.json`) and
|
|
50
|
+
* project NAMES to their roots. Parser-free and cached per instance: one run builds one index.
|
|
51
|
+
*/
|
|
52
|
+
export declare class ProjectIndex {
|
|
53
|
+
private readonly workspaceRoot;
|
|
54
|
+
private readonly rootByDir;
|
|
55
|
+
private namesToRoots;
|
|
56
|
+
constructor(workspaceRoot: string);
|
|
57
|
+
/** Repo-relative root of the project owning `relFile` ('.' for a repo-root project), or null. */
|
|
58
|
+
rootOf(relFile: string): string | null;
|
|
59
|
+
/** The roots of the named projects. Throws naming every unknown name and the known ones. */
|
|
60
|
+
rootsFor(names: readonly string[]): string[];
|
|
61
|
+
/** The project name declared for `root`, for reports (the root itself when no project.json names it). */
|
|
62
|
+
nameOf(root: string): string;
|
|
63
|
+
private rootOfDir;
|
|
64
|
+
private names;
|
|
65
|
+
private readName;
|
|
66
|
+
private readJsonName;
|
|
67
|
+
}
|
|
68
|
+
/** Lists repo files — tracked plus untracked-not-ignored — that still exist on disk. */
|
|
69
|
+
export declare class RepoFileLister {
|
|
70
|
+
list(workspaceRoot: string, pathspecs: readonly string[]): string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Turns the diff's changed files into the files a {@link FileScope} selects. `keep` is the caller's
|
|
74
|
+
* own filter (ts-only, no tests) so a widened set obeys exactly the same in-scope test as the diff.
|
|
75
|
+
*/
|
|
76
|
+
export declare class ScopedFileSelector {
|
|
77
|
+
select(workspaceRoot: string, scope: FileScope, diffFiles: readonly string[], touchedFiles: () => readonly string[], pathspecs: readonly string[], keep: (file: string) => boolean): string[];
|
|
78
|
+
private widen;
|
|
79
|
+
}
|