@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,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.`,
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// builtin-rules/static/general/no-todo-comment.rule.ts
|
|
2
|
+
var TODO_KEYWORD_RE = /\b([Tt][Oo][Dd][Oo]|[Ff][Ii][Xx][Mm][Ee]|[Hh][Aa][Cc][Kk]|XXX|xxx)\b/;
|
|
3
|
+
var rule = {
|
|
4
|
+
id: "general/no-todo-comment",
|
|
5
|
+
version: 2,
|
|
6
|
+
kind: "static-ts",
|
|
7
|
+
title: "Kh\xF4ng \u0111\u1EC3 TODO/FIXME/HACK/XXX trong code \u0111\xE3 commit",
|
|
8
|
+
description: 'TODO comments kh\xF4ng ph\u1EA3i l\xE0 c\xE1ch tracking c\xF4ng vi\u1EC7c \u2014 ch\xFAng t\xEDch t\u1EE5 v\xE0 b\u1ECB qu\xEAn. H\xE3y t\u1EA1o issue trong tracker (Jira/Linear), commit code \u0111\xE3 ho\xE0n th\xE0nh, v\xE0 \u0111\u1EC3 comment gi\u1EA3i th\xEDch "t\u1EA1i sao" thay v\xEC "c\xF2n thi\u1EBFu g\xEC". Rule n\xE0y flag m\u1ECDi comment ch\u1EE9a TODO, FIXME, HACK, XXX (kh\xF4ng ph\xE2n bi\u1EC7t hoa th\u01B0\u1EDDng).',
|
|
9
|
+
severity: "info",
|
|
10
|
+
category: "maintainability",
|
|
11
|
+
languages: ["typescript", "javascript", "java", "dart"],
|
|
12
|
+
scope: "general",
|
|
13
|
+
requires: "text",
|
|
14
|
+
baseConfidence: 100,
|
|
15
|
+
check(ctx) {
|
|
16
|
+
const content = ctx.file.content;
|
|
17
|
+
const lines = content.split(/\r?\n/);
|
|
18
|
+
const findings = [];
|
|
19
|
+
let inBlockComment = false;
|
|
20
|
+
for (let i = 0; i < lines.length; i++) {
|
|
21
|
+
const lineText = lines[i];
|
|
22
|
+
if (lineText === void 0) continue;
|
|
23
|
+
const lineNum = i + 1;
|
|
24
|
+
if (inBlockComment) {
|
|
25
|
+
const endIdx = lineText.indexOf("*/");
|
|
26
|
+
const commentChunk = endIdx !== -1 ? lineText.slice(0, endIdx + 2) : lineText;
|
|
27
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
28
|
+
if (match) {
|
|
29
|
+
findings.push({
|
|
30
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
31
|
+
file: ctx.file.path,
|
|
32
|
+
range: { line: lineNum, column: (match.index ?? 0) + 1 },
|
|
33
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (endIdx !== -1) {
|
|
37
|
+
inBlockComment = false;
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const singleIdx = lineText.indexOf("//");
|
|
42
|
+
const blockStartIdx = lineText.indexOf("/*");
|
|
43
|
+
if (singleIdx !== -1 && (blockStartIdx === -1 || singleIdx < blockStartIdx)) {
|
|
44
|
+
const commentChunk = lineText.slice(singleIdx);
|
|
45
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
46
|
+
if (match) {
|
|
47
|
+
findings.push({
|
|
48
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
49
|
+
file: ctx.file.path,
|
|
50
|
+
range: { line: lineNum, column: singleIdx + (match.index ?? 0) + 1 },
|
|
51
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else if (blockStartIdx !== -1) {
|
|
55
|
+
const endIdx = lineText.indexOf("*/", blockStartIdx + 2);
|
|
56
|
+
if (endIdx !== -1) {
|
|
57
|
+
const commentChunk = lineText.slice(blockStartIdx, endIdx + 2);
|
|
58
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
59
|
+
if (match) {
|
|
60
|
+
findings.push({
|
|
61
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
62
|
+
file: ctx.file.path,
|
|
63
|
+
range: { line: lineNum, column: blockStartIdx + (match.index ?? 0) + 1 },
|
|
64
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
inBlockComment = true;
|
|
69
|
+
const commentChunk = lineText.slice(blockStartIdx);
|
|
70
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
71
|
+
if (match) {
|
|
72
|
+
findings.push({
|
|
73
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
74
|
+
file: ctx.file.path,
|
|
75
|
+
range: { line: lineNum, column: blockStartIdx + (match.index ?? 0) + 1 },
|
|
76
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return findings;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export { rule };
|
|
87
|
+
//# sourceMappingURL=no-todo-comment.rule.js.map
|
|
88
|
+
//# sourceMappingURL=no-todo-comment.rule.js.map
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { asTsMorphSourceFile } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
1
3
|
// builtin-rules/static/general/no-unused-export.rule.ts
|
|
4
|
+
var TYPE_ONLY_KINDS = /* @__PURE__ */ new Set([
|
|
5
|
+
"interface",
|
|
6
|
+
"type",
|
|
7
|
+
"enum"
|
|
8
|
+
]);
|
|
2
9
|
var DEFAULT_SKIP_PATHS = [
|
|
3
10
|
"**/index.ts",
|
|
4
11
|
"**/index.tsx",
|
|
@@ -12,6 +19,19 @@ var DEFAULT_SKIP_PATHS = [
|
|
|
12
19
|
"**/*.module.ts",
|
|
13
20
|
"**/*.routes.ts",
|
|
14
21
|
"**/*.config.ts",
|
|
22
|
+
// v2 (ADR-0065) — shared-contract file conventions. These hold the types,
|
|
23
|
+
// constants and models a codebase deliberately publishes for other modules
|
|
24
|
+
// to import; "nobody in the reviewed subtree imports it" is not evidence
|
|
25
|
+
// that nobody imports it.
|
|
26
|
+
"**/*.types.ts",
|
|
27
|
+
"**/*.interface.ts",
|
|
28
|
+
"**/*.interfaces.ts",
|
|
29
|
+
"**/*.model.ts",
|
|
30
|
+
"**/*.models.ts",
|
|
31
|
+
"**/*.const.ts",
|
|
32
|
+
"**/*.constants.ts",
|
|
33
|
+
"**/*.enum.ts",
|
|
34
|
+
"**/*.dto.ts",
|
|
15
35
|
"**/test-setup.ts",
|
|
16
36
|
"**/jest-setup.ts",
|
|
17
37
|
"**/vitest-setup.ts"
|
|
@@ -19,7 +39,29 @@ var DEFAULT_SKIP_PATHS = [
|
|
|
19
39
|
var DEFAULTS = {
|
|
20
40
|
skipPaths: DEFAULT_SKIP_PATHS,
|
|
21
41
|
includeDefaultExports: false,
|
|
22
|
-
includeOrphanFiles: false
|
|
42
|
+
includeOrphanFiles: false,
|
|
43
|
+
includeTypeOnlyExports: false
|
|
44
|
+
};
|
|
45
|
+
var declarationLines = (parsed) => {
|
|
46
|
+
const lines = /* @__PURE__ */ new Map();
|
|
47
|
+
try {
|
|
48
|
+
const sf = asTsMorphSourceFile(parsed);
|
|
49
|
+
const declarations = [
|
|
50
|
+
...sf.getVariableDeclarations(),
|
|
51
|
+
...sf.getFunctions(),
|
|
52
|
+
...sf.getClasses(),
|
|
53
|
+
...sf.getInterfaces(),
|
|
54
|
+
...sf.getEnums(),
|
|
55
|
+
...sf.getTypeAliases()
|
|
56
|
+
];
|
|
57
|
+
for (const declaration of declarations) {
|
|
58
|
+
const name = declaration.getName();
|
|
59
|
+
if (name === void 0 || name === "" || lines.has(name)) continue;
|
|
60
|
+
lines.set(name, sf.getLineAndColumnAtPos(declaration.getStart()).line);
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
return lines;
|
|
23
65
|
};
|
|
24
66
|
var REGEX_SPECIAL = new Set(".+^$()|[]\\".split(""));
|
|
25
67
|
var globToRegex = (pattern) => {
|
|
@@ -90,17 +132,19 @@ var consumedNames = (graph, targetPath) => {
|
|
|
90
132
|
};
|
|
91
133
|
var rule = {
|
|
92
134
|
id: "general/no-unused-export",
|
|
93
|
-
|
|
135
|
+
// v2 (ADR-0065): type-only exports off by default, shared-contract skipPaths,
|
|
136
|
+
// finding anchored on the declaration line. Precision v1 đo được 13,3 %.
|
|
137
|
+
version: 2,
|
|
94
138
|
kind: "static-ts",
|
|
95
139
|
title: "Kh\xF4ng export symbol n\u1EBFu kh\xF4ng ai d\xF9ng",
|
|
96
|
-
description: "Symbol \u0111\u01B0\u1EE3c export nh\u01B0ng kh\xF4ng c\xF3 file n\xE0o trong project import l\u1EA1i. Conservative: b\u1ECF qua
|
|
140
|
+
description: "Symbol \u0111\u01B0\u1EE3c export nh\u01B0ng kh\xF4ng c\xF3 file n\xE0o trong project import l\u1EA1i. Conservative: b\u1ECF qua export ki\u1EC3u (interface/type/enum \u2014 m\u1EB7c \u0111\u1ECBnh, v\xEC \u0111\xF3 l\xE0 h\u1EE3p \u0111\u1ED3ng d\xF9ng chung), wildcard re-export targets, default exports, orphan files, v\xE0 c\xE1c file public-API/entry-point/h\u1EE3p \u0111\u1ED3ng (index.ts, public-api.ts, *.module.ts, *.routes.ts, *.types.ts, *.interface.ts, *.const.ts, *.model.ts, *.d.ts, ...). \u26A0 CH\u1EC8 \u0111\xE1ng tin khi qu\xE9t TO\xC0N d\u1EF1 \xE1n: \u0111\u1ED3 th\u1ECB ch\u1EC9 ch\u1EE9a file \u0111\u01B0\u1EE3c qu\xE9t, n\xEAn qu\xE9t m\u1ED9t th\u01B0 m\u1EE5c con s\u1EBD l\xE0m m\u1ECDi export \u1EDF bi\xEAn module tr\xF4ng nh\u01B0 kh\xF4ng ai d\xF9ng.",
|
|
97
141
|
severity: "info",
|
|
98
142
|
category: "maintainability",
|
|
99
143
|
languages: ["typescript", "javascript"],
|
|
100
144
|
scope: "general",
|
|
101
145
|
requires: "semantic-ts",
|
|
102
146
|
usesAstGraph: true,
|
|
103
|
-
baseConfidence:
|
|
147
|
+
baseConfidence: 45,
|
|
104
148
|
defaultOptions: DEFAULTS,
|
|
105
149
|
check(ctx) {
|
|
106
150
|
const graph = ctx.astGraph;
|
|
@@ -108,7 +152,8 @@ var rule = {
|
|
|
108
152
|
const options = {
|
|
109
153
|
skipPaths: ctx.options.skipPaths ?? DEFAULTS.skipPaths,
|
|
110
154
|
includeDefaultExports: ctx.options.includeDefaultExports ?? DEFAULTS.includeDefaultExports,
|
|
111
|
-
includeOrphanFiles: ctx.options.includeOrphanFiles ?? DEFAULTS.includeOrphanFiles
|
|
155
|
+
includeOrphanFiles: ctx.options.includeOrphanFiles ?? DEFAULTS.includeOrphanFiles,
|
|
156
|
+
includeTypeOnlyExports: ctx.options.includeTypeOnlyExports ?? DEFAULTS.includeTypeOnlyExports
|
|
112
157
|
};
|
|
113
158
|
const skipRegexes = compilePatterns(options.skipPaths);
|
|
114
159
|
if (matchesAny(ctx.file.path, skipRegexes)) return [];
|
|
@@ -119,15 +164,17 @@ var rule = {
|
|
|
119
164
|
const hasAnyIncomingEdge = incoming.some((e) => CONSUMING_KINDS.has(e.kind));
|
|
120
165
|
if (!hasAnyIncomingEdge && !options.includeOrphanFiles) return [];
|
|
121
166
|
const consumed = consumedNames(graph, ctx.file.path);
|
|
167
|
+
const lineOf = declarationLines(ctx.parsed);
|
|
122
168
|
const findings = [];
|
|
123
169
|
for (const symbol of node.symbols) {
|
|
124
170
|
if (!symbol.exported) continue;
|
|
125
171
|
if (symbol.name === "default" && !options.includeDefaultExports) continue;
|
|
172
|
+
if (!options.includeTypeOnlyExports && TYPE_ONLY_KINDS.has(symbol.kind)) continue;
|
|
126
173
|
if (consumed.has(symbol.name)) continue;
|
|
127
174
|
findings.push({
|
|
128
175
|
message: `Exported ${symbol.kind} '${symbol.name}' is not imported by any file in the project.`,
|
|
129
176
|
file: ctx.file.path,
|
|
130
|
-
range: { line: 1, column: 1 },
|
|
177
|
+
range: { line: lineOf.get(symbol.name) ?? 1, column: 1 },
|
|
131
178
|
suggestion: "Remove the export, mark the symbol non-exported (file-local), or move it behind the public API barrel that consumers actually import."
|
|
132
179
|
});
|
|
133
180
|
}
|