@futdevpro/dynamo-eslint 1.15.25 → 1.20.2
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/.c8rc.json +26 -26
- package/.cursor/rules/__assistant_guide.mdc +30 -30
- package/.cursor/rules/__main.mdc +64 -64
- package/.cursor/rules/_ag_backend-structure.mdc +85 -85
- package/.cursor/rules/_ag_backend.mdc +16 -16
- package/.cursor/rules/_ag_debug.mdc +7 -7
- package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -372
- package/.cursor/rules/_ag_file-refactoring.mdc +113 -113
- package/.cursor/rules/_ag_fixes_rules.mdc +5 -5
- package/.cursor/rules/_ag_frontend-structure.mdc +86 -86
- package/.cursor/rules/_ag_frontend.mdc +39 -39
- package/.cursor/rules/_ag_import-rules.mdc +44 -44
- package/.cursor/rules/_ag_naming.mdc +115 -115
- package/.cursor/rules/_ag_running_commands.mdc +4 -4
- package/.cursor/rules/_ag_server-controller.mdc +5 -5
- package/.cursor/rules/_ag_should-be.mdc +6 -6
- package/.cursor/rules/_ag_swearing.mdc +47 -47
- package/.cursor/rules/ai_development_guide.md +60 -60
- package/.cursor/rules/ai_directives.md +114 -114
- package/.cursor/rules/cursor-rules.md +160 -160
- package/.cursor/rules/default-command.mdc +464 -464
- package/.cursor/rules/error_code_pattern.md +39 -39
- package/.cursor/rules/saved rule mcp server use.md +15 -15
- package/.dynamo/pipeline.cicd.config.json +184 -184
- package/.dynamo/version-bump.config.json +5 -5
- package/.eslintrc.json +4 -4
- package/.github/workflows/main.yml +436 -436
- package/.husky/pre-commit +2 -2
- package/.vscode/settings.json +11 -11
- package/README.md +312 -315
- package/__documentations/2026-04-18-ccap-review-integration.md +173 -173
- package/__documentations/2026-08-18-bfr-ctm-005-eslint9-validator-report.md +45 -0
- package/__documentations/2026-08-22-angular-20-phase2-release.md +79 -0
- package/build/configs/base.d.ts +1 -2
- package/build/configs/base.d.ts.map +1 -1
- package/build/configs/base.js +3 -4
- package/build/configs/base.js.map +1 -1
- package/build/configs/ngx.d.ts +1 -3
- package/build/configs/ngx.d.ts.map +1 -1
- package/build/configs/ngx.js +4 -7
- package/build/configs/ngx.js.map +1 -1
- package/build/plugin/index.d.ts +24 -24
- package/build/plugin/rules/no-getter-logic.js +1 -1
- package/build/plugin/rules/no-getter-logic.js.map +1 -1
- package/build/plugin/rules/prefer-enum-over-string-union.js +7 -7
- package/build/plugin/rules/prefer-enum-over-string-union.js.map +1 -1
- package/build/plugin/rules/prefer-interface-over-duplicate-types.js +2 -2
- package/build/plugin/rules/prefer-interface-over-duplicate-types.js.map +1 -1
- package/build/plugin/rules/require-jsdoc-description.js +7 -7
- package/build/plugin/rules/require-jsdoc-description.js.map +1 -1
- package/build/scripts/dynamo-fix.js +1 -1
- package/build/scripts/dynamo-fix.js.map +1 -1
- package/build/scripts/fix-return-types.d.ts.map +1 -1
- package/build/scripts/fix-return-types.js.map +1 -1
- package/build/scripts/validate-imports.js +51 -27
- package/build/scripts/validate-imports.js.map +1 -1
- package/build/scripts/validate-naming.js +49 -10
- package/build/scripts/validate-naming.js.map +1 -1
- package/eslint.config.js +15 -15
- package/package.json +27 -28
- package/pnpm-workspace.yaml +2 -0
- package/samples/.vscode/settings.json +13 -13
- package/samples/base/.eslintrc.json +6 -6
- package/samples/base/eslint.config.js +3 -3
- package/samples/fsm/.eslintrc.json +4 -4
- package/samples/fsm/eslint.config.js +3 -3
- package/samples/ngx/.eslintrc.json +6 -6
- package/samples/ngx/eslint.config.js +3 -3
- package/samples/ngx-package/.eslintrc.json +4 -4
- package/samples/ngx-package/eslint.config.js +3 -3
- package/samples/nts/.eslintrc.json +6 -6
- package/samples/nts/eslint.config.js +3 -3
- package/samples/nts-package/.eslintrc.json +4 -4
- package/samples/nts-package/eslint.config.js +3 -3
- package/samples/package.json.example +22 -26
- package/samples/poc-sample.ts +38 -38
- package/samples/poc-violations.ts +54 -54
- package/scripts/run-coverage-tests.js +24 -24
- package/spec/support/helpers/ts-node-helper.js +9 -9
- package/spec/support/jasmine.coverage.json +23 -23
- package/spec/support/jasmine.json +24 -24
- package/src/configs/angular20-compatibility.spec.ts +62 -0
- package/src/configs/base.ts +156 -157
- package/src/configs/fsm.ts +10 -10
- package/src/configs/ngx-package.ts +10 -10
- package/src/configs/ngx.ts +92 -95
- package/src/configs/nts-package.ts +20 -20
- package/src/configs/nts.ts +34 -34
- package/src/index.ts +4 -4
- package/src/plugin/index.ts +86 -86
- package/src/plugin/rules/angular/angular-for-track-logic.spec.ts +44 -44
- package/src/plugin/rules/angular/angular-for-track-logic.ts +88 -88
- package/src/plugin/rules/angular/effect-signal-loop.spec.ts +89 -89
- package/src/plugin/rules/angular/effect-signal-loop.ts +125 -125
- package/src/plugin/rules/angular/no-async-ngoninit.spec.ts +50 -50
- package/src/plugin/rules/angular/no-async-ngoninit.ts +43 -43
- package/src/plugin/rules/angular/no-component-direct-api.spec.ts +78 -78
- package/src/plugin/rules/angular/no-component-direct-api.ts +82 -82
- package/src/plugin/rules/angular/no-method-call-in-template.spec.ts +63 -63
- package/src/plugin/rules/angular/no-method-call-in-template.ts +89 -89
- package/src/plugin/rules/angular/no-ngfor-directive.spec.ts +44 -44
- package/src/plugin/rules/angular/no-ngfor-directive.ts +62 -62
- package/src/plugin/rules/angular/no-ngif-directive.spec.ts +44 -44
- package/src/plugin/rules/angular/no-ngif-directive.ts +62 -62
- package/src/plugin/rules/explicit-types.spec.ts +190 -190
- package/src/plugin/rules/explicit-types.ts +186 -186
- package/src/plugin/rules/import/import-order.spec.ts +219 -219
- package/src/plugin/rules/import/import-order.ts +197 -197
- package/src/plugin/rules/import/no-import-type.spec.ts +69 -69
- package/src/plugin/rules/import/no-import-type.ts +46 -46
- package/src/plugin/rules/import/no-js-import.spec.ts +82 -82
- package/src/plugin/rules/import/no-js-import.ts +45 -45
- package/src/plugin/rules/naming-patterns.spec.ts +189 -189
- package/src/plugin/rules/naming-patterns.ts +426 -426
- package/src/plugin/rules/no-getter-logic.spec.ts +591 -591
- package/src/plugin/rules/no-getter-logic.ts +220 -220
- package/src/plugin/rules/prefer-enum-over-string-union.spec.ts +583 -583
- package/src/plugin/rules/prefer-enum-over-string-union.ts +333 -334
- package/src/plugin/rules/prefer-interface-over-duplicate-types.spec.ts +404 -404
- package/src/plugin/rules/prefer-interface-over-duplicate-types.ts +314 -314
- package/src/plugin/rules/require-jsdoc-description.spec.ts +779 -779
- package/src/plugin/rules/require-jsdoc-description.ts +572 -572
- package/src/plugin/rules/require-test-description-prefix.spec.ts +459 -459
- package/src/plugin/rules/require-test-description-prefix.ts +154 -154
- package/src/plugin/rules/ts/data-model-extends.spec.ts +84 -84
- package/src/plugin/rules/ts/data-model-extends.ts +100 -100
- package/src/plugin/rules/ts/no-any-type.spec.ts +28 -28
- package/src/plugin/rules/ts/no-any-type.ts +36 -36
- package/src/plugin/rules/ts/no-as-cast.spec.ts +51 -51
- package/src/plugin/rules/ts/no-as-cast.ts +51 -51
- package/src/plugin/rules/ts/no-dynamic-imports.spec.ts +54 -54
- package/src/plugin/rules/ts/no-dynamic-imports.ts +49 -49
- package/src/plugin/rules/ts/no-native-browser-dialogs.spec.ts +54 -54
- package/src/plugin/rules/ts/no-native-browser-dialogs.ts +84 -84
- package/src/plugin/rules/ts/no-plain-function-export.spec.ts +72 -72
- package/src/plugin/rules/ts/no-plain-function-export.ts +73 -73
- package/src/plugin/rules/ts/one-export-per-file.spec.ts +64 -64
- package/src/plugin/rules/ts/one-export-per-file.ts +77 -77
- package/src/scripts/dynamo-fix.ts +172 -172
- package/src/scripts/eslintrc-audit.ts +116 -116
- package/src/scripts/fix-return-types.spec.ts +65 -65
- package/src/scripts/fix-return-types.ts +286 -285
- package/src/scripts/validate-imports.ts +288 -257
- package/src/scripts/validate-naming.ts +209 -183
- package/src/scripts/validator-cli.integration.spec.ts +99 -0
- package/tsconfig.json +31 -31
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { Rule } from 'eslint';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* `@for (...; track <expr>)` kifejezés keresése — capture group 1: a track expression.
|
|
5
|
-
*/
|
|
6
|
-
const FOR_TRACK_REGEX: RegExp = /@for\s*\([^)]*;\s*track\s+([^;)]+)/g;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Logika detektáló minták a track kifejezésben.
|
|
10
|
-
* Tiltott: `??`, `||`, `&&`, `()`, `+-*\/`, ternary `?`.
|
|
11
|
-
* Megengedett: egyszerű property access (`item.id`).
|
|
12
|
-
*/
|
|
13
|
-
const TRACK_LOGIC_PATTERNS: RegExp[] = [
|
|
14
|
-
/\?\?/,
|
|
15
|
-
/\|\|/,
|
|
16
|
-
/&&/,
|
|
17
|
-
/\(/,
|
|
18
|
-
/\)/,
|
|
19
|
-
/[+\-*/%]/,
|
|
20
|
-
/\?\s*[^:]/,
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Adott offset alapján a sor és oszlop kiszámítása az alap szövegből.
|
|
25
|
-
*/
|
|
26
|
-
function computeLoc(text: string, index: number): { line: number; column: number } {
|
|
27
|
-
const before: string = text.substring(0, index);
|
|
28
|
-
const newlineMatches: RegExpMatchArray | null = before.match(/\n/g);
|
|
29
|
-
const line: number = (newlineMatches ? newlineMatches.length : 0) + 1;
|
|
30
|
-
const lastNewline: number = before.lastIndexOf('\n');
|
|
31
|
-
const column: number = lastNewline === -1 ? index : index - lastNewline - 1;
|
|
32
|
-
return { line: line, column: column };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Angular-for-track-logic szabály: tilos logika `@for (...; track <expr>)` kifejezésben.
|
|
37
|
-
* CCAP "angular-for-track-logic" review ESLint template-text-scan portja.
|
|
38
|
-
*/
|
|
39
|
-
const rule: Rule.RuleModule = {
|
|
40
|
-
meta: {
|
|
41
|
-
type: 'problem',
|
|
42
|
-
docs: {
|
|
43
|
-
description:
|
|
44
|
-
'Forbid logic in Angular `@for (...; track <expr>)`; '
|
|
45
|
-
+ 'only direct property access (`item.id`) allowed.',
|
|
46
|
-
recommended: true,
|
|
47
|
-
},
|
|
48
|
-
schema: [],
|
|
49
|
-
messages: {
|
|
50
|
-
trackLogic: 'Logika a `@for track` kifejezésben: `track {{expr}}`.',
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
create(context: Rule.RuleContext): Rule.RuleListener {
|
|
54
|
-
const filename: string = context.filename ?? '';
|
|
55
|
-
if (!filename.endsWith('.html')) {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
const text: string = context.sourceCode.text ?? '';
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
Program(): void {
|
|
62
|
-
try {
|
|
63
|
-
const localRegex: RegExp = new RegExp(FOR_TRACK_REGEX.source, 'g');
|
|
64
|
-
let match: RegExpExecArray | null = localRegex.exec(text);
|
|
65
|
-
while (match !== null) {
|
|
66
|
-
const expr: string = match[1].trim();
|
|
67
|
-
const hasLogic: boolean = TRACK_LOGIC_PATTERNS.some(
|
|
68
|
-
(p: RegExp): boolean => p.test(expr),
|
|
69
|
-
);
|
|
70
|
-
if (hasLogic) {
|
|
71
|
-
const loc: { line: number; column: number } = computeLoc(text, match.index);
|
|
72
|
-
context.report({
|
|
73
|
-
loc: { start: loc, end: { line: loc.line, column: loc.column + match[0].length } },
|
|
74
|
-
messageId: 'trackLogic',
|
|
75
|
-
data: { expr: expr },
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
match = localRegex.exec(text);
|
|
79
|
-
}
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error('[angular-for-track-logic] Error in Program visitor:', error);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export default rule;
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `@for (...; track <expr>)` kifejezés keresése — capture group 1: a track expression.
|
|
5
|
+
*/
|
|
6
|
+
const FOR_TRACK_REGEX: RegExp = /@for\s*\([^)]*;\s*track\s+([^;)]+)/g;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Logika detektáló minták a track kifejezésben.
|
|
10
|
+
* Tiltott: `??`, `||`, `&&`, `()`, `+-*\/`, ternary `?`.
|
|
11
|
+
* Megengedett: egyszerű property access (`item.id`).
|
|
12
|
+
*/
|
|
13
|
+
const TRACK_LOGIC_PATTERNS: RegExp[] = [
|
|
14
|
+
/\?\?/,
|
|
15
|
+
/\|\|/,
|
|
16
|
+
/&&/,
|
|
17
|
+
/\(/,
|
|
18
|
+
/\)/,
|
|
19
|
+
/[+\-*/%]/,
|
|
20
|
+
/\?\s*[^:]/,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adott offset alapján a sor és oszlop kiszámítása az alap szövegből.
|
|
25
|
+
*/
|
|
26
|
+
function computeLoc(text: string, index: number): { line: number; column: number } {
|
|
27
|
+
const before: string = text.substring(0, index);
|
|
28
|
+
const newlineMatches: RegExpMatchArray | null = before.match(/\n/g);
|
|
29
|
+
const line: number = (newlineMatches ? newlineMatches.length : 0) + 1;
|
|
30
|
+
const lastNewline: number = before.lastIndexOf('\n');
|
|
31
|
+
const column: number = lastNewline === -1 ? index : index - lastNewline - 1;
|
|
32
|
+
return { line: line, column: column };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Angular-for-track-logic szabály: tilos logika `@for (...; track <expr>)` kifejezésben.
|
|
37
|
+
* CCAP "angular-for-track-logic" review ESLint template-text-scan portja.
|
|
38
|
+
*/
|
|
39
|
+
const rule: Rule.RuleModule = {
|
|
40
|
+
meta: {
|
|
41
|
+
type: 'problem',
|
|
42
|
+
docs: {
|
|
43
|
+
description:
|
|
44
|
+
'Forbid logic in Angular `@for (...; track <expr>)`; '
|
|
45
|
+
+ 'only direct property access (`item.id`) allowed.',
|
|
46
|
+
recommended: true,
|
|
47
|
+
},
|
|
48
|
+
schema: [],
|
|
49
|
+
messages: {
|
|
50
|
+
trackLogic: 'Logika a `@for track` kifejezésben: `track {{expr}}`.',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
create(context: Rule.RuleContext): Rule.RuleListener {
|
|
54
|
+
const filename: string = context.filename ?? '';
|
|
55
|
+
if (!filename.endsWith('.html')) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
const text: string = context.sourceCode.text ?? '';
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
Program(): void {
|
|
62
|
+
try {
|
|
63
|
+
const localRegex: RegExp = new RegExp(FOR_TRACK_REGEX.source, 'g');
|
|
64
|
+
let match: RegExpExecArray | null = localRegex.exec(text);
|
|
65
|
+
while (match !== null) {
|
|
66
|
+
const expr: string = match[1].trim();
|
|
67
|
+
const hasLogic: boolean = TRACK_LOGIC_PATTERNS.some(
|
|
68
|
+
(p: RegExp): boolean => p.test(expr),
|
|
69
|
+
);
|
|
70
|
+
if (hasLogic) {
|
|
71
|
+
const loc: { line: number; column: number } = computeLoc(text, match.index);
|
|
72
|
+
context.report({
|
|
73
|
+
loc: { start: loc, end: { line: loc.line, column: loc.column + match[0].length } },
|
|
74
|
+
messageId: 'trackLogic',
|
|
75
|
+
data: { expr: expr },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
match = localRegex.exec(text);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('[angular-for-track-logic] Error in Program visitor:', error);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default rule;
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import effectSignalLoopRule from './effect-signal-loop';
|
|
2
|
-
|
|
3
|
-
describe('| effect-signal-loop', () => {
|
|
4
|
-
it('| should be a valid ESLint rule', () => {
|
|
5
|
-
expect(effectSignalLoopRule.meta?.type).toBe('problem');
|
|
6
|
-
expect(effectSignalLoopRule.meta?.messages?.effectSignalLoop).toBeDefined();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('| should report when same signal is read AND written in effect', () => {
|
|
10
|
-
let reportCalled: boolean = false;
|
|
11
|
-
const mockContext: any = {
|
|
12
|
-
report: (options: any): void => {
|
|
13
|
-
reportCalled = true;
|
|
14
|
-
expect(options.messageId).toBe('effectSignalLoop');
|
|
15
|
-
expect(options.data.signalName).toBe('count_$');
|
|
16
|
-
},
|
|
17
|
-
options: [],
|
|
18
|
-
};
|
|
19
|
-
const rule: any = effectSignalLoopRule.create(mockContext);
|
|
20
|
-
const mockNode: any = {
|
|
21
|
-
callee: { type: 'Identifier', name: 'effect' },
|
|
22
|
-
arguments: [
|
|
23
|
-
{
|
|
24
|
-
type: 'ArrowFunctionExpression',
|
|
25
|
-
body: {
|
|
26
|
-
type: 'BlockStatement',
|
|
27
|
-
body: [
|
|
28
|
-
{
|
|
29
|
-
type: 'ExpressionStatement',
|
|
30
|
-
expression: {
|
|
31
|
-
type: 'CallExpression',
|
|
32
|
-
callee: { type: 'Identifier', name: 'count_$' },
|
|
33
|
-
arguments: [],
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
type: 'ExpressionStatement',
|
|
38
|
-
expression: {
|
|
39
|
-
type: 'CallExpression',
|
|
40
|
-
callee: {
|
|
41
|
-
type: 'MemberExpression',
|
|
42
|
-
object: { type: 'Identifier', name: 'count_$' },
|
|
43
|
-
property: { type: 'Identifier', name: 'set' },
|
|
44
|
-
},
|
|
45
|
-
arguments: [{ type: 'Literal', value: 1 }],
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
};
|
|
53
|
-
rule.CallExpression(mockNode);
|
|
54
|
-
expect(reportCalled).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('| should not report when only reading a signal', () => {
|
|
58
|
-
let reportCalled: boolean = false;
|
|
59
|
-
const mockContext: any = { report: () => { reportCalled = true; }, options: [] };
|
|
60
|
-
const rule: any = effectSignalLoopRule.create(mockContext);
|
|
61
|
-
const mockNode: any = {
|
|
62
|
-
callee: { type: 'Identifier', name: 'effect' },
|
|
63
|
-
arguments: [
|
|
64
|
-
{
|
|
65
|
-
type: 'ArrowFunctionExpression',
|
|
66
|
-
body: {
|
|
67
|
-
type: 'CallExpression',
|
|
68
|
-
callee: { type: 'Identifier', name: 'count_$' },
|
|
69
|
-
arguments: [],
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
rule.CallExpression(mockNode);
|
|
75
|
-
expect(reportCalled).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('| should ignore non-effect calls', () => {
|
|
79
|
-
let reportCalled: boolean = false;
|
|
80
|
-
const mockContext: any = { report: () => { reportCalled = true; }, options: [] };
|
|
81
|
-
const rule: any = effectSignalLoopRule.create(mockContext);
|
|
82
|
-
const mockNode: any = {
|
|
83
|
-
callee: { type: 'Identifier', name: 'computed' },
|
|
84
|
-
arguments: [],
|
|
85
|
-
};
|
|
86
|
-
rule.CallExpression(mockNode);
|
|
87
|
-
expect(reportCalled).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
1
|
+
import effectSignalLoopRule from './effect-signal-loop';
|
|
2
|
+
|
|
3
|
+
describe('| effect-signal-loop', () => {
|
|
4
|
+
it('| should be a valid ESLint rule', () => {
|
|
5
|
+
expect(effectSignalLoopRule.meta?.type).toBe('problem');
|
|
6
|
+
expect(effectSignalLoopRule.meta?.messages?.effectSignalLoop).toBeDefined();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('| should report when same signal is read AND written in effect', () => {
|
|
10
|
+
let reportCalled: boolean = false;
|
|
11
|
+
const mockContext: any = {
|
|
12
|
+
report: (options: any): void => {
|
|
13
|
+
reportCalled = true;
|
|
14
|
+
expect(options.messageId).toBe('effectSignalLoop');
|
|
15
|
+
expect(options.data.signalName).toBe('count_$');
|
|
16
|
+
},
|
|
17
|
+
options: [],
|
|
18
|
+
};
|
|
19
|
+
const rule: any = effectSignalLoopRule.create(mockContext);
|
|
20
|
+
const mockNode: any = {
|
|
21
|
+
callee: { type: 'Identifier', name: 'effect' },
|
|
22
|
+
arguments: [
|
|
23
|
+
{
|
|
24
|
+
type: 'ArrowFunctionExpression',
|
|
25
|
+
body: {
|
|
26
|
+
type: 'BlockStatement',
|
|
27
|
+
body: [
|
|
28
|
+
{
|
|
29
|
+
type: 'ExpressionStatement',
|
|
30
|
+
expression: {
|
|
31
|
+
type: 'CallExpression',
|
|
32
|
+
callee: { type: 'Identifier', name: 'count_$' },
|
|
33
|
+
arguments: [],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'ExpressionStatement',
|
|
38
|
+
expression: {
|
|
39
|
+
type: 'CallExpression',
|
|
40
|
+
callee: {
|
|
41
|
+
type: 'MemberExpression',
|
|
42
|
+
object: { type: 'Identifier', name: 'count_$' },
|
|
43
|
+
property: { type: 'Identifier', name: 'set' },
|
|
44
|
+
},
|
|
45
|
+
arguments: [{ type: 'Literal', value: 1 }],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
rule.CallExpression(mockNode);
|
|
54
|
+
expect(reportCalled).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('| should not report when only reading a signal', () => {
|
|
58
|
+
let reportCalled: boolean = false;
|
|
59
|
+
const mockContext: any = { report: () => { reportCalled = true; }, options: [] };
|
|
60
|
+
const rule: any = effectSignalLoopRule.create(mockContext);
|
|
61
|
+
const mockNode: any = {
|
|
62
|
+
callee: { type: 'Identifier', name: 'effect' },
|
|
63
|
+
arguments: [
|
|
64
|
+
{
|
|
65
|
+
type: 'ArrowFunctionExpression',
|
|
66
|
+
body: {
|
|
67
|
+
type: 'CallExpression',
|
|
68
|
+
callee: { type: 'Identifier', name: 'count_$' },
|
|
69
|
+
arguments: [],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
rule.CallExpression(mockNode);
|
|
75
|
+
expect(reportCalled).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('| should ignore non-effect calls', () => {
|
|
79
|
+
let reportCalled: boolean = false;
|
|
80
|
+
const mockContext: any = { report: () => { reportCalled = true; }, options: [] };
|
|
81
|
+
const rule: any = effectSignalLoopRule.create(mockContext);
|
|
82
|
+
const mockNode: any = {
|
|
83
|
+
callee: { type: 'Identifier', name: 'computed' },
|
|
84
|
+
arguments: [],
|
|
85
|
+
};
|
|
86
|
+
rule.CallExpression(mockNode);
|
|
87
|
+
expect(reportCalled).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
import { Rule } from 'eslint';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Adott AST node alá tartozó signal olvasások / írások begyűjtése.
|
|
5
|
-
* Olvasás: `something_$()` hívás (callee Identifier `*_$` névvel vagy
|
|
6
|
-
* MemberExpression `.foo_$()` property-vel).
|
|
7
|
-
* Írás: `something_$.set(...)` vagy `something_$.update(...)`.
|
|
8
|
-
*/
|
|
9
|
-
function collectSignals(
|
|
10
|
-
rootNode: any,
|
|
11
|
-
reads: Set<string>,
|
|
12
|
-
writes: Set<string>,
|
|
13
|
-
): void {
|
|
14
|
-
if (!rootNode || typeof rootNode !== 'object') {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (rootNode.type === 'CallExpression') {
|
|
19
|
-
const callee: any = rootNode.callee;
|
|
20
|
-
// Signal olvasás: `name_$()` direkt hívás (Identifier callee)
|
|
21
|
-
if (callee && callee.type === 'Identifier' && /_\$$/.test(callee.name)) {
|
|
22
|
-
reads.add(callee.name);
|
|
23
|
-
}
|
|
24
|
-
// Signal olvasás: `this.name_$()` vagy `obj.name_$()`
|
|
25
|
-
if (
|
|
26
|
-
callee
|
|
27
|
-
&& callee.type === 'MemberExpression'
|
|
28
|
-
&& callee.property
|
|
29
|
-
&& callee.property.type === 'Identifier'
|
|
30
|
-
&& /_\$$/.test(callee.property.name)
|
|
31
|
-
) {
|
|
32
|
-
reads.add(callee.property.name);
|
|
33
|
-
}
|
|
34
|
-
// Signal írás: `name_$.set(...)` / `name_$.update(...)`
|
|
35
|
-
if (
|
|
36
|
-
callee
|
|
37
|
-
&& callee.type === 'MemberExpression'
|
|
38
|
-
&& callee.property
|
|
39
|
-
&& callee.property.type === 'Identifier'
|
|
40
|
-
&& (callee.property.name === 'set' || callee.property.name === 'update')
|
|
41
|
-
) {
|
|
42
|
-
const obj: any = callee.object;
|
|
43
|
-
if (obj && obj.type === 'Identifier' && /_\$$/.test(obj.name)) {
|
|
44
|
-
writes.add(obj.name);
|
|
45
|
-
}
|
|
46
|
-
if (
|
|
47
|
-
obj
|
|
48
|
-
&& obj.type === 'MemberExpression'
|
|
49
|
-
&& obj.property
|
|
50
|
-
&& obj.property.type === 'Identifier'
|
|
51
|
-
&& /_\$$/.test(obj.property.name)
|
|
52
|
-
) {
|
|
53
|
-
writes.add(obj.property.name);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (const key in rootNode) {
|
|
59
|
-
if (key === 'parent' || key === 'loc' || key === 'range') {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const value: any = rootNode[key];
|
|
63
|
-
if (Array.isArray(value)) {
|
|
64
|
-
for (const item of value) {
|
|
65
|
-
collectSignals(item, reads, writes);
|
|
66
|
-
}
|
|
67
|
-
} else if (value && typeof value === 'object' && typeof value.type === 'string') {
|
|
68
|
-
collectSignals(value, reads, writes);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Effect-signal-loop szabály: detektálja azt az `effect(...)` hívást ami
|
|
75
|
-
* ugyanazt a signal-t olvassa (dependency-ként) és írja (`.set` / `.update`).
|
|
76
|
-
* Ez végtelen loop-ot okozna, mert a write újra triggereli az effect-et.
|
|
77
|
-
* CCAP "effect-signal-loop" review ESLint AST-portja.
|
|
78
|
-
*/
|
|
79
|
-
const rule: Rule.RuleModule = {
|
|
80
|
-
meta: {
|
|
81
|
-
type: 'problem',
|
|
82
|
-
docs: {
|
|
83
|
-
description: 'Detect `effect()` callbacks that read and write the same signal — infinite loop risk.',
|
|
84
|
-
recommended: true,
|
|
85
|
-
},
|
|
86
|
-
schema: [],
|
|
87
|
-
messages: {
|
|
88
|
-
effectSignalLoop:
|
|
89
|
-
'Effect-signal loop: `{{signalName}}` olvasva ÉS írva (.set/.update) ugyanabban az `effect()`-ben. '
|
|
90
|
-
+ 'Végtelen újrafutás veszélye — a signal-írás újra triggereli az effect-et.',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
create(context: Rule.RuleContext): Rule.RuleListener {
|
|
94
|
-
return {
|
|
95
|
-
CallExpression(node: any): void {
|
|
96
|
-
try {
|
|
97
|
-
const callee: any = node.callee;
|
|
98
|
-
if (!callee || callee.type !== 'Identifier' || callee.name !== 'effect') {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const firstArg: any = node.arguments && node.arguments[0];
|
|
102
|
-
if (!firstArg) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const reads: Set<string> = new Set<string>();
|
|
106
|
-
const writes: Set<string> = new Set<string>();
|
|
107
|
-
collectSignals(firstArg, reads, writes);
|
|
108
|
-
for (const signalName of writes) {
|
|
109
|
-
if (reads.has(signalName)) {
|
|
110
|
-
context.report({
|
|
111
|
-
node: node,
|
|
112
|
-
messageId: 'effectSignalLoop',
|
|
113
|
-
data: { signalName: signalName },
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
} catch (error) {
|
|
118
|
-
console.error('[effect-signal-loop] Error in CallExpression visitor:', error);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export default rule;
|
|
1
|
+
import { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adott AST node alá tartozó signal olvasások / írások begyűjtése.
|
|
5
|
+
* Olvasás: `something_$()` hívás (callee Identifier `*_$` névvel vagy
|
|
6
|
+
* MemberExpression `.foo_$()` property-vel).
|
|
7
|
+
* Írás: `something_$.set(...)` vagy `something_$.update(...)`.
|
|
8
|
+
*/
|
|
9
|
+
function collectSignals(
|
|
10
|
+
rootNode: any,
|
|
11
|
+
reads: Set<string>,
|
|
12
|
+
writes: Set<string>,
|
|
13
|
+
): void {
|
|
14
|
+
if (!rootNode || typeof rootNode !== 'object') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (rootNode.type === 'CallExpression') {
|
|
19
|
+
const callee: any = rootNode.callee;
|
|
20
|
+
// Signal olvasás: `name_$()` direkt hívás (Identifier callee)
|
|
21
|
+
if (callee && callee.type === 'Identifier' && /_\$$/.test(callee.name)) {
|
|
22
|
+
reads.add(callee.name);
|
|
23
|
+
}
|
|
24
|
+
// Signal olvasás: `this.name_$()` vagy `obj.name_$()`
|
|
25
|
+
if (
|
|
26
|
+
callee
|
|
27
|
+
&& callee.type === 'MemberExpression'
|
|
28
|
+
&& callee.property
|
|
29
|
+
&& callee.property.type === 'Identifier'
|
|
30
|
+
&& /_\$$/.test(callee.property.name)
|
|
31
|
+
) {
|
|
32
|
+
reads.add(callee.property.name);
|
|
33
|
+
}
|
|
34
|
+
// Signal írás: `name_$.set(...)` / `name_$.update(...)`
|
|
35
|
+
if (
|
|
36
|
+
callee
|
|
37
|
+
&& callee.type === 'MemberExpression'
|
|
38
|
+
&& callee.property
|
|
39
|
+
&& callee.property.type === 'Identifier'
|
|
40
|
+
&& (callee.property.name === 'set' || callee.property.name === 'update')
|
|
41
|
+
) {
|
|
42
|
+
const obj: any = callee.object;
|
|
43
|
+
if (obj && obj.type === 'Identifier' && /_\$$/.test(obj.name)) {
|
|
44
|
+
writes.add(obj.name);
|
|
45
|
+
}
|
|
46
|
+
if (
|
|
47
|
+
obj
|
|
48
|
+
&& obj.type === 'MemberExpression'
|
|
49
|
+
&& obj.property
|
|
50
|
+
&& obj.property.type === 'Identifier'
|
|
51
|
+
&& /_\$$/.test(obj.property.name)
|
|
52
|
+
) {
|
|
53
|
+
writes.add(obj.property.name);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const key in rootNode) {
|
|
59
|
+
if (key === 'parent' || key === 'loc' || key === 'range') {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const value: any = rootNode[key];
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
for (const item of value) {
|
|
65
|
+
collectSignals(item, reads, writes);
|
|
66
|
+
}
|
|
67
|
+
} else if (value && typeof value === 'object' && typeof value.type === 'string') {
|
|
68
|
+
collectSignals(value, reads, writes);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Effect-signal-loop szabály: detektálja azt az `effect(...)` hívást ami
|
|
75
|
+
* ugyanazt a signal-t olvassa (dependency-ként) és írja (`.set` / `.update`).
|
|
76
|
+
* Ez végtelen loop-ot okozna, mert a write újra triggereli az effect-et.
|
|
77
|
+
* CCAP "effect-signal-loop" review ESLint AST-portja.
|
|
78
|
+
*/
|
|
79
|
+
const rule: Rule.RuleModule = {
|
|
80
|
+
meta: {
|
|
81
|
+
type: 'problem',
|
|
82
|
+
docs: {
|
|
83
|
+
description: 'Detect `effect()` callbacks that read and write the same signal — infinite loop risk.',
|
|
84
|
+
recommended: true,
|
|
85
|
+
},
|
|
86
|
+
schema: [],
|
|
87
|
+
messages: {
|
|
88
|
+
effectSignalLoop:
|
|
89
|
+
'Effect-signal loop: `{{signalName}}` olvasva ÉS írva (.set/.update) ugyanabban az `effect()`-ben. '
|
|
90
|
+
+ 'Végtelen újrafutás veszélye — a signal-írás újra triggereli az effect-et.',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
create(context: Rule.RuleContext): Rule.RuleListener {
|
|
94
|
+
return {
|
|
95
|
+
CallExpression(node: any): void {
|
|
96
|
+
try {
|
|
97
|
+
const callee: any = node.callee;
|
|
98
|
+
if (!callee || callee.type !== 'Identifier' || callee.name !== 'effect') {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const firstArg: any = node.arguments && node.arguments[0];
|
|
102
|
+
if (!firstArg) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const reads: Set<string> = new Set<string>();
|
|
106
|
+
const writes: Set<string> = new Set<string>();
|
|
107
|
+
collectSignals(firstArg, reads, writes);
|
|
108
|
+
for (const signalName of writes) {
|
|
109
|
+
if (reads.has(signalName)) {
|
|
110
|
+
context.report({
|
|
111
|
+
node: node,
|
|
112
|
+
messageId: 'effectSignalLoop',
|
|
113
|
+
data: { signalName: signalName },
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error('[effect-signal-loop] Error in CallExpression visitor:', error);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default rule;
|