@code-sentinel-cli/code-sentinel-cli 3.0.10 → 3.0.12
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 +10044 -6056
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +2 -2
- 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 +2 -3
- 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 +2 -3
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +4 -8
- package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +2 -2
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +2 -2
- package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +2 -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.prompt.md +2 -3
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +2 -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.prompt.md +2 -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 +21 -4
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +8 -3
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +5 -5
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +2 -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 +2 -3
- 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 +2 -3
- 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 +6 -6
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/import-template-contract-risk.prompt.md +74 -0
- package/dist/builtin-rules/ai/spring-boot/import-template-contract-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/native-dml-consistency-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/native-dml-consistency-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/native-query-performance-risk.prompt.md +73 -0
- package/dist/builtin-rules/ai/spring-boot/native-query-performance-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +5 -5
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/pagination-query-consistency-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-query-consistency-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/partial-update-mapper-risk.prompt.md +73 -0
- package/dist/builtin-rules/ai/spring-boot/partial-update-mapper-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/query-contract-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/spring-boot/query-contract-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/query-date-boundary-risk.prompt.md +74 -0
- package/dist/builtin-rules/ai/spring-boot/query-date-boundary-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +2 -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.prompt.md +2 -2
- 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.prompt.md +2 -2
- 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.prompt.md +9 -4
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +6 -6
- package/dist/builtin-rules/ai/spring-boot/soft-delete-publication-consistency-risk.prompt.md +74 -0
- package/dist/builtin-rules/ai/spring-boot/soft-delete-publication-consistency-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +2 -2
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/versioned-entity-concurrency-risk.prompt.md +73 -0
- package/dist/builtin-rules/ai/spring-boot/versioned-entity-concurrency-risk.rule.yaml +24 -0
- 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 +348 -382
- package/dist/index.js +10045 -6057
- package/package.json +1 -1
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +0 -30
|
@@ -17,7 +17,8 @@ var rule = {
|
|
|
17
17
|
// is detected — the dominant OWASP-Benchmark command-injection List shape. The
|
|
18
18
|
// rule's projection logic is unchanged; the bump invalidates findings cached on
|
|
19
19
|
// unchanged file content before the broader analyzer coverage.
|
|
20
|
-
|
|
20
|
+
// v5 (ADR-0065 calibration): luồng taint trực tiếp → severity blocker
|
|
21
|
+
version: 5,
|
|
21
22
|
kind: "static-ts",
|
|
22
23
|
title: "Kh\xF4ng ch\u1EA1y l\u1EC7nh h\u1EC7 th\u1ED1ng t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (OS Command Injection)",
|
|
23
24
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o l\u1EC7nh h\u1EC7 \u0111i\u1EC1u h\xE0nh (`Runtime.getRuntime().exec(...)` ho\u1EB7c `ProcessBuilder.command(...)`) l\xE0 l\u1ED7 h\u1ED5ng OS Command Injection (CWE-78) \u2014 k\u1EBB t\u1EA5n c\xF4ng ch\xE8n \u0111\u01B0\u1EE3c l\u1EC7nh shell t\xF9y \xFD ch\u1EA1y tr\xEAn server (RCE). Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: tr\xE1nh g\u1ECDi shell; n\u1EBFu b\u1EAFt bu\u1ED9c, d\xF9ng allowlist l\u1EC7nh/tham s\u1ED1 c\u1ED1 \u0111\u1ECBnh v\xE0 truy\u1EC1n d\u1EA1ng m\u1EA3ng tham s\u1ED1 (kh\xF4ng n\u1ED1i chu\u1ED7i v\xE0o `sh -c`), kh\xF4ng bao gi\u1EDD d\u1EF1ng l\u1EC7nh t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp.",
|
|
@@ -40,6 +41,12 @@ var rule = {
|
|
|
40
41
|
message: `\u26A0 Command 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 ch\u1EA1y l\u1EC7nh h\u1EC7 th\u1ED1ng t\xF9y \xFD tr\xEAn server (RCE).${trace}`,
|
|
41
42
|
file: ctx.file.path,
|
|
42
43
|
range: { line: tf.line, column: tf.column ?? 1 },
|
|
44
|
+
// ADR-0065 (calibration): luồng TRỰC TIẾP source→sink lớp RCE là đúng
|
|
45
|
+
// thứ tầng `blocker` sinh ra để chặn — trước bản này catalog KHÔNG có
|
|
46
|
+
// rule nào phát `blocker`, nên thang 4 mức thực chất chỉ có 3.
|
|
47
|
+
// Luồng laundered (truy vết liên thủ tục) giữ `error`: bằng chứng yếu
|
|
48
|
+
// hơn một bậc, không đủ để chặn merge.
|
|
49
|
+
severity: laundered ? "error" : "blocker",
|
|
43
50
|
confidence: laundered ? 75 : 85,
|
|
44
51
|
suggestion: 'Tr\xE1nh g\u1ECDi shell v\u1EDBi d\u1EEF li\u1EC7u ng\u01B0\u1EDDi d\xF9ng. N\u1EBFu b\u1EAFt bu\u1ED9c: validate b\u1EB1ng allowlist l\u1EC7nh/tham s\u1ED1 c\u1ED1 \u0111\u1ECBnh, truy\u1EC1n tham s\u1ED1 d\u1EA1ng m\u1EA3ng (`new ProcessBuilder(List.of("cmd", arg))`) thay v\xEC n\u1ED1i chu\u1ED7i v\xE0o `sh -c`. Tuy\u1EC7t \u0111\u1ED1i kh\xF4ng d\u1EF1ng l\u1EC7nh t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp.'
|
|
45
52
|
});
|
|
@@ -5,7 +5,8 @@ var SINK_LABEL = {
|
|
|
5
5
|
};
|
|
6
6
|
var rule = {
|
|
7
7
|
id: "spring-boot/no-spel-injection",
|
|
8
|
-
|
|
8
|
+
// v3 (ADR-0065 calibration): luồng taint trực tiếp → severity blocker
|
|
9
|
+
version: 3,
|
|
9
10
|
kind: "static-ts",
|
|
10
11
|
title: "Kh\xF4ng parse SpEL t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (Expression Language Injection)",
|
|
11
12
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o `ExpressionParser.parseExpression(...)` l\xE0 l\u1ED7 h\u1ED5ng Expression Language (SpEL) Injection (CWE-917) \u2014 bi\u1EC3u th\u1EE9c SpEL do k\u1EBB t\u1EA5n c\xF4ng ki\u1EC3m so\xE1t c\xF3 th\u1EC3 g\u1ECDi method t\xF9y \xFD (`T(java.lang.Runtime).getRuntime().exec(...)`) \u2192 RCE. Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: kh\xF4ng bao gi\u1EDD parse SpEL t\u1EEB input ng\u01B0\u1EDDi d\xF9ng; n\u1EBFu c\u1EA7n bi\u1EC3u th\u1EE9c \u0111\u1ED9ng, d\xF9ng allowlist bi\u1EC3u th\u1EE9c c\u1ED1 \u0111\u1ECBnh, ho\u1EB7c `SimpleEvaluationContext` (ch\u1EB7n type reference / method call nguy hi\u1EC3m) thay cho `StandardEvaluationContext`.",
|
|
@@ -28,6 +29,12 @@ var rule = {
|
|
|
28
29
|
message: `\u26A0 SpEL 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 ch\u1EA1y m\xE3 t\xF9y \xFD qua bi\u1EC3u th\u1EE9c SpEL (RCE).${trace}`,
|
|
29
30
|
file: ctx.file.path,
|
|
30
31
|
range: { line: tf.line, column: tf.column ?? 1 },
|
|
32
|
+
// ADR-0065 (calibration): luồng TRỰC TIẾP source→sink lớp RCE là đúng
|
|
33
|
+
// thứ tầng `blocker` sinh ra để chặn — trước bản này catalog KHÔNG có
|
|
34
|
+
// rule nào phát `blocker`, nên thang 4 mức thực chất chỉ có 3.
|
|
35
|
+
// Luồng laundered (truy vết liên thủ tục) giữ `error`: bằng chứng yếu
|
|
36
|
+
// hơn một bậc, không đủ để chặn merge.
|
|
37
|
+
severity: laundered ? "error" : "blocker",
|
|
31
38
|
confidence: laundered ? 75 : 85,
|
|
32
39
|
suggestion: "Kh\xF4ng parse SpEL t\u1EEB input ng\u01B0\u1EDDi d\xF9ng. N\u1EBFu c\u1EA7n bi\u1EC3u th\u1EE9c \u0111\u1ED9ng: d\xF9ng allowlist bi\u1EC3u th\u1EE9c c\u1ED1 \u0111\u1ECBnh, ho\u1EB7c \u0111\xE1nh gi\xE1 v\u1EDBi `SimpleEvaluationContext` (ch\u1EB7n type reference / g\u1ECDi method nguy hi\u1EC3m) thay cho `StandardEvaluationContext`. Tuy\u1EC7t \u0111\u1ED1i kh\xF4ng d\u1EF1ng bi\u1EC3u th\u1EE9c t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp."
|
|
33
40
|
});
|
|
@@ -152,7 +152,8 @@ var isConcatRoot = (node) => {
|
|
|
152
152
|
};
|
|
153
153
|
var rule = {
|
|
154
154
|
id: "spring-boot/no-sql-string-concat",
|
|
155
|
-
|
|
155
|
+
// v7 (ADR-0065 calibration): band CONFIRMED → severity blocker
|
|
156
|
+
version: 7,
|
|
156
157
|
kind: "static-ts",
|
|
157
158
|
title: "Kh\xF4ng n\u1ED1i SQL b\u1EB1ng `+` \u2014 d\xF9ng prepared statement / named parameter",
|
|
158
159
|
description: "N\u1ED1i chu\u1ED7i SQL b\u1EB1ng `+` l\xE0 pattern \u0111i\u1EC3n h\xECnh c\u1EE7a SQL Injection. v2 d\xF9ng taint analysis: n\u1ED1i c\xF3 gi\xE1 tr\u1ECB t\u1EEB request (taint-confirmed) \u2192 error tin c\u1EADy cao; n\u1ED1i to\xE0n h\u1EB1ng s\u1ED1 (literal / `static final`) \u2192 b\u1ECF qua; c\xF2n l\u1EA1i gi\u1EEF c\u1EA3nh b\xE1o nh\u01B0 v1. D\xF9ng JdbcTemplate `?` + args, JPQL `:param` + `setParameter(...)`, ho\u1EB7c Spring Data query methods.",
|
|
@@ -197,6 +198,10 @@ var rule = {
|
|
|
197
198
|
message: `\u26A0 SQL Injection x\xE1c nh\u1EADn: gi\xE1 tr\u1ECB t\u1EEB request (${sources}) n\u1ED1i th\u1EB3ng v\xE0o c\xE2u SQL \u2014 d\xF9ng prepared statement / named parameter.`,
|
|
198
199
|
file: ctx.file.path,
|
|
199
200
|
range,
|
|
201
|
+
// ADR-0065: band CONFIRMED = taint đã xác nhận request→SQL sink.
|
|
202
|
+
// Đó là bằng chứng mạnh nhất rule này có → `blocker`. Band UNKNOWN
|
|
203
|
+
// bên dưới vẫn `warning`/55 (advisory) theo ADR-0031.
|
|
204
|
+
severity: "blocker",
|
|
200
205
|
confidence: 90,
|
|
201
206
|
suggestion: "Bind tham s\u1ED1: JdbcTemplate `?` + args, ho\u1EB7c JPQL `:param` + `setParameter(...)`."
|
|
202
207
|
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/static/spring-boot/no-unzoned-datetime.rule.ts
|
|
4
|
+
var UNZONED_STATIC_OBJECTS = /* @__PURE__ */ new Set([
|
|
5
|
+
"LocalDateTime",
|
|
6
|
+
"LocalDate",
|
|
7
|
+
"LocalTime"
|
|
8
|
+
]);
|
|
9
|
+
var CALENDAR_OBJECTS = /* @__PURE__ */ new Set(["Calendar", "GregorianCalendar"]);
|
|
10
|
+
var isTestFile = (path) => {
|
|
11
|
+
const norm = path.replace(/\\/g, "/").toLowerCase();
|
|
12
|
+
return norm.includes("/test/") || norm.includes("/test-fixtures/") || norm.endsWith("test.java") || norm.endsWith("tests.java") || norm.endsWith("testcase.java");
|
|
13
|
+
};
|
|
14
|
+
function* walkNodes(node) {
|
|
15
|
+
const stack = [node];
|
|
16
|
+
while (stack.length > 0) {
|
|
17
|
+
const cur = stack.pop();
|
|
18
|
+
if (!cur) break;
|
|
19
|
+
yield cur;
|
|
20
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
21
|
+
const child = cur.namedChild(i);
|
|
22
|
+
if (child) stack.push(child);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var rule = {
|
|
27
|
+
id: "spring-boot/no-unzoned-datetime",
|
|
28
|
+
version: 1,
|
|
29
|
+
kind: "static-ts",
|
|
30
|
+
title: "Kh\xF4ng g\u1ECDi `LocalDateTime.now()` ho\u1EB7c `new Date()` thi\u1EBFu `Clock`/`ZoneId`",
|
|
31
|
+
description: "G\u1ECDi `LocalDateTime.now()`, `new Date()`, `Calendar.getInstance()` kh\xF4ng truy\u1EC1n `Clock` ho\u1EB7c `ZoneId` ng\u1EA7m s\u1EED d\u1EE5ng m\xFAi gi\u1EDD c\u1EE7a m\xE1y ch\u1EE7. Khi ch\u1EA1y tr\xEAn m\xF4i tr\u01B0\u1EDDng Cloud/K8s c\xF3 m\xFAi gi\u1EDD UTC, \u0111i\u1EC1u n\xE0y d\u1EABn \u0111\u1EBFn sai l\u1EC7ch d\u1EEF li\u1EC7u ng\xE0y gi\u1EDD v\xE0 kh\xF4ng th\u1EC3 mock khi vi\u1EBFt test.",
|
|
32
|
+
severity: "warning",
|
|
33
|
+
category: "correctness",
|
|
34
|
+
languages: ["java"],
|
|
35
|
+
scope: "spring-boot",
|
|
36
|
+
requires: "syntactic",
|
|
37
|
+
baseConfidence: 80,
|
|
38
|
+
check(ctx) {
|
|
39
|
+
if (isTestFile(ctx.file.path)) return [];
|
|
40
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
41
|
+
const findings = [];
|
|
42
|
+
for (const node of walkNodes(tree.rootNode)) {
|
|
43
|
+
if (node.type === "method_invocation") {
|
|
44
|
+
const nameNode = node.childForFieldName("name");
|
|
45
|
+
const objectNode = node.childForFieldName("object");
|
|
46
|
+
const argsNode = node.childForFieldName("arguments");
|
|
47
|
+
if (nameNode && objectNode && argsNode) {
|
|
48
|
+
const methodName = nameNode.text;
|
|
49
|
+
const objectName = objectNode.text;
|
|
50
|
+
const argCount = argsNode.namedChildCount;
|
|
51
|
+
if (methodName === "now" && UNZONED_STATIC_OBJECTS.has(objectName) && argCount === 0) {
|
|
52
|
+
findings.push({
|
|
53
|
+
message: `G\u1ECDi \`${objectName}.now()\` kh\xF4ng truy\u1EC1n \`ZoneId\` ho\u1EB7c \`Clock\` \u2014 r\u1EE7i ro sai l\u1EC7ch m\xFAi gi\u1EDD tr\xEAn K8s/Cloud v\xE0 kh\xF4ng th\u1EC3 mock khi vi\u1EBFt unit test.`,
|
|
54
|
+
file: ctx.file.path,
|
|
55
|
+
range: {
|
|
56
|
+
line: node.startPosition.row + 1,
|
|
57
|
+
column: node.startPosition.column + 1
|
|
58
|
+
},
|
|
59
|
+
suggestion: `D\xF9ng \`Instant.now(clock)\` ho\u1EB7c truy\u1EC1n \`ZoneId.of("...")\` / \`Clock\` v\xE0o \`${objectName}.now(...)\`.`
|
|
60
|
+
});
|
|
61
|
+
} else if (methodName === "getInstance" && CALENDAR_OBJECTS.has(objectName) && argCount === 0) {
|
|
62
|
+
findings.push({
|
|
63
|
+
message: `G\u1ECDi \`${objectName}.getInstance()\` ng\u1EA7m l\u1EA5y timezone v\xE0 locale c\u1EE7a JVM. N\xEAn d\xF9ng java.time API (\`ZonedDateTime\`, \`Instant\`) v\u1EDBi Clock t\u01B0\u1EDDng minh.`,
|
|
64
|
+
file: ctx.file.path,
|
|
65
|
+
range: {
|
|
66
|
+
line: node.startPosition.row + 1,
|
|
67
|
+
column: node.startPosition.column + 1
|
|
68
|
+
},
|
|
69
|
+
suggestion: "Chuy\u1EC3n sang d\xF9ng `java.time` API (`ZonedDateTime.now(zoneId)` / `Instant.now(clock)`)."
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (node.type === "object_creation_expression") {
|
|
75
|
+
const typeNode = node.childForFieldName("type");
|
|
76
|
+
const argsNode = node.childForFieldName("arguments");
|
|
77
|
+
if (typeNode && argsNode && typeNode.text === "Date" && argsNode.namedChildCount === 0) {
|
|
78
|
+
findings.push({
|
|
79
|
+
message: "Kh\u1EDFi t\u1EA1o `new Date()` ng\u1EA7m s\u1EED d\u1EE5ng system clock c\u1EE7a m\xE1y ch\u1EE7 v\xE0 l\xE0 legacy API. N\xEAn d\xF9ng `Instant.now(clock)` \u0111\u1EC3 c\xF3 th\u1EC3 inject Clock khi test.",
|
|
80
|
+
file: ctx.file.path,
|
|
81
|
+
range: {
|
|
82
|
+
line: node.startPosition.row + 1,
|
|
83
|
+
column: node.startPosition.column + 1
|
|
84
|
+
},
|
|
85
|
+
suggestion: "S\u1EED d\u1EE5ng `Instant.now(clock)` ho\u1EB7c `Clock.systemUTC()` thay cho `new Date()`."
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return findings;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { rule };
|
|
95
|
+
//# sourceMappingURL=no-unzoned-datetime.rule.js.map
|
|
96
|
+
//# sourceMappingURL=no-unzoned-datetime.rule.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
id: spring-boot/repository-naming
|
|
2
|
-
|
|
2
|
+
# v2 (ADR-0065 calibration): severity warning→info (quy ước đặt tên)
|
|
3
|
+
version: 2
|
|
3
4
|
kind: static-yaml
|
|
4
5
|
title: "Spring Data interface phải kết thúc bằng `Repository`"
|
|
5
6
|
description: |
|
|
@@ -14,7 +15,8 @@ description: |
|
|
|
14
15
|
Phase 8: dùng negative lookahead `(?!...)` trong regex predicate để
|
|
15
16
|
loại trừ tên đã đúng (vd `UserRepository`). Match cả `extends X` lẫn
|
|
16
17
|
`extends X<...>` (generic).
|
|
17
|
-
|
|
18
|
+
# ADR-0065: quy ước đặt tên thuần tuý → info (đồng bộ angular/observable-naming).
|
|
19
|
+
severity: info
|
|
18
20
|
category: naming
|
|
19
21
|
languages: [java]
|
|
20
22
|
scope: spring-boot
|