@code-sentinel-cli/code-sentinel-cli 3.0.9 → 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 +38961 -19863
- 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 +9 -8
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +12 -14
- 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 +28 -4
- 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 +14 -1
- package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +1 -1
- package/dist/builtin-rules/static/spring-boot/no-servlet-xss.rule.js +41 -0
- 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 +35 -4
- package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +1 -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 +316 -132
- package/dist/index.js +38952 -19854
- package/package.json +1 -1
- package/templates/ci/github-actions.yml +60 -2
- package/templates/ci/gitlab-ci.yml +51 -2
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +0 -30
|
@@ -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;
|
|
@@ -1,65 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Node } from 'ts-morph';
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
3
2
|
|
|
4
3
|
// builtin-rules/static/general/function-too-long.rule.ts
|
|
4
|
+
var FUNCTION_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
5
|
+
"function_declaration",
|
|
6
|
+
"method_definition",
|
|
7
|
+
"function_expression",
|
|
8
|
+
"arrow_function",
|
|
9
|
+
"method_declaration",
|
|
10
|
+
"constructor_declaration"
|
|
11
|
+
]);
|
|
5
12
|
var getName = (node) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const nameNode = node.childForFieldName("name");
|
|
14
|
+
if (nameNode) return nameNode.text;
|
|
15
|
+
if (node.type === "arrow_function" || node.type === "function_expression") {
|
|
16
|
+
const parent = node.parent;
|
|
17
|
+
if (parent?.type === "variable_declarator") {
|
|
18
|
+
const parentName = parent.childForFieldName("name");
|
|
19
|
+
if (parentName) return parentName.text;
|
|
20
|
+
}
|
|
21
|
+
if (parent?.type === "pair") {
|
|
22
|
+
const keyNode = parent.childForFieldName("key");
|
|
23
|
+
if (keyNode) return keyNode.text;
|
|
24
|
+
}
|
|
13
25
|
return "<arrow>";
|
|
14
26
|
}
|
|
15
27
|
return "<function>";
|
|
16
28
|
};
|
|
17
|
-
var
|
|
29
|
+
var collectFunctionNodes = (root) => {
|
|
18
30
|
const nodes = [];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
const stack = [root];
|
|
32
|
+
while (stack.length > 0) {
|
|
33
|
+
const cur = stack.pop();
|
|
34
|
+
if (!cur) break;
|
|
35
|
+
if (FUNCTION_NODE_TYPES.has(cur.type)) {
|
|
36
|
+
nodes.push(cur);
|
|
22
37
|
}
|
|
23
|
-
|
|
38
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
39
|
+
const child = cur.namedChild(i);
|
|
40
|
+
if (child) stack.push(child);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
24
43
|
return nodes;
|
|
25
44
|
};
|
|
26
45
|
var rule = {
|
|
27
46
|
id: "general/function-too-long",
|
|
28
|
-
|
|
47
|
+
// v5 (Tree-sitter multi-language refactor): TS/JS + Java support
|
|
48
|
+
version: 5,
|
|
29
49
|
kind: "static-ts",
|
|
30
50
|
title: "H\xE0m qu\xE1 d\xE0i \u2014 t\xE1ch helper ho\u1EB7c step nh\u1ECF h\u01A1n",
|
|
31
51
|
description: "H\xE0m d\xE0i th\u01B0\u1EDDng g\xE1nh qu\xE1 nhi\u1EC1u tr\xE1ch nhi\u1EC7m. T\xE1ch th\xE0nh helpers nh\u1ECF gi\xFAp \u0111\u1EB7t t\xEAn c\xF3 ngh\u0129a, d\u1EC5 test, d\u1EC5 \u0111\u1ECDc. Threshold m\u1EB7c \u0111\u1ECBnh 80 d\xF2ng \u2014 tune qua `options.maxLines`.",
|
|
32
52
|
severity: "warning",
|
|
33
53
|
category: "maintainability",
|
|
34
|
-
languages: ["typescript", "javascript"],
|
|
54
|
+
languages: ["typescript", "javascript", "java"],
|
|
35
55
|
scope: "general",
|
|
36
|
-
requires: "
|
|
37
|
-
baseConfidence:
|
|
56
|
+
requires: "syntactic",
|
|
57
|
+
baseConfidence: 95,
|
|
38
58
|
defaultOptions: { maxLines: 80 },
|
|
39
59
|
check(ctx) {
|
|
40
60
|
const threshold = ctx.options.maxLines;
|
|
41
|
-
const
|
|
61
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
42
62
|
const findings = [];
|
|
43
|
-
for (const node of
|
|
44
|
-
const start = node.
|
|
45
|
-
const end = node.
|
|
63
|
+
for (const node of collectFunctionNodes(tree.rootNode)) {
|
|
64
|
+
const start = node.startPosition.row + 1;
|
|
65
|
+
const end = node.endPosition.row + 1;
|
|
46
66
|
const lines = end - start + 1;
|
|
47
67
|
if (lines <= threshold) continue;
|
|
48
|
-
const parent = node.getParent();
|
|
49
68
|
let isNested = false;
|
|
50
|
-
let cur = parent;
|
|
69
|
+
let cur = node.parent;
|
|
51
70
|
while (cur) {
|
|
52
|
-
if (
|
|
71
|
+
if (FUNCTION_NODE_TYPES.has(cur.type)) {
|
|
53
72
|
isNested = true;
|
|
54
73
|
break;
|
|
55
74
|
}
|
|
56
|
-
cur = cur.
|
|
75
|
+
cur = cur.parent;
|
|
57
76
|
}
|
|
58
77
|
if (isNested) continue;
|
|
59
78
|
findings.push({
|
|
60
79
|
message: `H\xE0m "${getName(node)}" d\xE0i ${lines} d\xF2ng (gi\u1EDBi h\u1EA1n ${threshold}).`,
|
|
61
80
|
file: ctx.file.path,
|
|
62
|
-
range: { line: start, column: 1 },
|
|
81
|
+
range: { line: start, column: node.startPosition.column + 1 },
|
|
63
82
|
suggestion: "T\xE1ch th\xE0nh helpers nh\u1ECF \u2014 m\u1ED7i helper \u0111\u1EA3m nhi\u1EC7m m\u1ED9t b\u01B0\u1EDBc r\xF5 r\xE0ng v\xE0 \u0111\u1EB7t t\xEAn c\xF3 ngh\u0129a."
|
|
64
83
|
});
|
|
65
84
|
}
|
|
@@ -11,7 +11,8 @@ var SINK_LABEL = {
|
|
|
11
11
|
};
|
|
12
12
|
var rule = {
|
|
13
13
|
id: "general/no-code-injection",
|
|
14
|
-
|
|
14
|
+
// v3 (ADR-0065 calibration): luồng taint trực tiếp → severity blocker
|
|
15
|
+
version: 3,
|
|
15
16
|
kind: "static-ts",
|
|
16
17
|
title: "Kh\xF4ng th\u1EF1c thi m\xE3 \u0111\u1ED9ng t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (eval / setTimeout / setInterval)",
|
|
17
18
|
description: 'D\u1EEF li\u1EC7u t\u1EEB URL/ng\u01B0\u1EDDi d\xF9ng (location.search, ActivatedRoute params, document.referrer, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o h\xE0m th\u1EF1c thi m\xE3 \u0111\u1ED9ng (`eval(...)`, ho\u1EB7c `setTimeout` / `setInterval` v\u1EDBi tham s\u1ED1 \u0111\u1EA7u l\xE0 chu\u1ED7i) l\xE0 l\u1ED7 h\u1ED5ng Code Injection (CWE-94/95) \u2014 k\u1EBB t\u1EA5n c\xF4ng ch\xE8n \u0111\u01B0\u1EE3c m\xE3 JavaScript t\xF9y \xFD ch\u1EA1y trong ng\u1EEF c\u1EA3nh \u1EE9ng d\u1EE5ng. Rule d\xF9ng taint analysis (Tier-2 li\xEAn h\xE0m/li\xEAn file) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u k\u1EC3 c\u1EA3 khi gi\xE1 tr\u1ECB \u0111\u01B0\u1EE3c "r\u1EEDa" qua h\xE0m trung gian. Kh\u1EAFc ph\u1EE5c: b\u1ECF h\u1EB3n `eval`; truy\u1EC1n callback (function) thay v\xEC chu\u1ED7i cho timer; n\u1EBFu c\u1EA7n parse d\u1EEF li\u1EC7u, d\xF9ng `JSON.parse` thay cho `eval`.',
|
|
@@ -35,6 +36,12 @@ var rule = {
|
|
|
35
36
|
message: `\u26A0 Code Injection: d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (${sources}) ch\u1EA3y v\xE0o ${sinkLabel} \u2014 k\u1EBB t\u1EA5n c\xF4ng c\xF3 th\u1EC3 th\u1EF1c thi m\xE3 JavaScript t\xF9y \xFD.${trace}`,
|
|
36
37
|
file: ctx.file.path,
|
|
37
38
|
range: { line: tf.line, column: tf.column ?? 1 },
|
|
39
|
+
// ADR-0065 (calibration): luồng TRỰC TIẾP source→sink lớp RCE là đúng
|
|
40
|
+
// thứ tầng `blocker` sinh ra để chặn — trước bản này catalog KHÔNG có
|
|
41
|
+
// rule nào phát `blocker`, nên thang 4 mức thực chất chỉ có 3.
|
|
42
|
+
// Luồng laundered (truy vết liên thủ tục) giữ `error`: bằng chứng yếu
|
|
43
|
+
// hơn một bậc, không đủ để chặn merge.
|
|
44
|
+
severity: laundered ? "error" : "blocker",
|
|
38
45
|
confidence: laundered ? 75 : 85,
|
|
39
46
|
suggestion: "Lo\u1EA1i b\u1ECF `eval`; v\u1EDBi timer truy\u1EC1n callback (function) thay v\xEC chu\u1ED7i: `setTimeout(() => doSomething(), ms)`. N\u1EBFu c\u1EA7n parse d\u1EEF li\u1EC7u, d\xF9ng `JSON.parse`. Tuy\u1EC7t \u0111\u1ED1i kh\xF4ng d\u1EF1ng m\xE3 t\u1EEB gi\xE1 tr\u1ECB URL/ng\u01B0\u1EDDi d\xF9ng."
|
|
40
47
|
});
|
|
@@ -87,7 +87,8 @@ var rule = {
|
|
|
87
87
|
// version: 3 — Phase 14.3 invalidates Phase-10-era cache (rule logic
|
|
88
88
|
// unchanged; output gained `fix` field). Bumping is forward-only per
|
|
89
89
|
// DEVELOPMENT.md "cache invalidation via rule.version is one-way".
|
|
90
|
-
|
|
90
|
+
// v4 (ADR-0065 calibration): conf 85→95 (đo 27/27 TP)
|
|
91
|
+
version: 4,
|
|
91
92
|
kind: "static-ts",
|
|
92
93
|
title: "Kh\xF4ng d\xF9ng console.log trong source code",
|
|
93
94
|
description: "D\xF9ng logger (pino / project logger) thay v\xEC console.log. Phase 10 v2: skip rule cho file CLI (import commander/yargs/meow/...) v\xEC console.log l\xE0 user-facing output h\u1EE3p l\u1EC7 \u1EDF CLI tools.",
|
|
@@ -96,7 +97,7 @@ var rule = {
|
|
|
96
97
|
languages: ["typescript", "javascript"],
|
|
97
98
|
scope: "general",
|
|
98
99
|
requires: "syntactic",
|
|
99
|
-
baseConfidence:
|
|
100
|
+
baseConfidence: 95,
|
|
100
101
|
check(ctx) {
|
|
101
102
|
if (isCliByPath(ctx.file.path)) return [];
|
|
102
103
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
id: general/no-empty-catch
|
|
2
|
-
# version:
|
|
3
|
-
|
|
4
|
-
version: 3
|
|
2
|
+
# version: 4 — add Java support via per-language tree-sitter query (catch_clause + block).
|
|
3
|
+
version: 4
|
|
5
4
|
kind: static-yaml
|
|
6
5
|
title: "Không để catch block rỗng — log hoặc rethrow lỗi"
|
|
7
6
|
description: |
|
|
@@ -9,20 +8,27 @@ description: |
|
|
|
9
8
|
phải log lỗi (logger.error / logger.warn) hoặc rethrow. Nếu cố ý ignore
|
|
10
9
|
cho test code, thêm comment giải thích tại sao.
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
Flag mọi `statement_block`/`block` thuộc `catch_clause` mà text
|
|
13
12
|
chỉ chứa `{}` + whitespace. Block có comment vẫn được phép (vì comment đã
|
|
14
13
|
ghi rõ ý đồ).
|
|
15
14
|
severity: warning
|
|
16
15
|
category: error-handling
|
|
17
|
-
languages: [typescript, javascript]
|
|
16
|
+
languages: [typescript, javascript, java]
|
|
18
17
|
scope: general
|
|
19
18
|
baseConfidence: 90
|
|
20
19
|
detection:
|
|
21
20
|
type: tree-sitter
|
|
22
21
|
captureName: violation
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
queries:
|
|
23
|
+
typescript: |
|
|
24
|
+
(catch_clause body: (statement_block) @violation)
|
|
25
|
+
(#match? @violation "^\\{\\s*\\}$")
|
|
26
|
+
javascript: |
|
|
27
|
+
(catch_clause body: (statement_block) @violation)
|
|
28
|
+
(#match? @violation "^\\{\\s*\\}$")
|
|
29
|
+
java: |
|
|
30
|
+
(catch_clause (block) @violation)
|
|
31
|
+
(#match? @violation "^\\{\\s*\\}$")
|
|
26
32
|
message: "catch block rỗng — log lỗi hoặc rethrow."
|
|
27
33
|
suggestion: "Tối thiểu `logger.warn({ err }, 'context')`. Nếu cố ý nuốt, thêm comment giải thích."
|
|
28
34
|
# Phase 14.3/2026-06-07 — UNSAFE fix: replace `{}` with a neutral marker
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// builtin-rules/static/general/no-hardcoded-vietnamese.rule.ts
|
|
2
|
+
var VIETNAMESE_ACCENTED_RE = /[àáạảãâầấậẩẫăằắặẳẵèéẹẻẽêềếệểễìíịỉĩòóọỏõôồốộổỗơờớợởỡùúụủũưừứựửữỳýỵỷỹđÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸĐ]/;
|
|
3
|
+
var isTestOrFixturePath = (path) => {
|
|
4
|
+
const norm = path.replace(/\\/g, "/").toLowerCase();
|
|
5
|
+
return norm.includes(".spec.") || norm.includes(".test.") || norm.includes("_test.") || norm.includes("/test/") || norm.includes("/tests/") || norm.includes("/fixtures/") || norm.includes("/mocks/") || norm.includes("/e2e/");
|
|
6
|
+
};
|
|
7
|
+
var isSuppressedLine = (line) => {
|
|
8
|
+
const trimmed = line.trim();
|
|
9
|
+
if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*") || trimmed.startsWith("<!--")) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
if (trimmed.includes("console.log") || trimmed.includes("console.warn") || trimmed.includes("console.error") || trimmed.includes("logger.") || trimmed.includes("log.") || trimmed.includes("LoggerFactory")) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (trimmed.includes("translate.instant") || trimmed.includes("translate(") || trimmed.includes("i18n") || trimmed.includes("| translate") || trimmed.includes("translate>")) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
var rule = {
|
|
21
|
+
id: "general/no-hardcoded-vietnamese",
|
|
22
|
+
version: 1,
|
|
23
|
+
kind: "static-ts",
|
|
24
|
+
title: "Kh\xF4ng hardcode chu\u1ED7i ti\u1EBFng Vi\u1EC7t trong code \u2014 d\xF9ng i18n/resource",
|
|
25
|
+
description: "Chu\u1ED7i ti\u1EBFng Vi\u1EC7t c\xF3 d\u1EA5u hardcode trong source code ho\u1EB7c template g\xE2y kh\xF3 kh\u0103n khi b\u1EA3n \u0111\u1ECBa h\xF3a (i18n), thay \u0111\u1ED5i th\xF4ng \u0111i\u1EC7p, ho\u1EB7c b\u1EA3o tr\xEC. N\xEAn \u0111\u01B0a v\xE0o file resource / i18n message bundles.",
|
|
26
|
+
severity: "info",
|
|
27
|
+
category: "internationalization",
|
|
28
|
+
languages: ["typescript", "javascript", "html", "dart"],
|
|
29
|
+
scope: "general",
|
|
30
|
+
requires: "text",
|
|
31
|
+
baseConfidence: 75,
|
|
32
|
+
check(ctx) {
|
|
33
|
+
if (isTestOrFixturePath(ctx.file.path)) return [];
|
|
34
|
+
const content = ctx.file.content;
|
|
35
|
+
const lines = content.split(/\r?\n/);
|
|
36
|
+
const findings = [];
|
|
37
|
+
for (let i = 0; i < lines.length; i++) {
|
|
38
|
+
const line = lines[i];
|
|
39
|
+
if (!line || isSuppressedLine(line)) continue;
|
|
40
|
+
if (VIETNAMESE_ACCENTED_RE.test(line)) {
|
|
41
|
+
const match = VIETNAMESE_ACCENTED_RE.exec(line);
|
|
42
|
+
const col = match ? match.index + 1 : 1;
|
|
43
|
+
const preview = line.trim().slice(0, 60);
|
|
44
|
+
findings.push({
|
|
45
|
+
message: `Chu\u1ED7i ti\u1EBFng Vi\u1EC7t c\xF3 d\u1EA5u hardcode: "${preview}" \u2014 n\xEAn chuy\u1EC3n sang file i18n / message resource.`,
|
|
46
|
+
file: ctx.file.path,
|
|
47
|
+
range: { line: i + 1, column: col },
|
|
48
|
+
suggestion: "\u0110\u01B0a chu\u1ED7i v\xE0o file `vi.json` / `messages_vi.properties` v\xE0 g\u1ECDi qua `translate` / `i18n`."
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return findings;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { rule };
|
|
57
|
+
//# sourceMappingURL=no-hardcoded-vietnamese.rule.js.map
|
|
58
|
+
//# sourceMappingURL=no-hardcoded-vietnamese.rule.js.map
|
|
@@ -1,12 +1,135 @@
|
|
|
1
1
|
import { asTsMorphSourceFile } from '@code-sentinel/parsers';
|
|
2
|
-
import { Node } from 'ts-morph';
|
|
2
|
+
import { SyntaxKind, Node } from 'ts-morph';
|
|
3
3
|
|
|
4
4
|
// builtin-rules/static/general/no-magic-number.rule.ts
|
|
5
5
|
var DEFAULT_WHITELIST = [0, 1, 2, 3, 8, 10, 16, 24, 32, 60, 100, 1e3, 1024];
|
|
6
|
+
var WHITELIST_PRESETS = {
|
|
7
|
+
/** RFC 9110 status codes in common use. */
|
|
8
|
+
"http-status": [
|
|
9
|
+
200,
|
|
10
|
+
201,
|
|
11
|
+
202,
|
|
12
|
+
204,
|
|
13
|
+
206,
|
|
14
|
+
301,
|
|
15
|
+
302,
|
|
16
|
+
303,
|
|
17
|
+
304,
|
|
18
|
+
307,
|
|
19
|
+
308,
|
|
20
|
+
400,
|
|
21
|
+
401,
|
|
22
|
+
403,
|
|
23
|
+
404,
|
|
24
|
+
405,
|
|
25
|
+
406,
|
|
26
|
+
409,
|
|
27
|
+
410,
|
|
28
|
+
412,
|
|
29
|
+
413,
|
|
30
|
+
415,
|
|
31
|
+
422,
|
|
32
|
+
423,
|
|
33
|
+
429,
|
|
34
|
+
500,
|
|
35
|
+
501,
|
|
36
|
+
502,
|
|
37
|
+
503,
|
|
38
|
+
504
|
|
39
|
+
],
|
|
40
|
+
/** `KeyboardEvent.keyCode` values (legacy but still pervasive in enterprise UI). */
|
|
41
|
+
"key-codes": [
|
|
42
|
+
9,
|
|
43
|
+
13,
|
|
44
|
+
16,
|
|
45
|
+
17,
|
|
46
|
+
18,
|
|
47
|
+
19,
|
|
48
|
+
20,
|
|
49
|
+
27,
|
|
50
|
+
32,
|
|
51
|
+
33,
|
|
52
|
+
34,
|
|
53
|
+
35,
|
|
54
|
+
36,
|
|
55
|
+
37,
|
|
56
|
+
38,
|
|
57
|
+
39,
|
|
58
|
+
40,
|
|
59
|
+
45,
|
|
60
|
+
46,
|
|
61
|
+
48,
|
|
62
|
+
49,
|
|
63
|
+
50,
|
|
64
|
+
51,
|
|
65
|
+
52,
|
|
66
|
+
53,
|
|
67
|
+
54,
|
|
68
|
+
55,
|
|
69
|
+
56,
|
|
70
|
+
57,
|
|
71
|
+
112,
|
|
72
|
+
113,
|
|
73
|
+
114,
|
|
74
|
+
115,
|
|
75
|
+
116,
|
|
76
|
+
117,
|
|
77
|
+
118,
|
|
78
|
+
119,
|
|
79
|
+
120,
|
|
80
|
+
121,
|
|
81
|
+
122,
|
|
82
|
+
123
|
|
83
|
+
],
|
|
84
|
+
/**
|
|
85
|
+
* Calendar / clock boundaries: 23:59:59.999, 1440 min/day, 3600 s/h,
|
|
86
|
+
* 86400 s/day, 604800 s/week, 365/366 days.
|
|
87
|
+
*
|
|
88
|
+
* Deliberately EXCLUDES small generic integers (7, 11, 12, 30, 31, 52).
|
|
89
|
+
* They are plausible date constants but far too common as ordinary
|
|
90
|
+
* thresholds and array indexes — whitelisting them would trade a false
|
|
91
|
+
* positive for a false negative, which is the worse of the two for a rule
|
|
92
|
+
* that already errs toward silence.
|
|
93
|
+
*/
|
|
94
|
+
"date-time": [23, 59, 365, 366, 999, 1440, 3600, 86400, 604800]
|
|
95
|
+
};
|
|
96
|
+
var ARITHMETIC_OPERATORS = /* @__PURE__ */ new Set([
|
|
97
|
+
SyntaxKind.PlusToken,
|
|
98
|
+
SyntaxKind.MinusToken,
|
|
99
|
+
SyntaxKind.AsteriskToken,
|
|
100
|
+
SyntaxKind.SlashToken,
|
|
101
|
+
SyntaxKind.PercentToken,
|
|
102
|
+
SyntaxKind.AsteriskAsteriskToken
|
|
103
|
+
]);
|
|
104
|
+
var arithmeticRoot = (node) => {
|
|
105
|
+
let current = node;
|
|
106
|
+
for (; ; ) {
|
|
107
|
+
const parent = current.getParent();
|
|
108
|
+
if (parent === void 0) return current;
|
|
109
|
+
if (Node.isParenthesizedExpression(parent) || Node.isPrefixUnaryExpression(parent)) {
|
|
110
|
+
current = parent;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (Node.isBinaryExpression(parent) && ARITHMETIC_OPERATORS.has(parent.getOperatorToken().getKind())) {
|
|
114
|
+
current = parent;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
return current;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
6
120
|
var isArrayIndex = (node) => {
|
|
7
121
|
const parent = node.getParent();
|
|
8
122
|
return parent !== void 0 && Node.isElementAccessExpression(parent) && parent.getArgumentExpression() === node;
|
|
9
123
|
};
|
|
124
|
+
var isIgnoredCallArgument = (node, callees) => {
|
|
125
|
+
if (callees.size === 0) return false;
|
|
126
|
+
const parent = node.getParent();
|
|
127
|
+
if (parent === void 0 || !Node.isCallExpression(parent)) return false;
|
|
128
|
+
if (!parent.getArguments().includes(node)) return false;
|
|
129
|
+
const callee = parent.getExpression();
|
|
130
|
+
const name = Node.isPropertyAccessExpression(callee) ? callee.getName() : Node.isIdentifier(callee) ? callee.getText() : "";
|
|
131
|
+
return name !== "" && callees.has(name);
|
|
132
|
+
};
|
|
10
133
|
var isInNamedDeclaration = (node) => {
|
|
11
134
|
const parent = node.getParent();
|
|
12
135
|
if (!parent) return false;
|
|
@@ -24,7 +147,7 @@ var isInNamedDeclaration = (node) => {
|
|
|
24
147
|
}
|
|
25
148
|
if (Node.isPropertyAssignment(parent) && parent.getInitializer() === node) {
|
|
26
149
|
const name = parent.getName();
|
|
27
|
-
if (
|
|
150
|
+
if (name !== "" && !/^\d+$/.test(name)) {
|
|
28
151
|
return true;
|
|
29
152
|
}
|
|
30
153
|
}
|
|
@@ -32,23 +155,42 @@ var isInNamedDeclaration = (node) => {
|
|
|
32
155
|
};
|
|
33
156
|
var rule = {
|
|
34
157
|
id: "general/no-magic-number",
|
|
35
|
-
|
|
158
|
+
// v5 (ADR-0065): bốn carve-out theo số đo thực địa (precision v4 = 1,9 %).
|
|
159
|
+
version: 5,
|
|
36
160
|
kind: "static-ts",
|
|
37
161
|
title: "Tr\xE1nh magic number \u2014 \u0111\u1EB7t t\xEAn constant cho gi\xE1 tr\u1ECB c\xF3 \xFD ngh\u0129a",
|
|
38
|
-
description: "Magic number = s\u1ED1 literal xu\u1EA5t hi\u1EC7n inline m\xE0 \xFD ngh\u0129a kh\xF4ng hi\u1EC3n nhi\xEAn.
|
|
162
|
+
description: "Magic number = s\u1ED1 literal xu\u1EA5t hi\u1EC7n inline m\xE0 \xFD ngh\u0129a kh\xF4ng hi\u1EC3n nhi\xEAn. v5 b\u1ECF qua: literal \u0111\xE3 \u0111\u01B0\u1EE3c \u0111\u1EB7t t\xEAn qua `const X = N` (k\u1EC3 c\u1EA3 khi \u0111i qua ph\xE9p to\xE1n, vd `20 * 1024 * 1024`), class field, enum member, default param, M\u1ECCI object-property key kh\xF4ng thu\u1EA7n ch\u1EEF s\u1ED1 (`vtsWidth: 420`), array index, tham s\u1ED1 c\u1EE7a API th\u1EDDi gian/\u0111\u1ED9 d\xE0i (`setTimeout`, `debounceTime`, `maxLength`), v\xE0 c\xE1c preset h\u1EB1ng ph\u1ED5 qu\xE1t (HTTP status, keycode, m\u1ED1c ng\xE0y/gi\u1EDD). Tune qua `options.whitelist`, `options.whitelistPresets`, `options.ignoreArgumentsOf`, `options.skipInDeclarations`, `options.ignoreArrayIndexes`.",
|
|
39
163
|
severity: "info",
|
|
40
164
|
category: "maintainability",
|
|
41
165
|
languages: ["typescript", "javascript"],
|
|
42
166
|
scope: "general",
|
|
43
167
|
requires: "semantic-ts",
|
|
44
|
-
|
|
168
|
+
// 50 = "đã biết từng rất nhiễu (1,9 % ở v4), v5 chưa đo lại". Xem ADR-0065.
|
|
169
|
+
baseConfidence: 50,
|
|
45
170
|
defaultOptions: {
|
|
46
171
|
whitelist: [...DEFAULT_WHITELIST],
|
|
47
172
|
skipInDeclarations: true,
|
|
48
|
-
ignoreArrayIndexes: true
|
|
173
|
+
ignoreArrayIndexes: true,
|
|
174
|
+
ignoreArgumentsOf: [
|
|
175
|
+
"setTimeout",
|
|
176
|
+
"setInterval",
|
|
177
|
+
"debounceTime",
|
|
178
|
+
"throttleTime",
|
|
179
|
+
"auditTime",
|
|
180
|
+
"sampleTime",
|
|
181
|
+
"delay",
|
|
182
|
+
"timer",
|
|
183
|
+
"maxLength",
|
|
184
|
+
"minLength"
|
|
185
|
+
],
|
|
186
|
+
whitelistPresets: ["http-status", "key-codes", "date-time"]
|
|
49
187
|
},
|
|
50
188
|
check(ctx) {
|
|
51
|
-
const whitelist = new Set(ctx.options.whitelist);
|
|
189
|
+
const whitelist = new Set(ctx.options.whitelist ?? DEFAULT_WHITELIST);
|
|
190
|
+
for (const preset of ctx.options.whitelistPresets ?? []) {
|
|
191
|
+
for (const value of WHITELIST_PRESETS[preset] ?? []) whitelist.add(value);
|
|
192
|
+
}
|
|
193
|
+
const ignoredCallees = new Set(ctx.options.ignoreArgumentsOf ?? []);
|
|
52
194
|
const skipInDecl = ctx.options.skipInDeclarations;
|
|
53
195
|
const skipArrayIndex = ctx.options.ignoreArrayIndexes;
|
|
54
196
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
@@ -59,8 +201,9 @@ var rule = {
|
|
|
59
201
|
const value = Number(raw);
|
|
60
202
|
if (!Number.isFinite(value)) return;
|
|
61
203
|
if (whitelist.has(value)) return;
|
|
62
|
-
if (skipInDecl && isInNamedDeclaration(node)) return;
|
|
63
204
|
if (skipArrayIndex && isArrayIndex(node)) return;
|
|
205
|
+
if (isIgnoredCallArgument(node, ignoredCallees)) return;
|
|
206
|
+
if (skipInDecl && isInNamedDeclaration(arithmeticRoot(node))) return;
|
|
64
207
|
const { line, column } = sf.getLineAndColumnAtPos(node.getStart());
|
|
65
208
|
findings.push({
|
|
66
209
|
message: `Magic number ${raw} \u2014 c\xE2n nh\u1EAFc \u0111\u1EB7t t\xEAn constant \u0111\u1EC3 code r\xF5 ngh\u0129a h\u01A1n.`,
|