@futdevpro/dynamo-eslint 1.15.6 → 1.15.8
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/.cursor/rules/_ag_frontend-structure.mdc +5 -5
- package/.dynamo/version-bump.config.json +5 -0
- package/.github/workflows/main.yml +424 -395
- package/.husky/pre-commit +1 -0
- package/__documentations/2026-04-18-ccap-review-integration.md +173 -0
- package/build/configs/base.js +20 -1
- package/build/configs/base.js.map +1 -1
- package/build/configs/ngx.js +10 -0
- package/build/configs/ngx.js.map +1 -1
- package/build/plugin/index.d.ts +21 -0
- package/build/plugin/index.d.ts.map +1 -1
- package/build/plugin/index.js +38 -0
- package/build/plugin/index.js.map +1 -1
- package/build/plugin/rules/angular/angular-for-track-logic.d.ts +8 -0
- package/build/plugin/rules/angular/angular-for-track-logic.d.ts.map +1 -0
- package/build/plugin/rules/angular/angular-for-track-logic.js +82 -0
- package/build/plugin/rules/angular/angular-for-track-logic.js.map +1 -0
- package/build/plugin/rules/angular/effect-signal-loop.d.ts +10 -0
- package/build/plugin/rules/angular/effect-signal-loop.d.ts.map +1 -0
- package/build/plugin/rules/angular/effect-signal-loop.js +113 -0
- package/build/plugin/rules/angular/effect-signal-loop.js.map +1 -0
- package/build/plugin/rules/angular/no-async-ngoninit.d.ts +9 -0
- package/build/plugin/rules/angular/no-async-ngoninit.d.ts.map +1 -0
- package/build/plugin/rules/angular/no-async-ngoninit.js +43 -0
- package/build/plugin/rules/angular/no-async-ngoninit.js.map +1 -0
- package/build/plugin/rules/angular/no-component-direct-api.d.ts +10 -0
- package/build/plugin/rules/angular/no-component-direct-api.d.ts.map +1 -0
- package/build/plugin/rules/angular/no-component-direct-api.js +76 -0
- package/build/plugin/rules/angular/no-component-direct-api.js.map +1 -0
- package/build/plugin/rules/angular/no-method-call-in-template.d.ts +9 -0
- package/build/plugin/rules/angular/no-method-call-in-template.d.ts.map +1 -0
- package/build/plugin/rules/angular/no-method-call-in-template.js +80 -0
- package/build/plugin/rules/angular/no-method-call-in-template.js.map +1 -0
- package/build/plugin/rules/angular/no-ngfor-directive.d.ts +8 -0
- package/build/plugin/rules/angular/no-ngfor-directive.d.ts.map +1 -0
- package/build/plugin/rules/angular/no-ngfor-directive.js +60 -0
- package/build/plugin/rules/angular/no-ngfor-directive.js.map +1 -0
- package/build/plugin/rules/angular/no-ngif-directive.d.ts +8 -0
- package/build/plugin/rules/angular/no-ngif-directive.d.ts.map +1 -0
- package/build/plugin/rules/angular/no-ngif-directive.js +60 -0
- package/build/plugin/rules/angular/no-ngif-directive.js.map +1 -0
- package/build/plugin/rules/naming-patterns.d.ts +4 -0
- package/build/plugin/rules/naming-patterns.d.ts.map +1 -1
- package/build/plugin/rules/naming-patterns.js +331 -8
- package/build/plugin/rules/naming-patterns.js.map +1 -1
- package/build/plugin/rules/no-getter-logic.d.ts.map +1 -1
- package/build/plugin/rules/no-getter-logic.js +21 -2
- package/build/plugin/rules/no-getter-logic.js.map +1 -1
- package/build/plugin/rules/require-jsdoc-description.d.ts.map +1 -1
- package/build/plugin/rules/require-jsdoc-description.js +17 -0
- package/build/plugin/rules/require-jsdoc-description.js.map +1 -1
- package/build/plugin/rules/ts/data-model-extends.d.ts +9 -0
- package/build/plugin/rules/ts/data-model-extends.d.ts.map +1 -0
- package/build/plugin/rules/ts/data-model-extends.js +95 -0
- package/build/plugin/rules/ts/data-model-extends.js.map +1 -0
- package/build/plugin/rules/ts/no-any-type.d.ts +9 -0
- package/build/plugin/rules/ts/no-any-type.d.ts.map +1 -0
- package/build/plugin/rules/ts/no-any-type.js +37 -0
- package/build/plugin/rules/ts/no-any-type.js.map +1 -0
- package/build/plugin/rules/ts/no-as-cast.d.ts +9 -0
- package/build/plugin/rules/ts/no-as-cast.d.ts.map +1 -0
- package/build/plugin/rules/ts/no-as-cast.js +50 -0
- package/build/plugin/rules/ts/no-as-cast.js.map +1 -0
- package/build/plugin/rules/ts/no-dynamic-imports.d.ts +9 -0
- package/build/plugin/rules/ts/no-dynamic-imports.d.ts.map +1 -0
- package/build/plugin/rules/ts/no-dynamic-imports.js +51 -0
- package/build/plugin/rules/ts/no-dynamic-imports.js.map +1 -0
- package/build/plugin/rules/ts/no-native-browser-dialogs.d.ts +9 -0
- package/build/plugin/rules/ts/no-native-browser-dialogs.d.ts.map +1 -0
- package/build/plugin/rules/ts/no-native-browser-dialogs.js +79 -0
- package/build/plugin/rules/ts/no-native-browser-dialogs.js.map +1 -0
- package/build/plugin/rules/ts/no-plain-function-export.d.ts +10 -0
- package/build/plugin/rules/ts/no-plain-function-export.d.ts.map +1 -0
- package/build/plugin/rules/ts/no-plain-function-export.js +70 -0
- package/build/plugin/rules/ts/no-plain-function-export.js.map +1 -0
- package/build/plugin/rules/ts/one-export-per-file.d.ts +9 -0
- package/build/plugin/rules/ts/one-export-per-file.d.ts.map +1 -0
- package/build/plugin/rules/ts/one-export-per-file.js +74 -0
- package/build/plugin/rules/ts/one-export-per-file.js.map +1 -0
- package/package.json +6 -9
- package/pipeline.cicd.config.json +152 -0
- package/src/configs/base.ts +21 -1
- package/src/configs/ngx.ts +12 -0
- package/src/plugin/index.ts +44 -3
- package/src/plugin/rules/angular/angular-for-track-logic.spec.ts +44 -0
- package/src/plugin/rules/angular/angular-for-track-logic.ts +88 -0
- package/src/plugin/rules/angular/effect-signal-loop.spec.ts +89 -0
- package/src/plugin/rules/angular/effect-signal-loop.ts +125 -0
- package/src/plugin/rules/angular/no-async-ngoninit.spec.ts +50 -0
- package/src/plugin/rules/angular/no-async-ngoninit.ts +43 -0
- package/src/plugin/rules/angular/no-component-direct-api.spec.ts +78 -0
- package/src/plugin/rules/angular/no-component-direct-api.ts +82 -0
- package/src/plugin/rules/angular/no-method-call-in-template.spec.ts +63 -0
- package/src/plugin/rules/angular/no-method-call-in-template.ts +89 -0
- package/src/plugin/rules/angular/no-ngfor-directive.spec.ts +44 -0
- package/src/plugin/rules/angular/no-ngfor-directive.ts +62 -0
- package/src/plugin/rules/angular/no-ngif-directive.spec.ts +44 -0
- package/src/plugin/rules/angular/no-ngif-directive.ts +62 -0
- package/src/plugin/rules/naming-patterns.spec.ts +108 -22
- package/src/plugin/rules/naming-patterns.ts +390 -11
- package/src/plugin/rules/no-getter-logic.spec.ts +71 -0
- package/src/plugin/rules/no-getter-logic.ts +21 -2
- package/src/plugin/rules/require-jsdoc-description.spec.ts +1 -0
- package/src/plugin/rules/require-jsdoc-description.ts +19 -0
- package/src/plugin/rules/ts/data-model-extends.spec.ts +84 -0
- package/src/plugin/rules/ts/data-model-extends.ts +100 -0
- package/src/plugin/rules/ts/no-any-type.spec.ts +28 -0
- package/src/plugin/rules/ts/no-any-type.ts +36 -0
- package/src/plugin/rules/ts/no-as-cast.spec.ts +51 -0
- package/src/plugin/rules/ts/no-as-cast.ts +51 -0
- package/src/plugin/rules/ts/no-dynamic-imports.spec.ts +54 -0
- package/src/plugin/rules/ts/no-dynamic-imports.ts +49 -0
- package/src/plugin/rules/ts/no-native-browser-dialogs.spec.ts +54 -0
- package/src/plugin/rules/ts/no-native-browser-dialogs.ts +84 -0
- package/src/plugin/rules/ts/no-plain-function-export.spec.ts +72 -0
- package/src/plugin/rules/ts/no-plain-function-export.ts +73 -0
- package/src/plugin/rules/ts/one-export-per-file.spec.ts +64 -0
- package/src/plugin/rules/ts/one-export-per-file.ts +77 -0
- package/futdevpro-dynamo-eslint-1.15.6.tgz +0 -0
|
@@ -6,36 +6,122 @@ describe('| naming-patterns', () => {
|
|
|
6
6
|
expect(namingPatternsRule.meta?.docs?.description).toContain('naming conventions');
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
it('| should
|
|
10
|
-
const mockContext = {
|
|
9
|
+
it('| should expose PropertyDefinition / ClassDeclaration / TSEnumDeclaration visitors for non-spec files', () => {
|
|
10
|
+
const mockContext: any = {
|
|
11
|
+
filename: '/x/foo.ts',
|
|
11
12
|
report: () => {},
|
|
12
|
-
|
|
13
|
+
options: [],
|
|
14
|
+
};
|
|
15
|
+
const result: any = namingPatternsRule.create(mockContext);
|
|
16
|
+
expect(typeof result.PropertyDefinition).toBe('function');
|
|
17
|
+
expect(typeof result.ClassDeclaration).toBe('function');
|
|
18
|
+
expect(typeof result.TSEnumDeclaration).toBe('function');
|
|
19
|
+
});
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
it('| should skip .spec.ts files entirely', () => {
|
|
22
|
+
const mockContext: any = {
|
|
23
|
+
filename: '/x/foo.spec.ts',
|
|
24
|
+
report: () => {},
|
|
25
|
+
options: [],
|
|
26
|
+
};
|
|
27
|
+
const result: any = namingPatternsRule.create(mockContext);
|
|
28
|
+
expect(result.PropertyDefinition).toBeUndefined();
|
|
29
|
+
});
|
|
15
30
|
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
it('| should report class without required postfix in *.data-model.ts', () => {
|
|
32
|
+
let reportCalled: boolean = false;
|
|
33
|
+
const mockContext: any = {
|
|
34
|
+
filename: '/x/user.data-model.ts',
|
|
35
|
+
report: (options: any): void => {
|
|
36
|
+
if (options.messageId === 'fileClassPostfix') {
|
|
37
|
+
reportCalled = true;
|
|
38
|
+
expect(options.data.requiredPostfix).toBe('_DataModel');
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
options: [],
|
|
42
|
+
};
|
|
43
|
+
const rule: any = namingPatternsRule.create(mockContext);
|
|
44
|
+
const mockNode: any = { id: { name: 'User' } };
|
|
45
|
+
rule.ClassDeclaration(mockNode);
|
|
46
|
+
expect(reportCalled).toBe(true);
|
|
18
47
|
});
|
|
19
48
|
|
|
20
|
-
it('| should
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
it('| should NOT report class with correct postfix in *.data-model.ts', () => {
|
|
50
|
+
let reportCalled: boolean = false;
|
|
51
|
+
const mockContext: any = {
|
|
52
|
+
filename: '/x/user.data-model.ts',
|
|
53
|
+
report: (options: any): void => {
|
|
54
|
+
if (options.messageId === 'fileClassPostfix') {
|
|
55
|
+
reportCalled = true;
|
|
56
|
+
}
|
|
25
57
|
},
|
|
26
|
-
|
|
58
|
+
options: [],
|
|
59
|
+
};
|
|
60
|
+
const rule: any = namingPatternsRule.create(mockContext);
|
|
61
|
+
const mockNode: any = { id: { name: 'User_DataModel' } };
|
|
62
|
+
rule.ClassDeclaration(mockNode);
|
|
63
|
+
expect(reportCalled).toBe(false);
|
|
64
|
+
});
|
|
27
65
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
66
|
+
it('| should report non-camelCase enum key in *.type-enum.ts', () => {
|
|
67
|
+
let reportCalled: boolean = false;
|
|
68
|
+
const mockContext: any = {
|
|
69
|
+
filename: '/x/user-status.type-enum.ts',
|
|
70
|
+
report: (options: any): void => {
|
|
71
|
+
if (options.messageId === 'enumKeyCamel') {
|
|
72
|
+
reportCalled = true;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
options: [],
|
|
76
|
+
};
|
|
77
|
+
const rule: any = namingPatternsRule.create(mockContext);
|
|
78
|
+
const mockNode: any = {
|
|
79
|
+
members: [
|
|
80
|
+
{ id: { name: 'NotCamelCase' }, initializer: null },
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
rule.TSEnumDeclaration(mockNode);
|
|
84
|
+
expect(reportCalled).toBe(true);
|
|
85
|
+
});
|
|
33
86
|
|
|
34
|
-
|
|
87
|
+
it('| should report non-kebab-case string value in enum', () => {
|
|
88
|
+
let reportCalled: boolean = false;
|
|
89
|
+
const mockContext: any = {
|
|
90
|
+
filename: '/x/user-status.type-enum.ts',
|
|
91
|
+
report: (options: any): void => {
|
|
92
|
+
if (options.messageId === 'enumValueKebab') {
|
|
93
|
+
reportCalled = true;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
options: [],
|
|
97
|
+
};
|
|
98
|
+
const rule: any = namingPatternsRule.create(mockContext);
|
|
99
|
+
const mockNode: any = {
|
|
100
|
+
members: [
|
|
101
|
+
{
|
|
102
|
+
id: { name: 'activeUser' },
|
|
103
|
+
initializer: { type: 'Literal', value: 'NotKebabCase' },
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
rule.TSEnumDeclaration(mockNode);
|
|
108
|
+
expect(reportCalled).toBe(true);
|
|
109
|
+
});
|
|
35
110
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
111
|
+
it('| should respect `checks` option and disable booleanIsPrefix', () => {
|
|
112
|
+
let reportCalled: boolean = false;
|
|
113
|
+
const mockContext: any = {
|
|
114
|
+
filename: '/x/user.ts',
|
|
115
|
+
report: () => { reportCalled = true; },
|
|
116
|
+
options: [{ checks: { booleanIsPrefix: false }}],
|
|
117
|
+
};
|
|
118
|
+
const rule: any = namingPatternsRule.create(mockContext);
|
|
119
|
+
const mockNode: any = {
|
|
120
|
+
key: { type: 'Identifier', name: 'active' },
|
|
121
|
+
typeAnnotation: { typeAnnotation: { type: 'TSBooleanKeyword' }},
|
|
122
|
+
value: null,
|
|
123
|
+
};
|
|
124
|
+
rule.PropertyDefinition(mockNode);
|
|
125
|
+
expect(reportCalled).toBe(false);
|
|
40
126
|
});
|
|
41
127
|
});
|
|
@@ -1,23 +1,404 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
1
2
|
import { Rule } from 'eslint';
|
|
2
|
-
// import * as dyfmUtils from '@futdevpro/fsm-dynamo';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Konfigurálható al-ellenőrzések — alapból minden bekapcsolva.
|
|
6
|
+
* Eredete: CCAP "naming/*" review-k (boolean-is-prefix, signal-postfix, rxjs-postfix,
|
|
7
|
+
* file-class-postfix, enum-value-format, service-property-postfix,
|
|
8
|
+
* file-class-name-consistency).
|
|
9
|
+
*/
|
|
10
|
+
interface NamingChecksOptions {
|
|
11
|
+
booleanIsPrefix?: boolean;
|
|
12
|
+
signalPostfix?: boolean;
|
|
13
|
+
rxjsPostfix?: boolean;
|
|
14
|
+
fileClassPostfix?: boolean;
|
|
15
|
+
enumValueFormat?: boolean;
|
|
16
|
+
servicePropertyPostfix?: boolean;
|
|
17
|
+
fileClassNameConsistency?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Fájlminta → kötelező class postfix leképezés (CCAP file-class-postfix).
|
|
22
|
+
*/
|
|
23
|
+
const FILE_POSTFIX_MAP: { pattern: RegExp; classPostfix: string; entitySuffix: string }[] = [
|
|
24
|
+
{ pattern: /\.data-model\.ts$/, classPostfix: '_DataModel', entitySuffix: '.data-model.ts' },
|
|
25
|
+
{ pattern: /\.control-model\.ts$/, classPostfix: '_ControlModel', entitySuffix: '.control-model.ts' },
|
|
26
|
+
{ pattern: /\.control-service\.ts$/, classPostfix: '_ControlService', entitySuffix: '.control-service.ts' },
|
|
27
|
+
{ pattern: /\.data-service\.ts$/, classPostfix: '_DataService', entitySuffix: '.data-service.ts' },
|
|
28
|
+
{ pattern: /\.api-service\.ts$/, classPostfix: '_ApiService', entitySuffix: '.api-service.ts' },
|
|
29
|
+
{ pattern: /\.util-service\.ts$/, classPostfix: '_Util', entitySuffix: '.util-service.ts' },
|
|
30
|
+
{ pattern: /\.service-base\.ts$/, classPostfix: '_ServiceBase', entitySuffix: '.service-base.ts' },
|
|
31
|
+
{ pattern: /\.controller\.ts$/, classPostfix: '_Controller', entitySuffix: '.controller.ts' },
|
|
32
|
+
{ pattern: /\.component\.ts$/, classPostfix: '_Component', entitySuffix: '.component.ts' },
|
|
33
|
+
{ pattern: /\.pipe\.ts$/, classPostfix: '_Pipe', entitySuffix: '.pipe.ts' },
|
|
34
|
+
{ pattern: /\.directive\.ts$/, classPostfix: '_Directive', entitySuffix: '.directive.ts' },
|
|
35
|
+
{ pattern: /\.module\.ts$/, classPostfix: '_Module', entitySuffix: '.module.ts' },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/** Service class postfix → kötelező inject property postfix leképezés (CCAP service-property-postfix). */
|
|
39
|
+
const SERVICE_INJECT_POSTFIX_MAP: { classPostfix: string; propertyPostfix: string }[] = [
|
|
40
|
+
{ classPostfix: '_DataService', propertyPostfix: '_DS' },
|
|
41
|
+
{ classPostfix: '_ControlService', propertyPostfix: '_CS' },
|
|
42
|
+
{ classPostfix: '_ApiService', propertyPostfix: '_AS' },
|
|
43
|
+
{ classPostfix: '_MasterService', propertyPostfix: '_MS' },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/** Signal factory függvény nevek (CCAP signal-postfix). */
|
|
47
|
+
const SIGNAL_FACTORY_NAMES: Set<string> = new Set<string>([ 'signal', 'computed', 'toSignal' ]);
|
|
48
|
+
|
|
49
|
+
/** RxJS típusnevek detektáláshoz. */
|
|
50
|
+
const RXJS_BEHAVIOR_SUBJECT_NAME: string = 'BehaviorSubject';
|
|
51
|
+
const RXJS_SUBJECT_NAME: string = 'Subject';
|
|
52
|
+
const RXJS_OBSERVABLE_NAME: string = 'Observable';
|
|
53
|
+
|
|
54
|
+
/** camelCase enum kulcs regex. */
|
|
55
|
+
const CAMEL_CASE_KEY_REGEX: RegExp = /^[a-z][a-zA-Z0-9]*$/;
|
|
56
|
+
|
|
57
|
+
/** kebab-case enum érték regex. */
|
|
58
|
+
const KEBAB_CASE_VALUE_REGEX: RegExp = /^[a-z0-9][a-z0-9-]*$/;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* PascalCase szót kebab-case-re konvertál (CCAP file-class-name-consistency).
|
|
62
|
+
*/
|
|
63
|
+
function pascalPartToKebab(str: string): string {
|
|
64
|
+
if (str === str.toUpperCase() && str.length > 1) {
|
|
65
|
+
return str.toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
return str
|
|
68
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
69
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
70
|
+
.toLowerCase();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Class entity nevet kebab-case fájlnév entity részére konvertál.
|
|
75
|
+
*/
|
|
76
|
+
function classEntityToKebab(classEntity: string): string {
|
|
77
|
+
const parts: string[] = classEntity.split('_').filter((p: string): boolean => p.length > 0);
|
|
78
|
+
return parts.map(pascalPartToKebab).join('-');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Megnézi, hogy a property type-annotation `boolean`-e.
|
|
83
|
+
*/
|
|
84
|
+
function isBooleanType(typeAnnotation: any): boolean {
|
|
85
|
+
if (!typeAnnotation || !typeAnnotation.typeAnnotation) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return typeAnnotation.typeAnnotation.type === 'TSBooleanKeyword';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Megnézi, hogy a property init signal/computed/toSignal hívás-e.
|
|
93
|
+
*/
|
|
94
|
+
function isSignalFactoryCall(init: any): boolean {
|
|
95
|
+
if (!init || init.type !== 'CallExpression') {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const callee: any = init.callee;
|
|
99
|
+
if (!callee || callee.type !== 'Identifier') {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return SIGNAL_FACTORY_NAMES.has(callee.name);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Detektálja az RxJS típust property type-annotation vagy `new XSubject()` init alapján.
|
|
107
|
+
*/
|
|
108
|
+
function detectRxjsKind(typeAnnotation: any, init: any): 'BS' | 'S' | 'OBS' | null {
|
|
109
|
+
const typeName: string | null = (() => {
|
|
110
|
+
if (!typeAnnotation || !typeAnnotation.typeAnnotation) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const t: any = typeAnnotation.typeAnnotation;
|
|
114
|
+
if (t.type !== 'TSTypeReference' || !t.typeName) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
if (t.typeName.type === 'Identifier') {
|
|
118
|
+
return t.typeName.name;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
})();
|
|
122
|
+
|
|
123
|
+
const newName: string | null = (() => {
|
|
124
|
+
if (!init || init.type !== 'NewExpression' || !init.callee || init.callee.type !== 'Identifier') {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return init.callee.name;
|
|
128
|
+
})();
|
|
129
|
+
|
|
130
|
+
const candidate: string | null = typeName ?? newName;
|
|
131
|
+
if (candidate === null) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
if (candidate === RXJS_BEHAVIOR_SUBJECT_NAME) {
|
|
135
|
+
return 'BS';
|
|
136
|
+
}
|
|
137
|
+
if (candidate === RXJS_SUBJECT_NAME) {
|
|
138
|
+
return 'S';
|
|
139
|
+
}
|
|
140
|
+
if (candidate === RXJS_OBSERVABLE_NAME) {
|
|
141
|
+
return 'OBS';
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Detektálja, hogy az init `inject(SomeService)` hívás-e — visszaadja a service nevet.
|
|
148
|
+
*/
|
|
149
|
+
function detectInjectedService(init: any): string | null {
|
|
150
|
+
if (!init || init.type !== 'CallExpression') {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
if (!init.callee || init.callee.type !== 'Identifier' || init.callee.name !== 'inject') {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const arg: any = init.arguments && init.arguments[0];
|
|
157
|
+
if (!arg || arg.type !== 'Identifier') {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
return arg.name;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Property kulcs név szöveggé alakítása.
|
|
165
|
+
*/
|
|
166
|
+
function getPropertyKeyName(node: any): string | null {
|
|
167
|
+
if (node.key && node.key.type === 'Identifier' && node.key.name) {
|
|
168
|
+
return node.key.name;
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Naming-patterns szabály (CCAP-megerősített): 7 al-ellenőrzés a CCAP "naming/*" review-kből.
|
|
175
|
+
* Minden al-ellenőrzés külön-külön kapcsolható a `checks` schema option-nel.
|
|
176
|
+
*/
|
|
4
177
|
const rule: Rule.RuleModule = {
|
|
5
178
|
meta: {
|
|
6
179
|
type: 'suggestion',
|
|
7
|
-
docs: {
|
|
8
|
-
|
|
180
|
+
docs: {
|
|
181
|
+
description: 'Enforce Dynamo naming conventions (CCAP-derived sub-checks).',
|
|
182
|
+
recommended: true,
|
|
183
|
+
},
|
|
184
|
+
schema: [
|
|
185
|
+
{
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: {
|
|
188
|
+
checks: {
|
|
189
|
+
type: 'object',
|
|
190
|
+
properties: {
|
|
191
|
+
booleanIsPrefix: { type: 'boolean' },
|
|
192
|
+
signalPostfix: { type: 'boolean' },
|
|
193
|
+
rxjsPostfix: { type: 'boolean' },
|
|
194
|
+
fileClassPostfix: { type: 'boolean' },
|
|
195
|
+
enumValueFormat: { type: 'boolean' },
|
|
196
|
+
servicePropertyPostfix: { type: 'boolean' },
|
|
197
|
+
fileClassNameConsistency: { type: 'boolean' },
|
|
198
|
+
},
|
|
199
|
+
additionalProperties: false,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
},
|
|
204
|
+
],
|
|
9
205
|
messages: {
|
|
10
|
-
|
|
206
|
+
booleanIsPrefix: 'Boolean property `{{name}}` nem `is`-sel kezdődik.',
|
|
207
|
+
signalPostfix: 'Signal változó `{{name}}` nem végződik `_$`-re.',
|
|
208
|
+
rxjsBsPostfix: '`BehaviorSubject` mező `{{name}}` nem végződik `_BS`-re.',
|
|
209
|
+
rxjsSPostfix: '`Subject` mező `{{name}}` nem végződik `_S`-re.',
|
|
210
|
+
rxjsObsPostfix: '`Observable` mező `{{name}}` nem végződik `$`-re.',
|
|
211
|
+
fileClassPostfix:
|
|
212
|
+
'Osztály `{{className}}` nem végződik `{{requiredPostfix}}`-re (fájlminta: {{fileName}}).',
|
|
213
|
+
enumKeyCamel: 'Enum kulcs `{{keyName}}` nem camelCase.',
|
|
214
|
+
enumValueKebab: 'Enum érték `{{value}}` nem kebab-case.',
|
|
215
|
+
servicePropertyPostfix:
|
|
216
|
+
'Property `{{property}}` `{{service}}`-t inject-el, de nem végződik `{{requiredPostfix}}`-re.',
|
|
217
|
+
fileClassNameConsistency:
|
|
218
|
+
'Osztály `{{className}}` entity része `{{classEntity}}` → '
|
|
219
|
+
+ 'elvárt fájlnév entity: `{{expected}}`, de a tényleges: `{{actual}}`.',
|
|
11
220
|
},
|
|
12
221
|
},
|
|
13
|
-
create(context) {
|
|
222
|
+
create(context: Rule.RuleContext): Rule.RuleListener {
|
|
223
|
+
const filename: string = context.filename ?? '';
|
|
224
|
+
const baseName: string = path.basename(filename);
|
|
225
|
+
if (baseName.endsWith('.spec.ts') || baseName.endsWith('.test.ts') || baseName.endsWith('.d.ts')) {
|
|
226
|
+
return {};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const userOptions: { checks?: NamingChecksOptions } = (context.options[0] ?? {}) as { checks?: NamingChecksOptions };
|
|
230
|
+
const checks: NamingChecksOptions = userOptions.checks ?? {};
|
|
231
|
+
const isOn = (key: keyof NamingChecksOptions): boolean => checks[key] !== false;
|
|
232
|
+
|
|
233
|
+
const filePostfixRule: { pattern: RegExp; classPostfix: string; entitySuffix: string } | undefined =
|
|
234
|
+
FILE_POSTFIX_MAP.find(
|
|
235
|
+
(r: { pattern: RegExp; classPostfix: string; entitySuffix: string }): boolean =>
|
|
236
|
+
r.pattern.test(baseName),
|
|
237
|
+
);
|
|
238
|
+
|
|
14
239
|
return {
|
|
15
|
-
|
|
240
|
+
PropertyDefinition(node: any): void {
|
|
16
241
|
try {
|
|
17
|
-
|
|
18
|
-
|
|
242
|
+
const propName: string | null = getPropertyKeyName(node);
|
|
243
|
+
if (propName === null) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (
|
|
248
|
+
isOn('booleanIsPrefix')
|
|
249
|
+
&& isBooleanType(node.typeAnnotation)
|
|
250
|
+
&& !propName.startsWith('is')
|
|
251
|
+
&& !propName.endsWith('_$')
|
|
252
|
+
) {
|
|
253
|
+
context.report({
|
|
254
|
+
node: node.key,
|
|
255
|
+
messageId: 'booleanIsPrefix',
|
|
256
|
+
data: { name: propName },
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (
|
|
261
|
+
isOn('signalPostfix')
|
|
262
|
+
&& isSignalFactoryCall(node.value)
|
|
263
|
+
&& !propName.endsWith('_$')
|
|
264
|
+
) {
|
|
265
|
+
context.report({
|
|
266
|
+
node: node.key,
|
|
267
|
+
messageId: 'signalPostfix',
|
|
268
|
+
data: { name: propName },
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (isOn('rxjsPostfix')) {
|
|
273
|
+
const rxKind: 'BS' | 'S' | 'OBS' | null = detectRxjsKind(node.typeAnnotation, node.value);
|
|
274
|
+
if (rxKind === 'BS' && !propName.endsWith('_BS')) {
|
|
275
|
+
context.report({ node: node.key, messageId: 'rxjsBsPostfix', data: { name: propName } });
|
|
276
|
+
} else if (rxKind === 'S' && !propName.endsWith('_S') && !propName.endsWith('_BS')) {
|
|
277
|
+
context.report({ node: node.key, messageId: 'rxjsSPostfix', data: { name: propName } });
|
|
278
|
+
} else if (rxKind === 'OBS' && !propName.endsWith('$')) {
|
|
279
|
+
context.report({ node: node.key, messageId: 'rxjsObsPostfix', data: { name: propName } });
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (isOn('servicePropertyPostfix')) {
|
|
284
|
+
const injectedService: string | null = detectInjectedService(node.value);
|
|
285
|
+
if (injectedService !== null) {
|
|
286
|
+
for (const mapping of SERVICE_INJECT_POSTFIX_MAP) {
|
|
287
|
+
if (
|
|
288
|
+
injectedService.endsWith(mapping.classPostfix)
|
|
289
|
+
&& !propName.endsWith(mapping.propertyPostfix)
|
|
290
|
+
) {
|
|
291
|
+
context.report({
|
|
292
|
+
node: node.key,
|
|
293
|
+
messageId: 'servicePropertyPostfix',
|
|
294
|
+
data: {
|
|
295
|
+
property: propName,
|
|
296
|
+
service: injectedService,
|
|
297
|
+
requiredPostfix: mapping.propertyPostfix,
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
19
305
|
} catch (error) {
|
|
20
|
-
console.error('[naming-patterns] Error in
|
|
306
|
+
console.error('[naming-patterns] Error in PropertyDefinition visitor:', error);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
ClassDeclaration(node: any): void {
|
|
311
|
+
try {
|
|
312
|
+
if (!node.id || !node.id.name || !filePostfixRule) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const className: string = node.id.name;
|
|
316
|
+
|
|
317
|
+
if (isOn('fileClassPostfix') && !className.endsWith(filePostfixRule.classPostfix)) {
|
|
318
|
+
context.report({
|
|
319
|
+
node: node.id,
|
|
320
|
+
messageId: 'fileClassPostfix',
|
|
321
|
+
data: {
|
|
322
|
+
className: className,
|
|
323
|
+
requiredPostfix: filePostfixRule.classPostfix,
|
|
324
|
+
fileName: baseName,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (isOn('fileClassNameConsistency') && className.endsWith(filePostfixRule.classPostfix)) {
|
|
330
|
+
const fileEntity: string = baseName.slice(
|
|
331
|
+
0,
|
|
332
|
+
baseName.length - filePostfixRule.entitySuffix.length,
|
|
333
|
+
);
|
|
334
|
+
const classEntity: string = className.slice(
|
|
335
|
+
0,
|
|
336
|
+
className.length - filePostfixRule.classPostfix.length,
|
|
337
|
+
);
|
|
338
|
+
const expectedFull: string = classEntityToKebab(classEntity);
|
|
339
|
+
const firstUnderscoreIdx: number = classEntity.indexOf('_');
|
|
340
|
+
const expectedWithoutPrefix: string = firstUnderscoreIdx > 0
|
|
341
|
+
? classEntityToKebab(classEntity.slice(firstUnderscoreIdx + 1))
|
|
342
|
+
: '';
|
|
343
|
+
const isMatch: boolean = expectedFull === fileEntity || expectedWithoutPrefix === fileEntity;
|
|
344
|
+
if (!isMatch && classEntity.length > 0) {
|
|
345
|
+
context.report({
|
|
346
|
+
node: node.id,
|
|
347
|
+
messageId: 'fileClassNameConsistency',
|
|
348
|
+
data: {
|
|
349
|
+
className: className,
|
|
350
|
+
classEntity: classEntity,
|
|
351
|
+
expected: expectedFull + (expectedWithoutPrefix ? ` vagy ${expectedWithoutPrefix}` : ''),
|
|
352
|
+
actual: fileEntity,
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
} catch (error) {
|
|
358
|
+
console.error('[naming-patterns] Error in ClassDeclaration visitor:', error);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
TSEnumDeclaration(node: any): void {
|
|
363
|
+
try {
|
|
364
|
+
if (!isOn('enumValueFormat')) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (!baseName.endsWith('.type-enum.ts')) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const members: any[] = node.members ?? [];
|
|
371
|
+
for (const member of members) {
|
|
372
|
+
const keyName: string | null = (member.id && member.id.name) ? member.id.name : null;
|
|
373
|
+
const initializer: any = member.initializer;
|
|
374
|
+
if (keyName === null) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (!CAMEL_CASE_KEY_REGEX.test(keyName)) {
|
|
378
|
+
context.report({
|
|
379
|
+
node: member.id,
|
|
380
|
+
messageId: 'enumKeyCamel',
|
|
381
|
+
data: { keyName: keyName },
|
|
382
|
+
});
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (
|
|
386
|
+
initializer
|
|
387
|
+
&& initializer.type === 'Literal'
|
|
388
|
+
&& typeof initializer.value === 'string'
|
|
389
|
+
) {
|
|
390
|
+
const value: string = initializer.value;
|
|
391
|
+
if (!KEBAB_CASE_VALUE_REGEX.test(value)) {
|
|
392
|
+
context.report({
|
|
393
|
+
node: initializer,
|
|
394
|
+
messageId: 'enumValueKebab',
|
|
395
|
+
data: { value: value },
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} catch (error) {
|
|
401
|
+
console.error('[naming-patterns] Error in TSEnumDeclaration visitor:', error);
|
|
21
402
|
}
|
|
22
403
|
},
|
|
23
404
|
};
|
|
@@ -25,5 +406,3 @@ const rule: Rule.RuleModule = {
|
|
|
25
406
|
};
|
|
26
407
|
|
|
27
408
|
export default rule;
|
|
28
|
-
|
|
29
|
-
|
|
@@ -479,6 +479,77 @@ describe('| no-getter-logic', () => {
|
|
|
479
479
|
expect(reportCalled).toBe(false);
|
|
480
480
|
});
|
|
481
481
|
|
|
482
|
+
it('| should report multi-statement getter body (CCAP-megerősítés)', () => {
|
|
483
|
+
let reportCalled: boolean = false;
|
|
484
|
+
const mockContext = {
|
|
485
|
+
report: (options: any) => {
|
|
486
|
+
reportCalled = true;
|
|
487
|
+
expect(options.messageId).toBe('noLogic');
|
|
488
|
+
},
|
|
489
|
+
options: [],
|
|
490
|
+
sourceCode: { getText: () => '' },
|
|
491
|
+
} as any;
|
|
492
|
+
|
|
493
|
+
const rule = noGetterLogicRule.create(mockContext);
|
|
494
|
+
|
|
495
|
+
const mockNode = {
|
|
496
|
+
kind: 'get',
|
|
497
|
+
key: { name: 'multiStatementGetter' },
|
|
498
|
+
value: {
|
|
499
|
+
body: {
|
|
500
|
+
type: 'BlockStatement',
|
|
501
|
+
body: [
|
|
502
|
+
{
|
|
503
|
+
type: 'VariableDeclaration',
|
|
504
|
+
declarations: [{ id: { name: 'tmp' }, init: { type: 'Identifier', name: 'foo' }}],
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
type: 'ReturnStatement',
|
|
508
|
+
argument: { type: 'Identifier', name: 'tmp' },
|
|
509
|
+
},
|
|
510
|
+
],
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
} as any;
|
|
514
|
+
|
|
515
|
+
rule.MethodDefinition(mockNode);
|
|
516
|
+
|
|
517
|
+
expect(reportCalled).toBe(true);
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it('| should report `if`-statement inside getter (CCAP-megerősítés)', () => {
|
|
521
|
+
let reportCalled: boolean = false;
|
|
522
|
+
const mockContext = {
|
|
523
|
+
report: () => { reportCalled = true; },
|
|
524
|
+
options: [],
|
|
525
|
+
sourceCode: { getText: () => '' },
|
|
526
|
+
} as any;
|
|
527
|
+
|
|
528
|
+
const rule = noGetterLogicRule.create(mockContext);
|
|
529
|
+
|
|
530
|
+
const mockNode = {
|
|
531
|
+
kind: 'get',
|
|
532
|
+
key: { name: 'gateGetter' },
|
|
533
|
+
value: {
|
|
534
|
+
body: {
|
|
535
|
+
type: 'BlockStatement',
|
|
536
|
+
body: [
|
|
537
|
+
{
|
|
538
|
+
type: 'IfStatement',
|
|
539
|
+
test: { type: 'Identifier', name: 'cond' },
|
|
540
|
+
consequent: { type: 'ReturnStatement', argument: { type: 'Literal', value: 1 }},
|
|
541
|
+
alternate: { type: 'ReturnStatement', argument: { type: 'Literal', value: 0 }},
|
|
542
|
+
},
|
|
543
|
+
],
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
} as any;
|
|
547
|
+
|
|
548
|
+
rule.MethodDefinition(mockNode);
|
|
549
|
+
|
|
550
|
+
expect(reportCalled).toBe(true);
|
|
551
|
+
});
|
|
552
|
+
|
|
482
553
|
it('| should handle errors gracefully', () => {
|
|
483
554
|
const mockContext = {
|
|
484
555
|
report: () => {},
|
|
@@ -18,7 +18,9 @@ function isAllowedNodeType(nodeType: string): boolean {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Check if a node type is explicitly forbidden (logic, calculations, function calls
|
|
21
|
+
* Check if a node type is explicitly forbidden (logic, calculations, function calls,
|
|
22
|
+
* block-level control flow, variable declarations).
|
|
23
|
+
* CCAP "no-getter-logic"-megerősítés: tilos `if/for/while/switch/try` és helyi `const/let`.
|
|
22
24
|
*/
|
|
23
25
|
function isForbiddenNodeType(nodeType: string): boolean {
|
|
24
26
|
const forbiddenTypes = [
|
|
@@ -37,6 +39,18 @@ function isForbiddenNodeType(nodeType: string): boolean {
|
|
|
37
39
|
'SequenceExpression',
|
|
38
40
|
'SpreadElement',
|
|
39
41
|
'RestElement',
|
|
42
|
+
// Block-level control flow — getter csak közvetlen property mapping lehet.
|
|
43
|
+
'IfStatement',
|
|
44
|
+
'ForStatement',
|
|
45
|
+
'ForInStatement',
|
|
46
|
+
'ForOfStatement',
|
|
47
|
+
'WhileStatement',
|
|
48
|
+
'DoWhileStatement',
|
|
49
|
+
'SwitchStatement',
|
|
50
|
+
'TryStatement',
|
|
51
|
+
'ThrowStatement',
|
|
52
|
+
// Lokális változó deklaráció — több-utasításos getter tilos.
|
|
53
|
+
'VariableDeclaration',
|
|
40
54
|
];
|
|
41
55
|
|
|
42
56
|
return forbiddenTypes.includes(nodeType);
|
|
@@ -85,9 +99,14 @@ function containsForbiddenNode(node: any): boolean {
|
|
|
85
99
|
return false;
|
|
86
100
|
}
|
|
87
101
|
|
|
88
|
-
// Special handling for BlockStatement - check all statements
|
|
102
|
+
// Special handling for BlockStatement - check all statements.
|
|
103
|
+
// CCAP-megerősítés: 1-nél több statement (az utolsó return-en kívül) tilos.
|
|
89
104
|
if (node.type === 'BlockStatement') {
|
|
90
105
|
if (node.body && Array.isArray(node.body)) {
|
|
106
|
+
// Több mint egy statement → többszörös utasítás → tilos.
|
|
107
|
+
if (node.body.length > 1) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
91
110
|
for (const statement of node.body) {
|
|
92
111
|
if (containsForbiddenNode(statement)) {
|
|
93
112
|
return true;
|