@nielspeter/eess-ts 0.5.1 → 0.7.0
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/README.md +2 -2
- package/dist/builders/class-rule-builder.d.ts +6 -10
- package/dist/builders/class-rule-builder.d.ts.map +1 -1
- package/dist/builders/class-rule-builder.js +33 -4
- package/dist/builders/class-rule-builder.js.map +1 -1
- package/dist/builders/function-rule-builder.d.ts +29 -7
- package/dist/builders/function-rule-builder.d.ts.map +1 -1
- package/dist/builders/function-rule-builder.js +34 -8
- package/dist/builders/function-rule-builder.js.map +1 -1
- package/dist/conditions/body-analysis-function.d.ts.map +1 -1
- package/dist/conditions/body-analysis-function.js +19 -1
- package/dist/conditions/body-analysis-function.js.map +1 -1
- package/dist/conditions/body-analysis-module.d.ts.map +1 -1
- package/dist/conditions/body-analysis-module.js +37 -4
- package/dist/conditions/body-analysis-module.js.map +1 -1
- package/dist/conditions/body-analysis.d.ts +5 -2
- package/dist/conditions/body-analysis.d.ts.map +1 -1
- package/dist/conditions/body-analysis.js +9 -6
- package/dist/conditions/body-analysis.js.map +1 -1
- package/dist/conditions/call.d.ts +8 -5
- package/dist/conditions/call.d.ts.map +1 -1
- package/dist/conditions/call.js +46 -20
- package/dist/conditions/call.js.map +1 -1
- package/dist/conditions/catch-analysis.d.ts +7 -1
- package/dist/conditions/catch-analysis.d.ts.map +1 -1
- package/dist/conditions/catch-analysis.js +26 -27
- package/dist/conditions/catch-analysis.js.map +1 -1
- package/dist/conditions/class.d.ts +5 -3
- package/dist/conditions/class.d.ts.map +1 -1
- package/dist/conditions/class.js +9 -6
- package/dist/conditions/class.js.map +1 -1
- package/dist/conditions/function.d.ts +4 -4
- package/dist/conditions/function.js +4 -4
- package/dist/core/execute-rule.js +1 -1
- package/dist/core/object-literal-functions.d.ts +4 -1
- package/dist/core/object-literal-functions.d.ts.map +1 -1
- package/dist/core/object-literal-functions.js +27 -5
- package/dist/core/object-literal-functions.js.map +1 -1
- package/dist/core/through-wrappers.d.ts +24 -0
- package/dist/core/through-wrappers.d.ts.map +1 -0
- package/dist/core/through-wrappers.js +36 -0
- package/dist/core/through-wrappers.js.map +1 -0
- package/dist/core/vacuity-diagnosis.d.ts.map +1 -1
- package/dist/core/vacuity-diagnosis.js +11 -3
- package/dist/core/vacuity-diagnosis.js.map +1 -1
- package/dist/graphql/resolver-rule-builder.d.ts.map +1 -1
- package/dist/graphql/resolver-rule-builder.js +16 -2
- package/dist/graphql/resolver-rule-builder.js.map +1 -1
- package/dist/helpers/body-traversal.d.ts +74 -20
- package/dist/helpers/body-traversal.d.ts.map +1 -1
- package/dist/helpers/body-traversal.js +273 -48
- package/dist/helpers/body-traversal.js.map +1 -1
- package/dist/helpers/callback-extractor.d.ts +6 -1
- package/dist/helpers/callback-extractor.d.ts.map +1 -1
- package/dist/helpers/callback-extractor.js +45 -10
- package/dist/helpers/callback-extractor.js.map +1 -1
- package/dist/helpers/global-binding.d.ts +11 -0
- package/dist/helpers/global-binding.d.ts.map +1 -0
- package/dist/helpers/global-binding.js +232 -0
- package/dist/helpers/global-binding.js.map +1 -0
- package/dist/helpers/heritage.d.ts +25 -0
- package/dist/helpers/heritage.d.ts.map +1 -0
- package/dist/helpers/heritage.js +41 -0
- package/dist/helpers/heritage.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/models/arch-function.d.ts +44 -14
- package/dist/models/arch-function.d.ts.map +1 -1
- package/dist/models/arch-function.js +226 -43
- package/dist/models/arch-function.js.map +1 -1
- package/dist/predicates/class.d.ts +9 -9
- package/dist/predicates/class.d.ts.map +1 -1
- package/dist/predicates/class.js +14 -13
- package/dist/predicates/class.js.map +1 -1
- package/dist/predicates/function.d.ts +16 -4
- package/dist/predicates/function.d.ts.map +1 -1
- package/dist/predicates/function.js +56 -3
- package/dist/predicates/function.js.map +1 -1
- package/dist/predicates/type.d.ts +2 -1
- package/dist/predicates/type.d.ts.map +1 -1
- package/dist/predicates/type.js +6 -2
- package/dist/predicates/type.js.map +1 -1
- package/dist/presets/agent-guardrails.js +5 -5
- package/dist/presets/agent-guardrails.js.map +1 -1
- package/dist/presets/recommended.d.ts +14 -6
- package/dist/presets/recommended.d.ts.map +1 -1
- package/dist/presets/recommended.js +30 -11
- package/dist/presets/recommended.js.map +1 -1
- package/dist/rules/code-quality.d.ts +12 -1
- package/dist/rules/code-quality.d.ts.map +1 -1
- package/dist/rules/code-quality.js +106 -12
- package/dist/rules/code-quality.js.map +1 -1
- package/dist/rules/errors.d.ts +4 -2
- package/dist/rules/errors.d.ts.map +1 -1
- package/dist/rules/errors.js +44 -23
- package/dist/rules/errors.js.map +1 -1
- package/dist/rules/hygiene.d.ts +3 -1
- package/dist/rules/hygiene.d.ts.map +1 -1
- package/dist/rules/hygiene.js +3 -1
- package/dist/rules/hygiene.js.map +1 -1
- package/dist/rules/metrics.d.ts +6 -4
- package/dist/rules/metrics.d.ts.map +1 -1
- package/dist/rules/metrics.js +40 -20
- package/dist/rules/metrics.js.map +1 -1
- package/dist/rules/security.d.ts +19 -5
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +198 -19
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/typescript.d.ts +2 -2
- package/dist/rules/typescript.js +2 -2
- package/dist/smells/duplicate-bodies.js +2 -2
- package/dist/smells/duplicate-bodies.js.map +1 -1
- package/dist/smells/sibling-files.js +2 -2
- package/dist/smells/sibling-files.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -172,7 +172,7 @@ layeredArchitecture(p, {
|
|
|
172
172
|
|
|
173
173
|
**Floor presets** (universal safety, scoped by glob):
|
|
174
174
|
|
|
175
|
-
- `recommended(p)` — a thin, universal safety floor (no `eval`, no Function constructor, no silent catches, no empty bodies) that fires ~never on healthy code.
|
|
175
|
+
- `recommended(p)` — a thin, universal safety floor (no `eval`, no Function constructor, no silent catches, no empty bodies) that fires ~never on healthy code. The first three read the whole FILE, so they see a call wherever it is written — at top level, in a class's static block or field initializer, in a callback — not only inside a function body (bug 0333); `no-empty-bodies` reads functions, since that is what an empty body is a fact about. A finding names the declaration that contains it, or the file when nothing does, and carries a per-file identity so two files never share a baseline entry.
|
|
176
176
|
- `agentGuardrails(p, { src })` — the mistakes AI coding agents make most: generic errors, stub comments, empty bodies, copy-paste, and banned inline calls. Each rule carries `imperative` metadata for `explain --format agent`.
|
|
177
177
|
|
|
178
178
|
Every preset **runs its rules and throws** on any error-severity violation by
|
|
@@ -380,7 +380,7 @@ smells
|
|
|
380
380
|
| -------------- | ----------------------------------------- | ----------------------------------------------------- |
|
|
381
381
|
| `modules(p)` | Source files | Import/dependency rules |
|
|
382
382
|
| `classes(p)` | Class declarations | Inheritance, decorators, methods, body analysis |
|
|
383
|
-
| `functions(p)` | Functions, arrow functions, class
|
|
383
|
+
| `functions(p)` | Functions, arrow functions, class members | Naming, parameters, body analysis |
|
|
384
384
|
| `types(p)` | Interfaces + type aliases | Property types, type safety |
|
|
385
385
|
| `slices(p)` | Groups of files | Cycles, layer ordering |
|
|
386
386
|
| `calls(p)` | Call expressions | Framework-agnostic route/handler matching |
|
|
@@ -3,13 +3,6 @@ import { RuleBuilder } from '../core/rule-builder.js';
|
|
|
3
3
|
import type { ArchProject } from '../core/project.js';
|
|
4
4
|
import type { ExpressionMatcher } from '../helpers/matchers.js';
|
|
5
5
|
import type { TypeMatcher } from '../helpers/type-matchers.js';
|
|
6
|
-
/**
|
|
7
|
-
* Rule builder for ClassDeclaration elements.
|
|
8
|
-
*
|
|
9
|
-
* Created by the `classes(p)` entry point. Provides class-specific
|
|
10
|
-
* predicates and conditions alongside the identity predicates and
|
|
11
|
-
* structural conditions from the foundation plans.
|
|
12
|
-
*/
|
|
13
6
|
export declare class ClassRuleBuilder extends RuleBuilder<ClassDeclaration> {
|
|
14
7
|
constructor(project: ArchProject);
|
|
15
8
|
protected getElements(): ClassDeclaration[];
|
|
@@ -204,12 +197,15 @@ export declare class ClassRuleBuilder extends RuleBuilder<ClassDeclaration> {
|
|
|
204
197
|
notAcceptParameterOfType(matcher: TypeMatcher): this;
|
|
205
198
|
/**
|
|
206
199
|
* Assert that the class body contains at least one match.
|
|
207
|
-
* "Body" =
|
|
200
|
+
* "Body" = the member code only — method, constructor and accessor bodies, parameter defaults,
|
|
201
|
+
* property initializers and static blocks. A decorator, a computed name or a base class is
|
|
202
|
+
* wiring, and cannot satisfy it (bug 0307).
|
|
208
203
|
*/
|
|
209
204
|
contain(matcher: ExpressionMatcher): this;
|
|
210
205
|
/**
|
|
211
|
-
* Assert that the class
|
|
212
|
-
*
|
|
206
|
+
* Assert that no code the class runs contains a match: its member code, and every decorator
|
|
207
|
+
* expression, computed member name and the `extends` expression (bug 0307). Produces one
|
|
208
|
+
* violation per matching node found.
|
|
213
209
|
*/
|
|
214
210
|
notContain(matcher: ExpressionMatcher): this;
|
|
215
211
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-rule-builder.d.ts","sourceRoot":"","sources":["../../src/builders/class-rule-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"class-rule-builder.d.ts","sourceRoot":"","sources":["../../src/builders/class-rule-builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAmD/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AA6B9D,qBAAa,gBAAiB,SAAQ,WAAW,CAAC,gBAAgB,CAAC;gBACrD,OAAO,EAAE,WAAW;IAIhC,SAAS,CAAC,WAAW,IAAI,gBAAgB,EAAE;IA6B3C;;;OAGG;I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uleBuilder } from '../core/rule-builder.js';
|
|
2
4
|
import { classContain, classNotContain, classUseInsteadOf, classNotHaveEmptyBody, } from '../conditions/body-analysis.js';
|
|
3
5
|
// Identity predicates (plan 0003)
|
|
@@ -20,6 +22,12 @@ const cache = createElementCache();
|
|
|
20
22
|
* predicates and conditions alongside the identity predicates and
|
|
21
23
|
* structural conditions from the foundation plans.
|
|
22
24
|
*/
|
|
25
|
+
/** Whether a class lies inside another class, where that class's body search already reads it. */
|
|
26
|
+
function isInsideAClass(cls) {
|
|
27
|
+
return cls
|
|
28
|
+
.getAncestors()
|
|
29
|
+
.some((ancestor) => Node.isClassDeclaration(ancestor) || Node.isClassExpression(ancestor));
|
|
30
|
+
}
|
|
23
31
|
export class ClassRuleBuilder extends RuleBuilder {
|
|
24
32
|
constructor(project) {
|
|
25
33
|
super(project);
|
|
@@ -28,7 +36,25 @@ export class ClassRuleBuilder extends RuleBuilder {
|
|
|
28
36
|
return cache.get(this.project, SOLE_POPULATION, () => {
|
|
29
37
|
const classes = [];
|
|
30
38
|
for (const sourceFile of this.project.getSourceFiles()) {
|
|
31
|
-
|
|
39
|
+
// Every class declaration in the file, not only the top-level ones (bug 0321):
|
|
40
|
+
// `export namespace N { export class Inner {} }` is an ordinary class that
|
|
41
|
+
// `sourceFile.getClasses()` does not answer for, so no class rule reached it — and a class
|
|
42
|
+
// declared inside a function was invisible the same way.
|
|
43
|
+
//
|
|
44
|
+
// A class EXPRESSION is still not selected: this builder's element type is
|
|
45
|
+
// `ClassDeclaration` from its predicates to `searchClassBody`, and widening it is a
|
|
46
|
+
// separate change with its own question — what an anonymous class is called when an
|
|
47
|
+
// identity predicate asks. Its MEMBERS are read by the function rules since bug 0321.
|
|
48
|
+
// Through the shared walk cache, as every other walk in this package is: this is now a
|
|
49
|
+
// whole-AST walk per file where it used to be a top-level statement scan.
|
|
50
|
+
for (const cls of descendantsOfKind(sourceFile, SyntaxKind.ClassDeclaration)) {
|
|
51
|
+
// A class INSIDE another class is not its own subject: the enclosing class's body search
|
|
52
|
+
// already reads everything in it, so collecting both reported one `eval` twice — three
|
|
53
|
+
// times at two levels of nesting. Measured by the enforcement review of bug 0321, which
|
|
54
|
+
// is the same hazard the function collection guards against with `isInsideAFunction`.
|
|
55
|
+
if (Node.isClassDeclaration(cls) && !isInsideAClass(cls))
|
|
56
|
+
classes.push(cls);
|
|
57
|
+
}
|
|
32
58
|
}
|
|
33
59
|
return classes;
|
|
34
60
|
});
|
|
@@ -298,14 +324,17 @@ export class ClassRuleBuilder extends RuleBuilder {
|
|
|
298
324
|
// --- Body analysis condition methods (plan 0011) ---
|
|
299
325
|
/**
|
|
300
326
|
* Assert that the class body contains at least one match.
|
|
301
|
-
* "Body" =
|
|
327
|
+
* "Body" = the member code only — method, constructor and accessor bodies, parameter defaults,
|
|
328
|
+
* property initializers and static blocks. A decorator, a computed name or a base class is
|
|
329
|
+
* wiring, and cannot satisfy it (bug 0307).
|
|
302
330
|
*/
|
|
303
331
|
contain(matcher) {
|
|
304
332
|
return this.addCondition(classContain(matcher));
|
|
305
333
|
}
|
|
306
334
|
/**
|
|
307
|
-
* Assert that the class
|
|
308
|
-
*
|
|
335
|
+
* Assert that no code the class runs contains a match: its member code, and every decorator
|
|
336
|
+
* expression, computed member name and the `extends` expression (bug 0307). Produces one
|
|
337
|
+
* violation per matching node found.
|
|
309
338
|
*/
|
|
310
339
|
notContain(matcher) {
|
|
311
340
|
return this.addCondition(classNotContain(matcher));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-rule-builder.js","sourceRoot":"","sources":["../../src/builders/class-rule-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"class-rule-builder.js","sourceRoot":"","sources":["../../src/builders/class-rule-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE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AAY,CAAC,qBAAqB,EAAE,CAAC,CAAA;IACnD,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CAAC,OAAoB;IAC1C,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -3,14 +3,15 @@ import type { Condition } from '@nielspeter/eess';
|
|
|
3
3
|
import { RuleBuilder } from '../core/rule-builder.js';
|
|
4
4
|
import type { ExpressionMatcher } from '../helpers/matchers.js';
|
|
5
5
|
import type { ArchFunction } from '../models/arch-function.js';
|
|
6
|
-
import { type FunctionCollectionOptions } from '../models/arch-function.js';
|
|
6
|
+
import { type FunctionCollectionOptions, type FunctionKind } from '../models/arch-function.js';
|
|
7
7
|
import type { ArchPattern } from '../helpers/pattern.js';
|
|
8
8
|
import type { TypeMatcher } from '../helpers/type-matchers.js';
|
|
9
9
|
/**
|
|
10
10
|
* Rule builder for function-level architecture rules.
|
|
11
11
|
*
|
|
12
|
-
* Operates on
|
|
13
|
-
*
|
|
12
|
+
* Operates on every named function — declarations, variables holding a function, and class
|
|
13
|
+
* members: methods, constructors, accessors and function-valued properties (bug 0315) — unified
|
|
14
|
+
* through the ArchFunction model.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
16
17
|
* ```typescript
|
|
@@ -136,6 +137,27 @@ export declare class FunctionRuleBuilder extends RuleBuilder<ArchFunction> {
|
|
|
136
137
|
* rule pass having asserted nothing.
|
|
137
138
|
*/
|
|
138
139
|
areNotAsync(): this;
|
|
140
|
+
/**
|
|
141
|
+
* Narrows the selection to functions of any of the given kinds: `'function'`, `'method'`,
|
|
142
|
+
* `'constructor'`, `'getter'`, `'setter'` or `'property'` (bug 0315).
|
|
143
|
+
*
|
|
144
|
+
* **Predicate only**, unlike the dual-use methods on this builder: it never
|
|
145
|
+
* becomes an assertion. Written after `.should()` it still filters, and the
|
|
146
|
+
* assertion gate reports it as a misplaced predicate rather than letting the
|
|
147
|
+
* rule pass having asserted nothing.
|
|
148
|
+
*/
|
|
149
|
+
areOfKind(...kinds: FunctionKind[]): this;
|
|
150
|
+
/**
|
|
151
|
+
* Narrows the selection to functions of none of the given kinds. A rule that requires something a
|
|
152
|
+
* constructor or an accessor cannot give — `beAsync()`, `contain(call(...))` — keeps to the
|
|
153
|
+
* functions that can with `.that().areNotOfKind('constructor', 'getter', 'setter')` (bug 0315).
|
|
154
|
+
*
|
|
155
|
+
* **Predicate only**, unlike the dual-use methods on this builder: it never
|
|
156
|
+
* becomes an assertion. Written after `.should()` it still filters, and the
|
|
157
|
+
* assertion gate reports it as a misplaced predicate rather than letting the
|
|
158
|
+
* rule pass having asserted nothing.
|
|
159
|
+
*/
|
|
160
|
+
areNotOfKind(...kinds: FunctionKind[]): this;
|
|
139
161
|
/**
|
|
140
162
|
* Narrows the selection to functions that have exactly `n` parameters.
|
|
141
163
|
*
|
|
@@ -240,8 +262,8 @@ export declare class FunctionRuleBuilder extends RuleBuilder<ArchFunction> {
|
|
|
240
262
|
* Assert that at least one parameter has a type matching the given matcher.
|
|
241
263
|
*
|
|
242
264
|
* **Scope note:** Scans only the function's own parameter list.
|
|
243
|
-
*
|
|
244
|
-
*
|
|
265
|
+
* A set accessor is a function of its own, `Class.set x`, since bug 0315;
|
|
266
|
+
* the class-level counterpart scans the whole class at once.
|
|
245
267
|
*/
|
|
246
268
|
acceptParameterOfType(matcher: TypeMatcher): this;
|
|
247
269
|
/**
|
|
@@ -249,8 +271,8 @@ export declare class FunctionRuleBuilder extends RuleBuilder<ArchFunction> {
|
|
|
249
271
|
* Reports one violation per matching parameter.
|
|
250
272
|
*
|
|
251
273
|
* **Scope note:** Scans only the function's own parameter list.
|
|
252
|
-
*
|
|
253
|
-
*
|
|
274
|
+
* A set accessor is a function of its own, `Class.set x`, since bug 0315;
|
|
275
|
+
* the class-level counterpart scans the whole class at once.
|
|
254
276
|
*/
|
|
255
277
|
notAcceptParameterOfType(matcher: TypeMatcher): this;
|
|
256
278
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-rule-builder.d.ts","sourceRoot":"","sources":["../../src/builders/function-rule-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAO/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,OAAO,
|
|
1
|
+
{"version":3,"file":"function-rule-builder.d.ts","sourceRoot":"","sources":["../../src/builders/function-rule-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAO/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,YAAY,EAClB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAqBxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAuC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,mBAAoB,SAAQ,WAAW,CAAC,YAAY,CAAC;IAG9D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC;gBADpC,OAAO,EAAE,WAAW,EACH,kBAAkB,CAAC,EAAE,yBAAyB,YAAA;IAKjE,SAAS,CAAC,WAAW,IAAI,YAAY,EAAE;IAevC;;;OA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I,IAAI;IAI7B;;;;;;;OAOG;IACH,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAI9D;;;;;;;OAOG;IACH,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMhD;;;OAGG;IACH,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,IAAI;IAIvD;;OAEG;IACH,QAAQ,IAAI,IAAI;IAIhB;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,OAAO,IAAI,IAAI;IAIf,sEAAsE;IACtE,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMhD;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAIjD;;;;;;;OAOG;IACH,wBAAwB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAMpD;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAMlD;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAIzC;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAI5C;;;OAGG;IACH,YAAY,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAInE;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAIxB;;;;;OAKG;IACH,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;CAG1C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CACvB,CAAC,EAAE,WAAW,EACd,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAErB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { RuleBuilder } from '../core/rule-builder.js';
|
|
2
2
|
import { functionContain, functionNotContain, functionUseInsteadOf, functionNotHaveEmptyBody, } from '../conditions/body-analysis-function.js';
|
|
3
3
|
import { createElementCache, SOLE_POPULATION } from '../core/element-cache.js';
|
|
4
|
-
import { collectFunctions } from '../models/arch-function.js';
|
|
4
|
+
import { collectFunctions, } from '../models/arch-function.js';
|
|
5
5
|
import { followPattern as followPatternCondition } from '../conditions/pattern.js';
|
|
6
6
|
import { notExist as fnNotExist, beExported as fnBeExported, beAsync as fnBeAsync, haveNameMatching as fnConditionHaveNameMatching, acceptParameterOfType as fnAcceptParameterOfType, notAcceptParameterOfType as fnNotAcceptParameterOfType, haveReturnTypeMatching as fnHaveReturnTypeMatching, resideInFile as fnConditionResideInFile, resideInFolder as fnConditionResideInFolder, } from '../conditions/function.js';
|
|
7
7
|
import { haveNameMatching as identityHaveNameMatching, haveNameStartingWith as identityHaveNameStartingWith, haveNameEndingWith as identityHaveNameEndingWith, resideInFile as identityResideInFile, resideInFolder as identityResideInFolder, areExported as identityAreExported, areNotExported as identityAreNotExported, } from '../predicates/identity.js';
|
|
8
|
-
import { arePublic as fnArePublic, areProtected as fnAreProtected, arePrivate as fnArePrivate, areAsync as fnAreAsync, areNotAsync as fnAreNotAsync, haveParameterCount as fnHaveParameterCount, haveParameterCountGreaterThan as fnHaveParameterCountGreaterThan, haveParameterCountLessThan as fnHaveParameterCountLessThan, haveParameterNamed as fnHaveParameterNamed, haveReturnType as fnHaveReturnType, haveRestParameter as fnHaveRestParameter, haveOptionalParameter as fnHaveOptionalParameter, haveParameterOfType as fnHaveParameterOfType, haveParameterNameMatching as fnHaveParameterNameMatching, } from '../predicates/function.js';
|
|
8
|
+
import { arePublic as fnArePublic, areProtected as fnAreProtected, arePrivate as fnArePrivate, areAsync as fnAreAsync, areNotAsync as fnAreNotAsync, areOfKind as fnAreOfKind, areNotOfKind as fnAreNotOfKind, haveParameterCount as fnHaveParameterCount, haveParameterCountGreaterThan as fnHaveParameterCountGreaterThan, haveParameterCountLessThan as fnHaveParameterCountLessThan, haveParameterNamed as fnHaveParameterNamed, haveReturnType as fnHaveReturnType, haveRestParameter as fnHaveRestParameter, haveOptionalParameter as fnHaveOptionalParameter, haveParameterOfType as fnHaveParameterOfType, haveParameterNameMatching as fnHaveParameterNameMatching, } from '../predicates/function.js';
|
|
9
9
|
/** One collection per (project, collection options), shared by every rule (plan 0075). */
|
|
10
10
|
const cache = createElementCache();
|
|
11
11
|
/**
|
|
@@ -27,8 +27,9 @@ function optionsKey(options) {
|
|
|
27
27
|
/**
|
|
28
28
|
* Rule builder for function-level architecture rules.
|
|
29
29
|
*
|
|
30
|
-
* Operates on
|
|
31
|
-
*
|
|
30
|
+
* Operates on every named function — declarations, variables holding a function, and class
|
|
31
|
+
* members: methods, constructors, accessors and function-valued properties (bug 0315) — unified
|
|
32
|
+
* through the ArchFunction model.
|
|
32
33
|
*
|
|
33
34
|
* @example
|
|
34
35
|
* ```typescript
|
|
@@ -194,6 +195,31 @@ export class FunctionRuleBuilder extends RuleBuilder {
|
|
|
194
195
|
areNotAsync() {
|
|
195
196
|
return this.addPredicate(fnAreNotAsync());
|
|
196
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Narrows the selection to functions of any of the given kinds: `'function'`, `'method'`,
|
|
200
|
+
* `'constructor'`, `'getter'`, `'setter'` or `'property'` (bug 0315).
|
|
201
|
+
*
|
|
202
|
+
* **Predicate only**, unlike the dual-use methods on this builder: it never
|
|
203
|
+
* becomes an assertion. Written after `.should()` it still filters, and the
|
|
204
|
+
* assertion gate reports it as a misplaced predicate rather than letting the
|
|
205
|
+
* rule pass having asserted nothing.
|
|
206
|
+
*/
|
|
207
|
+
areOfKind(...kinds) {
|
|
208
|
+
return this.addPredicate(fnAreOfKind(...kinds));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Narrows the selection to functions of none of the given kinds. A rule that requires something a
|
|
212
|
+
* constructor or an accessor cannot give — `beAsync()`, `contain(call(...))` — keeps to the
|
|
213
|
+
* functions that can with `.that().areNotOfKind('constructor', 'getter', 'setter')` (bug 0315).
|
|
214
|
+
*
|
|
215
|
+
* **Predicate only**, unlike the dual-use methods on this builder: it never
|
|
216
|
+
* becomes an assertion. Written after `.should()` it still filters, and the
|
|
217
|
+
* assertion gate reports it as a misplaced predicate rather than letting the
|
|
218
|
+
* rule pass having asserted nothing.
|
|
219
|
+
*/
|
|
220
|
+
areNotOfKind(...kinds) {
|
|
221
|
+
return this.addPredicate(fnAreNotOfKind(...kinds));
|
|
222
|
+
}
|
|
197
223
|
/**
|
|
198
224
|
* Narrows the selection to functions that have exactly `n` parameters.
|
|
199
225
|
*
|
|
@@ -328,8 +354,8 @@ export class FunctionRuleBuilder extends RuleBuilder {
|
|
|
328
354
|
* Assert that at least one parameter has a type matching the given matcher.
|
|
329
355
|
*
|
|
330
356
|
* **Scope note:** Scans only the function's own parameter list.
|
|
331
|
-
*
|
|
332
|
-
*
|
|
357
|
+
* A set accessor is a function of its own, `Class.set x`, since bug 0315;
|
|
358
|
+
* the class-level counterpart scans the whole class at once.
|
|
333
359
|
*/
|
|
334
360
|
acceptParameterOfType(matcher) {
|
|
335
361
|
return this.addCondition(fnAcceptParameterOfType(matcher));
|
|
@@ -339,8 +365,8 @@ export class FunctionRuleBuilder extends RuleBuilder {
|
|
|
339
365
|
* Reports one violation per matching parameter.
|
|
340
366
|
*
|
|
341
367
|
* **Scope note:** Scans only the function's own parameter list.
|
|
342
|
-
*
|
|
343
|
-
*
|
|
368
|
+
* A set accessor is a function of its own, `Class.set x`, since bug 0315;
|
|
369
|
+
* the class-level counterpart scans the whole class at once.
|
|
344
370
|
*/
|
|
345
371
|
notAcceptParameterOfType(matcher) {
|
|
346
372
|
return this.addCondition(fnNotAcceptParameterOfType(matcher));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-rule-builder.js","sourceRoot":"","sources":["../../src/builders/function-rule-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,
|
|
1
|
+
{"version":3,"file":"function-rule-builder.js","sourceRoot":"","sources":["../../src/builders/function-rule-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,EACL,gBAAgB,GAGjB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,aAAa,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAElF,OAAO,EACL,QAAQ,IAAI,UAAU,EACtB,UAAU,IAAI,YAAY,EAC1B,OAAO,IAAI,SAAS,EACpB,gBAAgB,IAAI,2BAA2B,EAC/C,qBAAqB,IAAI,uBAAuB,EAChD,wBAAwB,IAAI,0BAA0B,EACtD,sBAAsB,IAAI,wBAAwB,EAClD,YAAY,IAAI,uBAAuB,EACvC,cAAc,IAAI,yBAAyB,GAC5C,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,gBAAgB,IAAI,wBAAwB,EAC5C,oBAAoB,IAAI,4BAA4B,EACpD,kBAAkB,IAAI,0BAA0B,EAChD,YAAY,IAAI,oBAAoB,EACpC,cAAc,IAAI,sBAAsB,EACxC,WAAW,IAAI,mBAAmB,EAClC,cAAc,IAAI,sBAAsB,GACzC,MAAM,2BAA2B,CAAA;AAElC,OAAO,EACL,SAAS,IAAI,WAAW,EACxB,YAAY,IAAI,cAAc,EAC9B,UAAU,IAAI,YAAY,EAC1B,QAAQ,IAAI,UAAU,EACtB,WAAW,IAAI,aAAa,EAC5B,SAAS,IAAI,WAAW,EACxB,Y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,EACd,OAAmC;IAEnC,OAAO,IAAI,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAC5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-analysis-function.d.ts","sourceRoot":"","sources":["../../src/conditions/body-analysis-function.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAoB,MAAM,kBAAkB,CAAA;AAEnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAyB9D;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC,YAAY,CAAC,CAoBnF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC,YAAY,CAAC,CA2BtF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,iBAAiB,EACtB,IAAI,EAAE,iBAAiB,GACtB,SAAS,CAAC,YAAY,CAAC,CAuCzB;
|
|
1
|
+
{"version":3,"file":"body-analysis-function.d.ts","sourceRoot":"","sources":["../../src/conditions/body-analysis-function.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAoB,MAAM,kBAAkB,CAAA;AAEnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAyB9D;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC,YAAY,CAAC,CAoBnF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC,YAAY,CAAC,CA2BtF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,iBAAiB,EACtB,IAAI,EAAE,iBAAiB,GACtB,SAAS,CAAC,YAAY,CAAC,CAuCzB;AAiBD;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,SAAS,CAAC,YAAY,CAAC,CA0BlE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node } from 'ts-morph';
|
|
1
|
+
import { Node, Scope } from 'ts-morph';
|
|
2
2
|
import { searchFunctionBody, reportedLine } from '../helpers/body-traversal.js';
|
|
3
3
|
import { identifyMatches } from './match-identity.js';
|
|
4
4
|
/**
|
|
@@ -83,6 +83,22 @@ export function functionUseInsteadOf(bad, good) {
|
|
|
83
83
|
},
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* An empty constructor that still does something (bug 0315). One whose every parameter is a parameter
|
|
88
|
+
* property assigns a field for each — `constructor(private readonly db: Db) {}` — and a private or
|
|
89
|
+
* protected one that takes nothing restricts who may construct the class. An empty constructor that
|
|
90
|
+
* takes a plain parameter drops it, and an empty public constructor that takes nothing does nothing:
|
|
91
|
+
* both are reported.
|
|
92
|
+
*/
|
|
93
|
+
function isPurposefulConstructor(node) {
|
|
94
|
+
if (!Node.isConstructorDeclaration(node))
|
|
95
|
+
return false;
|
|
96
|
+
const parameters = node.getParameters();
|
|
97
|
+
if (parameters.length > 0)
|
|
98
|
+
return parameters.every((parameter) => parameter.isParameterProperty());
|
|
99
|
+
const scope = node.getScope();
|
|
100
|
+
return scope === Scope.Private || scope === Scope.Protected;
|
|
101
|
+
}
|
|
86
102
|
/**
|
|
87
103
|
* Function must not have an empty body (zero statements).
|
|
88
104
|
*
|
|
@@ -101,6 +117,8 @@ export function functionNotHaveEmptyBody() {
|
|
|
101
117
|
// Expression-bodied arrows return the expression, not a Block
|
|
102
118
|
if (!Node.isBlock(body))
|
|
103
119
|
continue; // expression body — always has content
|
|
120
|
+
if (isPurposefulConstructor(fn.getNode()))
|
|
121
|
+
continue;
|
|
104
122
|
if (body.getStatements().length === 0) {
|
|
105
123
|
violations.push(createFunctionViolation(fn, `${fn.getName() ?? '<anonymous>'} has an empty body`, context));
|
|
106
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-analysis-function.js","sourceRoot":"","sources":["../../src/conditions/body-analysis-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"body-analysis-function.js","sourceRoot":"","sources":["../../src/conditions/body-analysis-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAKtC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;GAKG;AACH,SAAS,uBAAuB,CAC9B,EAAgB,EAChB,OAAe,EACf,OAAyB;IAEzB,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,aAAa;QACtC,IAAI,EAAE,EAAE,CAAC,aAAa,EAAE,CAAC,WAAW,EAAE;QACtC,IAAI,EAAE,EAAE,CAAC,kBAAkB,EAAE;QAC7B,OAAO;QACP,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,OAAO;QACL,WAAW,EAAE,WAAW,OAAO,CAAC,WAAW,EAAE;QAC7C,QAAQ,CAAC,QAAwB,EAAE,OAAyB;YAC1D,MAAM,UAAU,GAAoB,EAAE,CAAA;YACtC,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE,CAAC;gBAC1B,MAAM,MAAM,GAAG,kBAAkB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;gBAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;oBAClB,UAA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;QACnB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-analysis-module.d.ts","sourceRoot":"","sources":["../../src/conditions/body-analysis-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"body-analysis-module.d.ts","sourceRoot":"","sources":["../../src/conditions/body-analysis-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,UAAU,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAoB,MAAM,kBAAkB,CAAA;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,EAEL,KAAK,iBAAiB,EAEvB,MAAM,8BAA8B,CAAA;AAgBrC;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,SAAS,CAAC,UAAU,CAAC,CAqBvB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,SAAS,CAAC,UAAU,CAAC,CA4CvB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,iBAAiB,EACtB,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,SAAS,CAAC,UAAU,CAAC,CA8CvB"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { identifyMatches } from './match-identity.js';
|
|
2
|
+
import { enclosingScopeName } from '../core/violation.js';
|
|
2
3
|
import { searchModuleBody, reportedLine, } from '../helpers/body-traversal.js';
|
|
3
4
|
// ─── Module body conditions ────────────────────────────────────────
|
|
5
|
+
/**
|
|
6
|
+
* What a per-match module finding is ABOUT: the declaration containing the match, and the file only
|
|
7
|
+
* when nothing does (bug 0333).
|
|
8
|
+
*
|
|
9
|
+
* One definition, because two module conditions report per-match findings and the expression was
|
|
10
|
+
* written twice — which also left the sabotage matrix unable to name either site unambiguously, in
|
|
11
|
+
* the commit that claimed to correct that matrix.
|
|
12
|
+
*/
|
|
13
|
+
function subjectOf(node, sf) {
|
|
14
|
+
return enclosingScopeName(node) ?? sf.getBaseName();
|
|
15
|
+
}
|
|
4
16
|
/**
|
|
5
17
|
* Module must contain at least one node matching the matcher.
|
|
6
18
|
*
|
|
@@ -45,12 +57,28 @@ export function moduleNotContain(matcher, options) {
|
|
|
45
57
|
const result = searchModuleBody(sf, matcher, options);
|
|
46
58
|
const identities = identifyMatches('module-body', sf.getFilePath(), result.matchingNodes, matcher.description);
|
|
47
59
|
result.matchingNodes.forEach((node, index) => {
|
|
60
|
+
const subjectName = subjectOf(node, sf);
|
|
48
61
|
violations.push({
|
|
49
62
|
rule: context.rule,
|
|
50
|
-
|
|
63
|
+
// The declaration that CONTAINS the match, and the file only when none does (bug 0333).
|
|
64
|
+
// A module rule reads the whole file, so `element` was the file for every finding — and
|
|
65
|
+
// `element` is what `.excluding()` keys on and what a reader looks at first. With the
|
|
66
|
+
// `recommended` floor reading module subjects, that would have turned every finding it
|
|
67
|
+
// already made from `runEval` into `dangerous.ts`.
|
|
68
|
+
//
|
|
69
|
+
// This does not change any existing baseline entry, because `identifyMatches` — which
|
|
70
|
+
// is untouched — builds the identity. It is NOT independent of the name, though: the
|
|
71
|
+
// key carries the match's own scope, so renaming the enclosing declaration moves the
|
|
72
|
+
// entry. An earlier version of this comment said renames were safe; the method review
|
|
73
|
+
// of PR #149 measured otherwise.
|
|
74
|
+
element: subjectName,
|
|
51
75
|
file: sf.getFilePath(),
|
|
52
76
|
line: reportedLine(node, result.triviaPositions[index]),
|
|
53
|
-
|
|
77
|
+
// The MESSAGE carries the same name as `element`, because the `github` emitter prints
|
|
78
|
+
// the message and drops `element` — naming the declaration only in `element` made the
|
|
79
|
+
// CI annotation LESS specific than before this rule changed subject, which the customer
|
|
80
|
+
// review measured (`runEval contains …` became `legacy.ts contains …`).
|
|
81
|
+
message: `${subjectName} contains ${matcher.description} at line ${String(reportedLine(node, result.triviaPositions[index]))}`,
|
|
54
82
|
identity: identities[index],
|
|
55
83
|
because: context.because,
|
|
56
84
|
});
|
|
@@ -76,12 +104,17 @@ export function moduleUseInsteadOf(bad, good, options) {
|
|
|
76
104
|
const goodResult = searchModuleBody(sf, good, options);
|
|
77
105
|
const identities = identifyMatches('module-body', sf.getFilePath(), badResult.matchingNodes, bad.description);
|
|
78
106
|
badResult.matchingNodes.forEach((node, index) => {
|
|
107
|
+
// Named like `moduleNotContain`'s matches (bug 0333): this is a finding ABOUT a match, so
|
|
108
|
+
// it names what contains the match. The two absence findings in this file — `moduleContain`
|
|
109
|
+
// above and the `goodResult` one below — are about the FILE not containing something, and
|
|
110
|
+
// name the file, which is the subject there.
|
|
111
|
+
const subjectName = subjectOf(node, sf);
|
|
79
112
|
violations.push({
|
|
80
113
|
rule: context.rule,
|
|
81
|
-
element:
|
|
114
|
+
element: subjectName,
|
|
82
115
|
file: sf.getFilePath(),
|
|
83
116
|
line: reportedLine(node, badResult.triviaPositions[index]),
|
|
84
|
-
message: `${
|
|
117
|
+
message: `${subjectName} contains ${bad.description} at line ${String(reportedLine(node, badResult.triviaPositions[index]))} — use ${good.description} instead`,
|
|
85
118
|
identity: identities[index],
|
|
86
119
|
because: context.because,
|
|
87
120
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-analysis-module.js","sourceRoot":"","sources":["../../src/conditions/body-analysis-module.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"body-analysis-module.js","sourceRoot":"","sources":["../../src/conditions/body-analysis-module.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,C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AAO,EAAE,OAAO,CAAC,OAAO;qBACzB,CAAC,CAAA;gBACJ,CAAC,CAAC,CAAA;gBAEF,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;oBACtB,UAAU,CAAC,IAAI,CAAC;wBACd,IAAI,EAAE,OAAO,CAAC,IAAI;wBAClB,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE;wBACzB,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE;wBACtB,IAAI,EAAE,CAAC;wBACP,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,qBAAqB,IAAI,CAAC,WAAW,EAAE;wBACnE,OAAO,EAAE,OAAO,CAAC,OAAO;qBACzB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YACD,OAAO,UAAU,CAAA;QACnB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -4,13 +4,16 @@ import type { ExpressionMatcher } from '../helpers/matchers.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Class body must contain at least one node matching the matcher.
|
|
6
6
|
*
|
|
7
|
-
* Violation if
|
|
7
|
+
* Violation if nothing in the class's member code contains a match: method, constructor and
|
|
8
|
+
* accessor bodies, parameter defaults, property initializers and static blocks. Not decorators,
|
|
9
|
+
* computed names or `extends` — wiring cannot satisfy a must-contain rule (bug 0307).
|
|
8
10
|
*/
|
|
9
11
|
export declare function classContain(matcher: ExpressionMatcher): Condition<ClassDeclaration>;
|
|
10
12
|
/**
|
|
11
13
|
* Class body must NOT contain any node matching the matcher.
|
|
12
14
|
*
|
|
13
|
-
* Violation for EACH matching node found in any
|
|
15
|
+
* Violation for EACH matching node found in any code the class runs: its member code, and every
|
|
16
|
+
* decorator expression, computed member name and the `extends` expression (bug 0307).
|
|
14
17
|
* Reports the specific line where the violation occurs.
|
|
15
18
|
*/
|
|
16
19
|
export declare function classNotContain(matcher: ExpressionMatcher): Condition<ClassDeclaration>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-analysis.d.ts","sourceRoot":"","sources":["../../src/conditions/body-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAoB,MAAM,kBAAkB,CAAA;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAK/D
|
|
1
|
+
{"version":3,"file":"body-analysis.d.ts","sourceRoot":"","sources":["../../src/conditions/body-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAoB,MAAM,kBAAkB,CAAA;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAK/D;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAoBpF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC,gBAAgB,CAAC,CA2BvF;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,iBAAiB,EACtB,IAAI,EAAE,iBAAiB,GACtB,SAAS,CAAC,gBAAgB,CAAC,CAyC7B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,SAAS,CAAC,gBAAgB,CAAC,CAmBnE"}
|
|
@@ -5,7 +5,9 @@ import { searchClassBody, reportedLine } from '../helpers/body-traversal.js';
|
|
|
5
5
|
/**
|
|
6
6
|
* Class body must contain at least one node matching the matcher.
|
|
7
7
|
*
|
|
8
|
-
* Violation if
|
|
8
|
+
* Violation if nothing in the class's member code contains a match: method, constructor and
|
|
9
|
+
* accessor bodies, parameter defaults, property initializers and static blocks. Not decorators,
|
|
10
|
+
* computed names or `extends` — wiring cannot satisfy a must-contain rule (bug 0307).
|
|
9
11
|
*/
|
|
10
12
|
export function classContain(matcher) {
|
|
11
13
|
return {
|
|
@@ -13,7 +15,7 @@ export function classContain(matcher) {
|
|
|
13
15
|
evaluate(elements, context) {
|
|
14
16
|
const violations = [];
|
|
15
17
|
for (const cls of elements) {
|
|
16
|
-
const result = searchClassBody(cls, matcher);
|
|
18
|
+
const result = searchClassBody(cls, matcher, 'member-code');
|
|
17
19
|
if (!result.found) {
|
|
18
20
|
violations.push(createViolation(cls, `${getElementName(cls)} does not contain ${matcher.description}`, context));
|
|
19
21
|
}
|
|
@@ -25,7 +27,8 @@ export function classContain(matcher) {
|
|
|
25
27
|
/**
|
|
26
28
|
* Class body must NOT contain any node matching the matcher.
|
|
27
29
|
*
|
|
28
|
-
* Violation for EACH matching node found in any
|
|
30
|
+
* Violation for EACH matching node found in any code the class runs: its member code, and every
|
|
31
|
+
* decorator expression, computed member name and the `extends` expression (bug 0307).
|
|
29
32
|
* Reports the specific line where the violation occurs.
|
|
30
33
|
*/
|
|
31
34
|
export function classNotContain(matcher) {
|
|
@@ -34,7 +37,7 @@ export function classNotContain(matcher) {
|
|
|
34
37
|
evaluate(elements, context) {
|
|
35
38
|
const violations = [];
|
|
36
39
|
for (const cls of elements) {
|
|
37
|
-
const result = searchClassBody(cls, matcher);
|
|
40
|
+
const result = searchClassBody(cls, matcher, 'all-code');
|
|
38
41
|
const identities = identifyMatches('class-body', cls.getSourceFile().getFilePath(), result.matchingNodes, matcher.description);
|
|
39
42
|
result.matchingNodes.forEach((node, index) => {
|
|
40
43
|
violations.push({
|
|
@@ -63,8 +66,8 @@ export function classUseInsteadOf(bad, good) {
|
|
|
63
66
|
evaluate(elements, context) {
|
|
64
67
|
const violations = [];
|
|
65
68
|
for (const cls of elements) {
|
|
66
|
-
const badResult = searchClassBody(cls, bad);
|
|
67
|
-
const goodResult = searchClassBody(cls, good);
|
|
69
|
+
const badResult = searchClassBody(cls, bad, 'all-code');
|
|
70
|
+
const goodResult = searchClassBody(cls, good, 'member-code');
|
|
68
71
|
// Report each occurrence of the bad pattern
|
|
69
72
|
const identities = identifyMatches('class-body', cls.getSourceFile().getFilePath(), badResult.matchingNodes, bad.description);
|
|
70
73
|
badResult.matchingNodes.forEach((node, index) => {
|