@code-sentinel-cli/code-sentinel-cli 3.0.10 → 3.0.11
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/dist/bin.js +4729 -1306
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +3 -6
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +4 -8
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +0 -2
- package/dist/builtin-rules/ai/general/code-clarity.prompt.md +19 -2
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +8 -3
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +3 -3
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +4 -10
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +2 -9
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +4 -4
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +3 -3
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +1 -2
- package/dist/builtin-rules/static/angular/button-accessible-name.rule.js +143 -0
- package/dist/builtin-rules/static/angular/component-prefix.rule.js +6 -2
- package/dist/builtin-rules/static/angular/img-alt-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/inject-pattern.rule.js +3 -2
- package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +14 -5
- package/dist/builtin-rules/static/angular/onpush-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +3 -2
- package/dist/builtin-rules/static/angular/trackby-required.rule.js +3 -2
- package/dist/builtin-rules/static/flutter/no-undisposed-resource.rule.js +143 -0
- package/dist/builtin-rules/static/general/file-too-long.rule.js +5 -4
- package/dist/builtin-rules/static/general/function-too-long.rule.js +46 -27
- package/dist/builtin-rules/static/general/no-code-injection.rule.js +8 -1
- package/dist/builtin-rules/static/general/no-console-log.rule.js +3 -2
- package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +14 -8
- package/dist/builtin-rules/static/general/no-hardcoded-vietnamese.rule.js +58 -0
- package/dist/builtin-rules/static/general/no-magic-number.rule.js +151 -8
- package/dist/builtin-rules/static/general/no-todo-comment.rule.js +88 -0
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +53 -6
- package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +8 -1
- package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +8 -1
- package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +6 -1
- package/dist/builtin-rules/static/spring-boot/no-unzoned-datetime.rule.js +96 -0
- package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +4 -2
- package/dist/index.d.ts +84 -152
- package/dist/index.js +4730 -1307
- package/package.json +1 -1
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +0 -30
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
id: spring-boot/security-mass-assignment-risk
|
|
2
|
-
|
|
2
|
+
# v2 (ADR-0065 calibration): conf 60→75 (đo cùng lô 19/19 TP)
|
|
3
|
+
version: 2
|
|
3
4
|
kind: ai
|
|
4
5
|
title: "Spring Boot mass assignment or security-state input?"
|
|
5
6
|
description: |
|
|
@@ -10,10 +11,9 @@ severity: warning
|
|
|
10
11
|
category: security
|
|
11
12
|
languages: [java]
|
|
12
13
|
scope: spring-boot
|
|
13
|
-
baseConfidence:
|
|
14
|
+
baseConfidence: 75
|
|
14
15
|
prompt: ./security-mass-assignment-risk.prompt.md
|
|
15
16
|
contextScope: per-cluster
|
|
16
|
-
maxTokens: 1200
|
|
17
17
|
aiConfig:
|
|
18
18
|
tier: regular
|
|
19
19
|
prRouting:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/security-redirect-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 2
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot open redirect or unsafe forward?"
|
|
5
5
|
description: |
|
|
@@ -13,7 +13,6 @@ scope: spring-boot
|
|
|
13
13
|
baseConfidence: 60
|
|
14
14
|
prompt: ./security-redirect-risk.prompt.md
|
|
15
15
|
contextScope: per-cluster
|
|
16
|
-
maxTokens: 1000
|
|
17
16
|
aiConfig:
|
|
18
17
|
tier: regular
|
|
19
18
|
prRouting:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/security-sensitive-data-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 2
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot sensitive data exposure?"
|
|
5
5
|
description: |
|
|
@@ -14,7 +14,6 @@ scope: spring-boot
|
|
|
14
14
|
baseConfidence: 60
|
|
15
15
|
prompt: ./security-sensitive-data-risk.prompt.md
|
|
16
16
|
contextScope: per-cluster
|
|
17
|
-
maxTokens: 1200
|
|
18
17
|
aiConfig:
|
|
19
18
|
tier: regular
|
|
20
19
|
prRouting:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/transaction-loop-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 3
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot transaction/loop flow co rui ro khong?"
|
|
5
5
|
description: |
|
|
@@ -14,7 +14,6 @@ scope: spring-boot
|
|
|
14
14
|
baseConfidence: 60
|
|
15
15
|
prompt: ./transaction-loop-risk.prompt.md
|
|
16
16
|
contextScope: per-cluster
|
|
17
|
-
maxTokens: 1800
|
|
18
17
|
aiConfig:
|
|
19
18
|
tier: regular
|
|
20
19
|
prRouting:
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/static/angular/button-accessible-name.rule.ts
|
|
4
|
+
var ACCESSIBLE_NAME_ATTRS = /* @__PURE__ */ new Set([
|
|
5
|
+
"aria-label",
|
|
6
|
+
"aria-labelledby",
|
|
7
|
+
"title"
|
|
8
|
+
]);
|
|
9
|
+
var DECORATIVE_ROLES = /* @__PURE__ */ new Set(["presentation", "none"]);
|
|
10
|
+
function* walkNodes(node) {
|
|
11
|
+
const stack = [node];
|
|
12
|
+
while (stack.length > 0) {
|
|
13
|
+
const cur = stack.pop();
|
|
14
|
+
if (!cur) break;
|
|
15
|
+
yield cur;
|
|
16
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
17
|
+
const child = cur.namedChild(i);
|
|
18
|
+
if (child) stack.push(child);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function namedChildOfType(node, type) {
|
|
23
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
24
|
+
const child = node.namedChild(i);
|
|
25
|
+
if (child?.type === type) return child;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function normalizeAttrName(name) {
|
|
30
|
+
let inner = name;
|
|
31
|
+
const bracket = /^\[(.+)\]$/.exec(inner);
|
|
32
|
+
if (bracket?.[1]) inner = bracket[1];
|
|
33
|
+
else if (inner.startsWith("bind-")) inner = inner.slice("bind-".length);
|
|
34
|
+
return inner.replace(/^attr\./i, "").toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
function attributeValue(attr) {
|
|
37
|
+
const quoted = namedChildOfType(attr, "quoted_attribute_value");
|
|
38
|
+
const value = quoted ? namedChildOfType(quoted, "attribute_value") : null;
|
|
39
|
+
return value?.text ?? "";
|
|
40
|
+
}
|
|
41
|
+
function hasAccessibleAttr(tagNode) {
|
|
42
|
+
for (let i = 0; i < tagNode.namedChildCount; i++) {
|
|
43
|
+
const child = tagNode.namedChild(i);
|
|
44
|
+
if (child?.type !== "attribute") continue;
|
|
45
|
+
const nameNode = namedChildOfType(child, "attribute_name");
|
|
46
|
+
if (!nameNode) continue;
|
|
47
|
+
const prop = normalizeAttrName(nameNode.text);
|
|
48
|
+
if (ACCESSIBLE_NAME_ATTRS.has(prop)) return true;
|
|
49
|
+
if (prop === "aria-hidden" && attributeValue(child).trim().toLowerCase() === "true") {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (prop === "role" && DECORATIVE_ROLES.has(attributeValue(child).trim().toLowerCase())) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
function hasInteractiveLinkAttr(tagNode) {
|
|
59
|
+
for (let i = 0; i < tagNode.namedChildCount; i++) {
|
|
60
|
+
const child = tagNode.namedChild(i);
|
|
61
|
+
if (child?.type !== "attribute") continue;
|
|
62
|
+
const nameNode = namedChildOfType(child, "attribute_name");
|
|
63
|
+
if (!nameNode) continue;
|
|
64
|
+
const prop = normalizeAttrName(nameNode.text);
|
|
65
|
+
if (prop === "href" || prop === "routerlink") return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
function isInsideIconTag(node, rootElement) {
|
|
70
|
+
let cur = node.parent;
|
|
71
|
+
while (cur && cur !== rootElement) {
|
|
72
|
+
if (cur.type === "element") {
|
|
73
|
+
const startTag = namedChildOfType(cur, "start_tag") ?? namedChildOfType(cur, "self_closing_tag");
|
|
74
|
+
const tag = startTag ? namedChildOfType(startTag, "tag_name")?.text.toLowerCase() : null;
|
|
75
|
+
if (tag === "mat-icon" || tag === "svg" || tag === "i") {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
cur = cur.parent;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
function hasMeaningfulTextOrDirective(elementNode) {
|
|
84
|
+
for (const node of walkNodes(elementNode)) {
|
|
85
|
+
if (node.type === "text") {
|
|
86
|
+
const text = node.text.trim();
|
|
87
|
+
if (text.length > 0 && !isInsideIconTag(node, elementNode)) return true;
|
|
88
|
+
}
|
|
89
|
+
if (node.type === "attribute") {
|
|
90
|
+
const nameNode = namedChildOfType(node, "attribute_name");
|
|
91
|
+
if (nameNode) {
|
|
92
|
+
const prop = normalizeAttrName(nameNode.text);
|
|
93
|
+
if (prop === "translate" || prop === "i18n" || ACCESSIBLE_NAME_ATTRS.has(prop)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
var rule = {
|
|
102
|
+
id: "angular/button-accessible-name",
|
|
103
|
+
version: 1,
|
|
104
|
+
kind: "static-ts",
|
|
105
|
+
title: "`<button>` v\xE0 `<a>` ph\u1EA3i c\xF3 accessible name (text ho\u1EB7c `aria-label`)",
|
|
106
|
+
description: "N\xFAt b\u1EA5m (`<button>`) v\xE0 li\xEAn k\u1EBFt (`<a>`) thi\u1EBFu accessible name vi ph\u1EA1m WCAG 4.1.2 / 2.4.4. N\u1EBFu n\xFAt ch\u1EC9 ch\u1EE9a icon (nh\u01B0 `<mat-icon>`, `<i>`, `<svg>`), h\xE3y th\xEAm thu\u1ED9c t\xEDnh `aria-label` ho\u1EB7c text \u1EA9n (`cdk-visually-hidden`) \u0111\u1EC3 ng\u01B0\u1EDDi d\xF9ng screen-reader hi\u1EC3u \u0111\u01B0\u1EE3c ch\u1EE9c n\u0103ng.",
|
|
107
|
+
severity: "warning",
|
|
108
|
+
category: "accessibility",
|
|
109
|
+
languages: ["html"],
|
|
110
|
+
scope: "angular",
|
|
111
|
+
requires: "syntactic",
|
|
112
|
+
baseConfidence: 85,
|
|
113
|
+
check(ctx) {
|
|
114
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
115
|
+
const findings = [];
|
|
116
|
+
for (const node of walkNodes(tree.rootNode)) {
|
|
117
|
+
if (node.type !== "element") continue;
|
|
118
|
+
const startTag = namedChildOfType(node, "start_tag") ?? namedChildOfType(node, "self_closing_tag");
|
|
119
|
+
if (!startTag) continue;
|
|
120
|
+
const tagNameNode = namedChildOfType(startTag, "tag_name");
|
|
121
|
+
if (!tagNameNode) continue;
|
|
122
|
+
const tag = tagNameNode.text.toLowerCase();
|
|
123
|
+
if (tag !== "button" && tag !== "a") continue;
|
|
124
|
+
if (tag === "a" && !hasInteractiveLinkAttr(startTag)) continue;
|
|
125
|
+
if (hasAccessibleAttr(startTag)) continue;
|
|
126
|
+
if (hasMeaningfulTextOrDirective(node)) continue;
|
|
127
|
+
findings.push({
|
|
128
|
+
message: `<${tag}> thi\u1EBFu accessible name \u2014 screen-reader kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xF4 t\u1EA3 h\xE0nh \u0111\u1ED9ng (l\u1ED7i WCAG 4.1.2). Th\xEAm text b\xEAn trong n\xFAt ho\u1EB7c khai b\xE1o thu\u1ED9c t\xEDnh \`aria-label="m\xF4 t\u1EA3"\`.`,
|
|
129
|
+
file: ctx.file.path,
|
|
130
|
+
range: {
|
|
131
|
+
line: startTag.startPosition.row + 1,
|
|
132
|
+
column: startTag.startPosition.column + 1
|
|
133
|
+
},
|
|
134
|
+
suggestion: 'Th\xEAm `aria-label="T\xEAn h\xE0nh \u0111\u1ED9ng"` ho\u1EB7c th\xEAm text n\u1ED9i dung v\xE0o b\xEAn trong th\u1EBB.'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return findings;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export { rule };
|
|
142
|
+
//# sourceMappingURL=button-accessible-name.rule.js.map
|
|
143
|
+
//# sourceMappingURL=button-accessible-name.rule.js.map
|
|
@@ -39,11 +39,15 @@ var hasAllowedPrefix = (selector, prefixes) => {
|
|
|
39
39
|
};
|
|
40
40
|
var rule = {
|
|
41
41
|
id: "angular/component-prefix",
|
|
42
|
-
|
|
42
|
+
// v3 (ADR-0065 calibration): severity warning→info (quy ước đặt tên)
|
|
43
|
+
version: 3,
|
|
43
44
|
kind: "static-ts",
|
|
44
45
|
title: "Component selector ph\u1EA3i c\xF3 prefix d\u1EF1 \xE1n",
|
|
45
46
|
description: '@Component selector n\xEAn b\u1EAFt \u0111\u1EA7u b\u1EB1ng prefix do d\u1EF1 \xE1n quy \u0111\u1ECBnh. Default prefix l\xE0 `app-` (Angular CLI). Tune cho d\u1EF1 \xE1n Viettel qua `options.prefixes: ["vts", "v"]` trong `.codereviewrc.yaml`.',
|
|
46
|
-
|
|
47
|
+
// ADR-0065: quy ước đặt tên thuần tuý → `info`. Trước bản này rule này ở
|
|
48
|
+
// `warning`/100, tức xếp CAO HƠN `angular/template-dom-xss` (XSS, warning/70)
|
|
49
|
+
// — một quy ước selector không thể nghiêm trọng hơn một lỗ hổng XSS.
|
|
50
|
+
severity: "info",
|
|
47
51
|
category: "angular-best-practice",
|
|
48
52
|
languages: ["typescript"],
|
|
49
53
|
scope: "angular",
|
|
@@ -61,7 +61,8 @@ function hasTextAlternative(tag) {
|
|
|
61
61
|
}
|
|
62
62
|
var rule = {
|
|
63
63
|
id: "angular/img-alt-required",
|
|
64
|
-
|
|
64
|
+
// v2 (ADR-0065 calibration): conf 80→90 (đo 32/32 TP)
|
|
65
|
+
version: 2,
|
|
65
66
|
kind: "static-ts",
|
|
66
67
|
title: "`<img>` ph\u1EA3i c\xF3 text alternative (`alt`) \u0111\u1EC3 \u0111\u1EA3m b\u1EA3o accessibility",
|
|
67
68
|
description: 'Th\u1EBB `<img>` thi\u1EBFu text alternative l\xE0 l\u1ED7i WCAG 1.1.1 (Level A): ng\u01B0\u1EDDi d\xF9ng screen-reader kh\xF4ng nh\u1EADn \u0111\u01B0\u1EE3c th\xF4ng tin g\xEC, nhi\u1EC1u tr\xECnh duy\u1EC7t \u0111\u1ECDc lu\xF4n t\xEAn file trong `src`. Th\xEAm `alt` m\xF4 t\u1EA3 n\u1ED9i dung \u1EA3nh; n\u1EBFu \u1EA3nh ch\u1EC9 trang tr\xED th\xEC d\xF9ng `alt=""` (khai b\xE1o r\xF5 l\xE0 decorative). \u1EA2nh \u0111\u1ED9ng c\u0169ng c\xF3 th\u1EC3 d\xF9ng `[alt]="\u2026"`. Rule b\u1ECF qua khi `<img>` \u0111\xE3 c\xF3 `alt`/`aria-label`/`aria-labelledby`/`title`/`aria-hidden` ho\u1EB7c `role="presentation"|"none"`.',
|
|
@@ -70,7 +71,7 @@ var rule = {
|
|
|
70
71
|
languages: ["html"],
|
|
71
72
|
scope: "angular",
|
|
72
73
|
requires: "syntactic",
|
|
73
|
-
baseConfidence:
|
|
74
|
+
baseConfidence: 90,
|
|
74
75
|
check(ctx) {
|
|
75
76
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
76
77
|
const findings = [];
|
|
@@ -10,7 +10,8 @@ var hasAngularDecorator = (cls) => {
|
|
|
10
10
|
};
|
|
11
11
|
var rule = {
|
|
12
12
|
id: "angular/inject-pattern",
|
|
13
|
-
|
|
13
|
+
// v2 (ADR-0065 calibration): conf 75→95 (đo 193/193 TP; đếm tham số không thể sai)
|
|
14
|
+
version: 2,
|
|
14
15
|
kind: "static-ts",
|
|
15
16
|
title: "D\xF9ng inject() thay v\xEC constructor DI (Angular 14+)",
|
|
16
17
|
description: "inject() ch\u1EA1y \u0111\u01B0\u1EE3c trong field initializer, g\u1ECDn h\u01A1n constructor params. C\u0169ng l\xE0 pattern b\u1EAFt bu\u1ED9c cho m\u1ED9t s\u1ED1 functional guards / interceptors. Flag m\u1ECDi constructor c\xF3 param trong class Angular (Component/Directive/Injectable/Pipe).",
|
|
@@ -19,7 +20,7 @@ var rule = {
|
|
|
19
20
|
languages: ["typescript"],
|
|
20
21
|
scope: "angular",
|
|
21
22
|
requires: "semantic-ts",
|
|
22
|
-
baseConfidence:
|
|
23
|
+
baseConfidence: 95,
|
|
23
24
|
check(ctx) {
|
|
24
25
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
25
26
|
const findings = [];
|
|
@@ -21,7 +21,8 @@ var getImplementedInterfaceNames = (cls) => {
|
|
|
21
21
|
};
|
|
22
22
|
var rule = {
|
|
23
23
|
id: "angular/lifecycle-method-required",
|
|
24
|
-
|
|
24
|
+
// v2 (ADR-0065 calibration): conf 85→95 (đo 71/71 TP)
|
|
25
|
+
version: 2,
|
|
25
26
|
kind: "static-ts",
|
|
26
27
|
title: "Class c\xF3 lifecycle method ph\u1EA3i `implements` interface t\u01B0\u01A1ng \u1EE9ng",
|
|
27
28
|
description: "Khi class c\xF3 ngOnInit/ngOnDestroy/... ph\u1EA3i khai b\xE1o `implements OnInit`/etc. Compiler s\u1EBD verify signature; typo (vd `ngOninit`) s\u1EBD b\u1ECB compiler b\u1EAFt thay v\xEC silent fail.",
|
|
@@ -30,7 +31,7 @@ var rule = {
|
|
|
30
31
|
languages: ["typescript"],
|
|
31
32
|
scope: "angular",
|
|
32
33
|
requires: "semantic-ts",
|
|
33
|
-
baseConfidence:
|
|
34
|
+
baseConfidence: 95,
|
|
34
35
|
check(ctx) {
|
|
35
36
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
36
37
|
const findings = [];
|
|
@@ -139,7 +139,11 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
139
139
|
file,
|
|
140
140
|
range,
|
|
141
141
|
suggestion: "B\u1ECDc `.pipe(takeUntilDestroyed())` / `.pipe(takeUntil(this.destroy$))`, ho\u1EB7c d\xF9ng `async` pipe trong template.",
|
|
142
|
-
|
|
142
|
+
// v5 (ADR-0065): 80→95. Đo trên hai module Angular sản xuất: 96 finding
|
|
143
|
+
// band `long-lived`, 0 bị bác. `baseConfidence` của rule này là metadata
|
|
144
|
+
// CHẾT — mọi finding đều mang confidence riêng — nên hiệu chỉnh phải sửa
|
|
145
|
+
// ở đây, không phải ở khai báo rule.
|
|
146
|
+
confidence: 95,
|
|
143
147
|
severity: "error"
|
|
144
148
|
};
|
|
145
149
|
}
|
|
@@ -149,7 +153,8 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
149
153
|
file,
|
|
150
154
|
range,
|
|
151
155
|
suggestion: "Th\xEAm `.pipe(takeUntilDestroyed())` ho\u1EB7c d\xF9ng `async` pipe / `firstValueFrom`.",
|
|
152
|
-
|
|
156
|
+
// v5 (ADR-0065): 70→90. Đo 430 finding band `one-shot`, 0 bị bác.
|
|
157
|
+
confidence: 90,
|
|
153
158
|
severity: "warning"
|
|
154
159
|
};
|
|
155
160
|
}
|
|
@@ -158,13 +163,16 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
158
163
|
file,
|
|
159
164
|
range,
|
|
160
165
|
suggestion: "L\u01B0u subscription r\u1ED3i `unsubscribe()` trong ngOnDestroy, gom v\xE0o m\u1ED9t `Subscription`, ho\u1EB7c d\xF9ng `takeUntilDestroyed()` / `async` pipe.",
|
|
161
|
-
|
|
166
|
+
// v5 (ADR-0065): 60→85. Band yếu nhất (không nhận diện được nguồn), nên
|
|
167
|
+
// vẫn giữ thấp hơn hai band trên một bậc.
|
|
168
|
+
confidence: 85,
|
|
162
169
|
severity: "warning"
|
|
163
170
|
};
|
|
164
171
|
};
|
|
165
172
|
var rule = {
|
|
166
173
|
id: "angular/no-leaky-subscription",
|
|
167
|
-
|
|
174
|
+
// v5 (ADR-0065 calibration): conf 80→95 (đo 526/526 TP trên 2 module Angular sản xuất)
|
|
175
|
+
version: 5,
|
|
168
176
|
kind: "static-ts",
|
|
169
177
|
title: "Subscription ph\u1EA3i \u0111\u01B0\u1EE3c h\u1EE7y (takeUntil / unsubscribe / Subscription.add / async pipe)",
|
|
170
178
|
description: "Flags bare .subscribe() calls WITHOUT visible teardown. v4 (precision-first): SUPPRESSES managed subscriptions (stored + unsubscribe(), or added to a Subscription collection via .add()) and terminating pipes (takeUntil/take/first/\u2026). Severity is per-subscription: long-lived streams (valueChanges/params/fromEvent/interval) stay `error` (genuine leak); one-shot sources (HTTP call/afterClosed/forkJoin) and unclassified streams are `warning`.",
|
|
@@ -173,7 +181,8 @@ var rule = {
|
|
|
173
181
|
languages: ["typescript"],
|
|
174
182
|
scope: "angular",
|
|
175
183
|
requires: "semantic-ts",
|
|
176
|
-
|
|
184
|
+
// Fallback thôi: mọi finding của rule này đều tự khai confidence (95/90/85).
|
|
185
|
+
baseConfidence: 85,
|
|
177
186
|
check(ctx) {
|
|
178
187
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
179
188
|
const findings = [];
|
|
@@ -29,7 +29,8 @@ var usesOnPush = (obj) => {
|
|
|
29
29
|
var hasSpread = (obj) => obj.getProperties().some((prop) => Node.isSpreadAssignment(prop));
|
|
30
30
|
var rule = {
|
|
31
31
|
id: "angular/onpush-required",
|
|
32
|
-
|
|
32
|
+
// v3 (ADR-0065 calibration): conf 70→95 (đo 122/122 TP)
|
|
33
|
+
version: 3,
|
|
33
34
|
kind: "static-ts",
|
|
34
35
|
title: "@Component n\xEAn d\xF9ng ChangeDetectionStrategy.OnPush",
|
|
35
36
|
description: "OnPush gi\u1EA3m s\u1ED1 l\u1EA7n change detection ch\u1EA1y, perf-critical cho app l\u1EDBn. Khuy\u1EBFn ngh\u1ECB \xE1p d\u1EE5ng cho h\u1EA7u h\u1EBFt Component; m\u1ED9t s\u1ED1 Component v\u1EABn h\u1EE3p l\u1EC7 khi d\xF9ng Default \u2192 \u0111\xE2y l\xE0 khuy\u1EBFn ngh\u1ECB perf (warning conf 70), kh\xF4ng ph\u1EA3i bug ch\u1EAFc ch\u1EAFn. B\u1ECF qua Component c\xF3 config spread (kh\xF4ng ch\u1EE9ng minh \u0111\u01B0\u1EE3c).",
|
|
@@ -41,7 +42,7 @@ var rule = {
|
|
|
41
42
|
// A4 calibration: 85→70. Detection is deterministic, but "should be OnPush"
|
|
42
43
|
// is a judgment — some Default components are intentional. 70 = "worth a look,
|
|
43
44
|
// not certain", so `--min-confidence` can filter it out of a strict gate.
|
|
44
|
-
baseConfidence:
|
|
45
|
+
baseConfidence: 95,
|
|
45
46
|
check(ctx) {
|
|
46
47
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
47
48
|
const findings = [];
|
|
@@ -54,7 +54,8 @@ function rootIdentifier(expr) {
|
|
|
54
54
|
}
|
|
55
55
|
var rule = {
|
|
56
56
|
id: "angular/template-dom-xss",
|
|
57
|
-
|
|
57
|
+
// v4 (ADR-0065 calibration): conf 70→90 (đo 76/76 TP)
|
|
58
|
+
version: 4,
|
|
58
59
|
kind: "static-ts",
|
|
59
60
|
usesTemplateComponent: true,
|
|
60
61
|
title: "Binding nguy hi\u1EC3m trong template Angular (DOM XSS)",
|
|
@@ -64,7 +65,7 @@ var rule = {
|
|
|
64
65
|
languages: ["html"],
|
|
65
66
|
scope: "angular",
|
|
66
67
|
requires: "syntactic",
|
|
67
|
-
baseConfidence:
|
|
68
|
+
baseConfidence: 90,
|
|
68
69
|
check(ctx) {
|
|
69
70
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
70
71
|
const findings = [];
|
|
@@ -29,7 +29,8 @@ function attributeValue(attr) {
|
|
|
29
29
|
}
|
|
30
30
|
var rule = {
|
|
31
31
|
id: "angular/trackby-required",
|
|
32
|
-
|
|
32
|
+
// v2 (ADR-0065 calibration): conf 70→95 (đo 166/166 TP)
|
|
33
|
+
version: 2,
|
|
33
34
|
kind: "static-ts",
|
|
34
35
|
title: "`*ngFor` n\xEAn khai b\xE1o `trackBy` \u0111\u1EC3 tr\xE1nh re-render to\xE0n b\u1ED9 list",
|
|
35
36
|
description: "V\xF2ng l\u1EB7p `*ngFor` kh\xF4ng c\xF3 `trackBy` khi\u1EBFn Angular d\u1EF1ng l\u1EA1i to\xE0n b\u1ED9 DOM c\u1EE7a list m\u1ED7i khi array \u0111\u1ED5i tham chi\u1EBFu (r\u1EA5t ph\u1ED5 bi\u1EBFn v\u1EDBi `| async`, immutable state, refetch HTTP) thay v\xEC gi\u1EEF l\u1EA1i node c\u0169 \u2014 m\u1ED9t trong c\xE1c v\u1EA5n \u0111\u1EC1 perf th\u01B0\u1EDDng g\u1EB7p nh\u1EA5t. Th\xEAm `; trackBy: trackFn` (tr\u1EA3 v\u1EC1 id \u1ED5n \u0111\u1ECBnh c\u1EE7a item), ho\u1EB7c chuy\u1EC3n sang control-flow `@for (x of items; track x.id)` c\u1EE7a Angular 17+.",
|
|
@@ -38,7 +39,7 @@ var rule = {
|
|
|
38
39
|
languages: ["html"],
|
|
39
40
|
scope: "angular",
|
|
40
41
|
requires: "syntactic",
|
|
41
|
-
baseConfidence:
|
|
42
|
+
baseConfidence: 95,
|
|
42
43
|
check(ctx) {
|
|
43
44
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
44
45
|
const findings = [];
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// builtin-rules/static/flutter/no-undisposed-resource.rule.ts
|
|
2
|
+
var DISPOSABLE_TYPE_PATTERN = /\b(?:late\s+)?(?:final\s+)?(AnimationController|TextEditingController|ScrollController|FocusNode|StreamSubscription(?:<[^>]+>)?|TabController|PageController|StreamController(?:<[^>]+>)?|TransformationController)\??\s+([_a-zA-Z0-9]+)/g;
|
|
3
|
+
var ASSIGNMENT_TYPE_PATTERN = /\b(?:final|var)\s+([_a-zA-Z0-9]+)\s*=\s*(AnimationController|TextEditingController|ScrollController|FocusNode|StreamController|TabController|PageController|TransformationController)\s*\(/g;
|
|
4
|
+
var extractStateClasses = (content) => {
|
|
5
|
+
const classes = [];
|
|
6
|
+
const classDeclRegex = /\bclass\s+([_a-zA-Z0-9]+)\s+extends\s+State(?:<[^>]+>)?/g;
|
|
7
|
+
for (const match of content.matchAll(classDeclRegex)) {
|
|
8
|
+
const className = match[1];
|
|
9
|
+
if (!className || match.index === void 0) continue;
|
|
10
|
+
const openBraceIdx = content.indexOf("{", match.index);
|
|
11
|
+
if (openBraceIdx === -1) continue;
|
|
12
|
+
const beforeClass = content.slice(0, match.index);
|
|
13
|
+
const startLine = beforeClass.split(/\r?\n/).length;
|
|
14
|
+
let depth = 1;
|
|
15
|
+
let endBraceIdx = -1;
|
|
16
|
+
for (let i = openBraceIdx + 1; i < content.length; i++) {
|
|
17
|
+
const ch = content[i];
|
|
18
|
+
if (ch === "{") depth++;
|
|
19
|
+
else if (ch === "}") {
|
|
20
|
+
depth--;
|
|
21
|
+
if (depth === 0) {
|
|
22
|
+
endBraceIdx = i;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (endBraceIdx !== -1) {
|
|
28
|
+
const body = content.slice(openBraceIdx + 1, endBraceIdx);
|
|
29
|
+
classes.push({ name: className, body, startLine });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return classes;
|
|
33
|
+
};
|
|
34
|
+
var extractFields = (classBody, contentBeforeClass) => {
|
|
35
|
+
const fields = [];
|
|
36
|
+
const lines = classBody.split(/\r?\n/);
|
|
37
|
+
const baseOffset = contentBeforeClass.split(/\r?\n/).length;
|
|
38
|
+
for (let i = 0; i < lines.length; i++) {
|
|
39
|
+
const line = lines[i];
|
|
40
|
+
if (!line) continue;
|
|
41
|
+
const currentLineNum = baseOffset + i;
|
|
42
|
+
const trimmed = line.trim();
|
|
43
|
+
if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*")) continue;
|
|
44
|
+
if (trimmed.includes("(") && !trimmed.includes("=") && !trimmed.startsWith("final") && !trimmed.startsWith("var") && !trimmed.startsWith("late")) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
for (const match of line.matchAll(DISPOSABLE_TYPE_PATTERN)) {
|
|
48
|
+
const typeName = match[1];
|
|
49
|
+
const varName = match[2];
|
|
50
|
+
if (!typeName || !varName || match.index === void 0) continue;
|
|
51
|
+
if (varName === "dispose" || varName === "initState" || varName === "build") continue;
|
|
52
|
+
fields.push({
|
|
53
|
+
name: varName,
|
|
54
|
+
type: typeName,
|
|
55
|
+
line: currentLineNum,
|
|
56
|
+
column: match.index + 1
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
for (const match of line.matchAll(ASSIGNMENT_TYPE_PATTERN)) {
|
|
60
|
+
const varName = match[1];
|
|
61
|
+
const typeName = match[2];
|
|
62
|
+
if (!varName || !typeName || match.index === void 0) continue;
|
|
63
|
+
if (!fields.some((f) => f.name === varName)) {
|
|
64
|
+
fields.push({
|
|
65
|
+
name: varName,
|
|
66
|
+
type: typeName,
|
|
67
|
+
line: currentLineNum,
|
|
68
|
+
column: match.index + 1
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return fields;
|
|
74
|
+
};
|
|
75
|
+
var extractDisposeBody = (classBody) => {
|
|
76
|
+
const disposeMatch = /\bvoid\s+dispose\s*\(\s*\)/.exec(classBody);
|
|
77
|
+
if (!disposeMatch) return null;
|
|
78
|
+
const openBraceIdx = classBody.indexOf("{", disposeMatch.index);
|
|
79
|
+
if (openBraceIdx === -1) return null;
|
|
80
|
+
let depth = 1;
|
|
81
|
+
let endBraceIdx = -1;
|
|
82
|
+
for (let i = openBraceIdx + 1; i < classBody.length; i++) {
|
|
83
|
+
const ch = classBody[i];
|
|
84
|
+
if (ch === "{") depth++;
|
|
85
|
+
else if (ch === "}") {
|
|
86
|
+
depth--;
|
|
87
|
+
if (depth === 0) {
|
|
88
|
+
endBraceIdx = i;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (endBraceIdx === -1) return null;
|
|
94
|
+
return classBody.slice(openBraceIdx + 1, endBraceIdx);
|
|
95
|
+
};
|
|
96
|
+
var rule = {
|
|
97
|
+
id: "flutter/no-undisposed-resource",
|
|
98
|
+
version: 1,
|
|
99
|
+
kind: "static-ts",
|
|
100
|
+
title: "T\xE0i nguy\xEAn trong State ph\u1EA3i \u0111\u01B0\u1EE3c gi\u1EA3i ph\xF3ng t\u1EA1i `dispose()`",
|
|
101
|
+
description: "C\xE1c t\xE0i nguy\xEAn nh\u01B0 `StreamSubscription`, `AnimationController`, `TextEditingController`, `ScrollController`, `FocusNode`, `TabController`, `PageController` khai b\xE1o trong State b\u1EAFt bu\u1ED9c ph\u1EA3i \u0111\u01B0\u1EE3c gi\u1EA3i ph\xF3ng (`.dispose()` ho\u1EB7c `.cancel()`) khi State b\u1ECB hu\u1EF7 \u0111\u1EC3 tr\xE1nh r\xF2 r\u1EC9 b\u1ED9 nh\u1EDB (memory leak) ho\u1EB7c crash app.",
|
|
102
|
+
severity: "warning",
|
|
103
|
+
category: "correctness",
|
|
104
|
+
languages: ["dart"],
|
|
105
|
+
scope: "flutter",
|
|
106
|
+
requires: "text",
|
|
107
|
+
baseConfidence: 85,
|
|
108
|
+
check(ctx) {
|
|
109
|
+
const content = ctx.file.content;
|
|
110
|
+
const findings = [];
|
|
111
|
+
const stateClasses = extractStateClasses(content);
|
|
112
|
+
for (const sc of stateClasses) {
|
|
113
|
+
const classDeclIdx = content.indexOf(`class ${sc.name}`);
|
|
114
|
+
const beforeClass = classDeclIdx !== -1 ? content.slice(0, classDeclIdx) : "";
|
|
115
|
+
const fields = extractFields(sc.body, beforeClass);
|
|
116
|
+
if (fields.length === 0) continue;
|
|
117
|
+
const disposeBody = extractDisposeBody(sc.body);
|
|
118
|
+
for (const field of fields) {
|
|
119
|
+
const isSubscription = field.type.startsWith("StreamSubscription");
|
|
120
|
+
const disposeCall = `${field.name}.dispose()`;
|
|
121
|
+
const disposeSafeCall = `${field.name}?.dispose()`;
|
|
122
|
+
const cancelCall = `${field.name}.cancel()`;
|
|
123
|
+
const cancelSafeCall = `${field.name}?.cancel()`;
|
|
124
|
+
const isDisposed = disposeBody !== null && (disposeBody.includes(disposeCall) || disposeBody.includes(disposeSafeCall) || disposeBody.includes(cancelCall) || disposeBody.includes(cancelSafeCall) || disposeBody.includes(`${field.name} = null`) || disposeBody.includes("for (") && disposeBody.includes(field.name));
|
|
125
|
+
if (!isDisposed) {
|
|
126
|
+
const action = isSubscription ? ".cancel()" : ".dispose()";
|
|
127
|
+
findings.push({
|
|
128
|
+
message: `T\xE0i nguy\xEAn "${field.name}" (${field.type}) trong State "${sc.name}" kh\xF4ng \u0111\u01B0\u1EE3c gi\u1EA3i ph\xF3ng t\u1EA1i dispose() \u2014 g\xE2y r\xF2 r\u1EC9 b\u1ED9 nh\u1EDB (memory leak).`,
|
|
129
|
+
file: ctx.file.path,
|
|
130
|
+
range: { line: field.line, column: field.column },
|
|
131
|
+
suggestion: `G\u1ECDi \`${field.name}${action}\` b\xEAn trong ph\u01B0\u01A1ng th\u1EE9c \`dispose()\` c\u1EE7a State.`,
|
|
132
|
+
confidence: isSubscription || field.type.includes("AnimationController") ? 90 : 85
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return findings;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export { rule };
|
|
142
|
+
//# sourceMappingURL=no-undisposed-resource.rule.js.map
|
|
143
|
+
//# sourceMappingURL=no-undisposed-resource.rule.js.map
|
|
@@ -10,16 +10,17 @@ var countLines = (content) => {
|
|
|
10
10
|
};
|
|
11
11
|
var rule = {
|
|
12
12
|
id: "general/file-too-long",
|
|
13
|
-
|
|
13
|
+
// v4 (ADR-0065 calibration): conf 60→95 (đo 81/81 TP; đếm dòng không thể sai)
|
|
14
|
+
version: 4,
|
|
14
15
|
kind: "static-ts",
|
|
15
16
|
title: "File qu\xE1 d\xE0i \u2014 c\xE2n nh\u1EAFc t\xE1ch module",
|
|
16
17
|
description: "File d\xE0i th\u01B0\u1EDDng kh\xF3 \u0111\u1ECDc + kh\xF3 test. C\xE2n nh\u1EAFc t\xE1ch theo tr\xE1ch nhi\u1EC7m: helpers, types, hooks, components m\u1ED7i file ri\xEAng. Threshold m\u1EB7c \u0111\u1ECBnh 500 d\xF2ng \u2014 tune qua `options.maxLines` trong `.codereviewrc.yaml`.",
|
|
17
18
|
severity: "warning",
|
|
18
19
|
category: "maintainability",
|
|
19
|
-
languages: ["typescript", "javascript", "java"],
|
|
20
|
+
languages: ["typescript", "javascript", "java", "dart", "kotlin", "swift"],
|
|
20
21
|
scope: "general",
|
|
21
|
-
requires: "
|
|
22
|
-
baseConfidence:
|
|
22
|
+
requires: "text",
|
|
23
|
+
baseConfidence: 95,
|
|
23
24
|
defaultOptions: { maxLines: 500 },
|
|
24
25
|
check(ctx) {
|
|
25
26
|
const threshold = ctx.options.maxLines;
|