@code-sentinel-cli/code-sentinel-cli 3.0.2 → 3.0.4

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.
Files changed (130) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +63 -4
  3. package/dist/bin.js +1266 -795
  4. package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
  5. package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
  6. package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
  7. package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
  8. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
  9. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
  10. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
  11. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
  12. package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
  13. package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
  14. package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
  15. package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
  16. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
  17. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
  18. package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
  19. package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
  20. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
  21. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
  22. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
  23. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
  24. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
  25. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
  26. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
  27. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
  28. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
  29. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
  30. package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
  31. package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
  32. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
  33. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
  34. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
  35. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
  36. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
  37. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
  38. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
  39. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
  40. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
  41. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
  42. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
  43. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
  44. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
  45. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
  46. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
  47. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
  48. package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
  49. package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
  50. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
  51. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
  52. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
  53. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
  54. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
  55. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
  56. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
  57. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
  58. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
  59. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
  60. package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
  61. package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
  62. package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
  63. package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
  64. package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
  65. package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
  66. package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
  67. package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
  68. package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
  69. package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
  70. package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
  71. package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
  72. package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
  73. package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
  74. package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
  75. package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
  76. package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
  77. package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
  78. package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
  79. package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
  80. package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
  81. package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
  82. package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
  83. package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
  84. package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
  85. package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
  86. package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
  87. package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
  88. package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
  89. package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
  90. package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
  91. package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
  92. package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
  93. package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
  94. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
  95. package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
  96. package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
  97. package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
  98. package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
  99. package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
  100. package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
  101. package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
  102. package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
  103. package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
  104. package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
  105. package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
  106. package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
  107. package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
  108. package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
  109. package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
  110. package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
  111. package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
  112. package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
  113. package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
  114. package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
  115. package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
  116. package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
  117. package/dist/index.d.ts +224 -47
  118. package/dist/index.js +1264 -793
  119. package/package.json +7 -5
  120. package/src/migrations/0000_initial.sql +62 -0
  121. package/src/migrations/0001_add_confidence.sql +7 -0
  122. package/src/migrations/0002_add_ai_stats.sql +21 -0
  123. package/src/migrations/0003_add_fix_recipe.sql +29 -0
  124. package/src/migrations/0004_add_ast_graph.sql +61 -0
  125. package/src/migrations/0005_add_project_id.sql +1 -0
  126. package/src/migrations/0006_add_ai_model.sql +5 -0
  127. package/src/migrations/0006_add_rule_results.sql +1 -0
  128. package/src/migrations/0007_add_finding_metadata.sql +4 -0
  129. package/src/migrations/0008_add_coverage.sql +2 -0
  130. package/src/migrations/0009_run_provenance.sql +5 -0
@@ -0,0 +1,41 @@
1
+ // builtin-rules/static/general/file-too-long.rule.ts
2
+ var countLines = (content) => {
3
+ if (content.length === 0) return 0;
4
+ let n = 1;
5
+ for (let i = 0; i < content.length; i++) {
6
+ if (content.charCodeAt(i) === 10) n++;
7
+ }
8
+ if (content.charCodeAt(content.length - 1) === 10) n--;
9
+ return n;
10
+ };
11
+ var rule = {
12
+ id: "general/file-too-long",
13
+ version: 3,
14
+ kind: "static-ts",
15
+ title: "File qu\xE1 d\xE0i \u2014 c\xE2n nh\u1EAFc t\xE1ch module",
16
+ 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
+ severity: "warning",
18
+ category: "maintainability",
19
+ languages: ["typescript", "javascript", "java"],
20
+ scope: "general",
21
+ requires: "syntactic",
22
+ baseConfidence: 60,
23
+ defaultOptions: { maxLines: 500 },
24
+ check(ctx) {
25
+ const threshold = ctx.options.maxLines;
26
+ const lineCount = countLines(ctx.file.content);
27
+ if (lineCount <= threshold) return [];
28
+ return [
29
+ {
30
+ message: `File c\xF3 ${lineCount} d\xF2ng (gi\u1EDBi h\u1EA1n ${threshold}) \u2014 c\xE2n nh\u1EAFc t\xE1ch th\xE0nh module nh\u1ECF h\u01A1n.`,
31
+ file: ctx.file.path,
32
+ range: { line: 1, column: 1 },
33
+ suggestion: "T\xE1ch theo tr\xE1ch nhi\u1EC7m: helpers / types / services / components m\u1ED7i file m\u1ED9t file."
34
+ }
35
+ ];
36
+ }
37
+ };
38
+
39
+ export { rule };
40
+ //# sourceMappingURL=file-too-long.rule.js.map
41
+ //# sourceMappingURL=file-too-long.rule.js.map
@@ -0,0 +1,72 @@
1
+ import { asTsMorphSourceFile } from '@code-sentinel/parsers';
2
+ import { Node } from 'ts-morph';
3
+
4
+ // builtin-rules/static/general/function-too-long.rule.ts
5
+ var getName = (node) => {
6
+ if (Node.isFunctionDeclaration(node) || Node.isMethodDeclaration(node) || Node.isFunctionExpression(node)) {
7
+ return node.getName() ?? "<anonymous>";
8
+ }
9
+ if (Node.isArrowFunction(node)) {
10
+ const parent = node.getParent();
11
+ if (parent && Node.isVariableDeclaration(parent)) return parent.getName();
12
+ if (parent && Node.isPropertyAssignment(parent)) return parent.getName();
13
+ return "<arrow>";
14
+ }
15
+ return "<function>";
16
+ };
17
+ var collectFunctionLikeNodes = (sf) => {
18
+ const nodes = [];
19
+ sf.forEachDescendant((node) => {
20
+ if (Node.isFunctionDeclaration(node) || Node.isMethodDeclaration(node) || Node.isFunctionExpression(node) || Node.isArrowFunction(node)) {
21
+ nodes.push(node);
22
+ }
23
+ });
24
+ return nodes;
25
+ };
26
+ var rule = {
27
+ id: "general/function-too-long",
28
+ version: 3,
29
+ kind: "static-ts",
30
+ title: "H\xE0m qu\xE1 d\xE0i \u2014 t\xE1ch helper ho\u1EB7c step nh\u1ECF h\u01A1n",
31
+ 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
+ severity: "warning",
33
+ category: "maintainability",
34
+ languages: ["typescript", "javascript"],
35
+ scope: "general",
36
+ requires: "semantic-ts",
37
+ baseConfidence: 65,
38
+ defaultOptions: { maxLines: 80 },
39
+ check(ctx) {
40
+ const threshold = ctx.options.maxLines;
41
+ const sf = asTsMorphSourceFile(ctx.parsed);
42
+ const findings = [];
43
+ for (const node of collectFunctionLikeNodes(sf)) {
44
+ const start = node.getStartLineNumber();
45
+ const end = node.getEndLineNumber();
46
+ const lines = end - start + 1;
47
+ if (lines <= threshold) continue;
48
+ const parent = node.getParent();
49
+ let isNested = false;
50
+ let cur = parent;
51
+ while (cur) {
52
+ if (Node.isFunctionDeclaration(cur) || Node.isMethodDeclaration(cur) || Node.isFunctionExpression(cur) || Node.isArrowFunction(cur)) {
53
+ isNested = true;
54
+ break;
55
+ }
56
+ cur = cur.getParent();
57
+ }
58
+ if (isNested) continue;
59
+ findings.push({
60
+ message: `H\xE0m "${getName(node)}" d\xE0i ${lines} d\xF2ng (gi\u1EDBi h\u1EA1n ${threshold}).`,
61
+ file: ctx.file.path,
62
+ range: { line: start, column: 1 },
63
+ 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
+ });
65
+ }
66
+ return findings;
67
+ }
68
+ };
69
+
70
+ export { rule };
71
+ //# sourceMappingURL=function-too-long.rule.js.map
72
+ //# sourceMappingURL=function-too-long.rule.js.map
@@ -0,0 +1,39 @@
1
+ import { findDirectedCycles } from '@code-sentinel/core';
2
+
3
+ // builtin-rules/static/general/no-circular-import.rule.ts
4
+ var importLikeKinds = ["import", "re-export"];
5
+ var formatCycle = (paths) => paths.join(" -> ");
6
+ var rule = {
7
+ id: "general/no-circular-import",
8
+ version: 4,
9
+ kind: "static-ts",
10
+ title: "Kh\xF4ng t\u1EA1o v\xF2ng import gi\u1EEFa c\xE1c file",
11
+ description: "V\xF2ng import l\xE0m module kh\u1EDFi t\u1EA1o kh\xF4ng \u1ED5n \u0111\u1ECBnh, d\u1EC5 sinh undefined runtime v\xE0 che gi\u1EA5u coupling gi\u1EEFa c\xE1c layer.",
12
+ severity: "warning",
13
+ category: "architecture",
14
+ languages: ["typescript", "javascript"],
15
+ scope: "general",
16
+ requires: "semantic-ts",
17
+ usesAstGraph: true,
18
+ baseConfidence: 95,
19
+ check(ctx) {
20
+ if (!ctx.astGraph) return [];
21
+ const cycles = findDirectedCycles(ctx.astGraph, { edgeKinds: importLikeKinds });
22
+ const findings = [];
23
+ for (const cycle of cycles) {
24
+ const primaryPath = cycle.paths[0];
25
+ if (primaryPath !== ctx.file.path) continue;
26
+ findings.push({
27
+ message: `Circular import detected: ${formatCycle(cycle.paths)}`,
28
+ file: ctx.file.path,
29
+ range: { line: 1, column: 1 },
30
+ suggestion: "Break the dependency by extracting shared types/utilities or moving one dependency behind an interface boundary."
31
+ });
32
+ }
33
+ return findings;
34
+ }
35
+ };
36
+
37
+ export { rule };
38
+ //# sourceMappingURL=no-circular-import.rule.js.map
39
+ //# sourceMappingURL=no-circular-import.rule.js.map
@@ -0,0 +1,48 @@
1
+ // builtin-rules/static/general/no-code-injection.rule.ts
2
+ var CODE_INJECTION_SINK_IDS = /* @__PURE__ */ new Set([
3
+ "general/eval-call",
4
+ "general/timer-string",
5
+ "general/function-ctor"
6
+ ]);
7
+ var SINK_LABEL = {
8
+ "general/eval-call": "eval(...)",
9
+ "general/timer-string": "setTimeout / setInterval (d\u1EA1ng chu\u1ED7i)",
10
+ "general/function-ctor": "new Function(...)"
11
+ };
12
+ var rule = {
13
+ id: "general/no-code-injection",
14
+ version: 2,
15
+ kind: "static-ts",
16
+ 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
+ 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`.',
18
+ severity: "error",
19
+ category: "security",
20
+ languages: ["typescript"],
21
+ scope: "general",
22
+ requires: "syntactic",
23
+ usesTaint: true,
24
+ usesAstGraph: true,
25
+ baseConfidence: 80,
26
+ check(ctx) {
27
+ const findings = [];
28
+ for (const tf of ctx.taintFindings ?? []) {
29
+ if (!CODE_INJECTION_SINK_IDS.has(tf.sinkId)) continue;
30
+ const sources = [...new Set(tf.sourceIds)].join(", ");
31
+ const laundered = (tf.path?.length ?? 0) > 0;
32
+ const sinkLabel = SINK_LABEL[tf.sinkId] ?? tf.sinkId;
33
+ const trace = laundered ? " (truy v\u1EBFt li\xEAn h\xE0m/li\xEAn file)" : "";
34
+ findings.push({
35
+ 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
+ file: ctx.file.path,
37
+ range: { line: tf.line, column: tf.column ?? 1 },
38
+ confidence: laundered ? 75 : 85,
39
+ 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
+ });
41
+ }
42
+ return findings;
43
+ }
44
+ };
45
+
46
+ export { rule };
47
+ //# sourceMappingURL=no-code-injection.rule.js.map
48
+ //# sourceMappingURL=no-code-injection.rule.js.map
@@ -0,0 +1,110 @@
1
+ import { asTreeSitterTree } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-console-log.rule.ts
4
+ var CLI_FRAMEWORK_IMPORTS = /* @__PURE__ */ new Set([
5
+ "commander",
6
+ "yargs",
7
+ "meow",
8
+ "cac",
9
+ "sade",
10
+ "@inquirer/prompts",
11
+ "inquirer",
12
+ "enquirer"
13
+ ]);
14
+ var CLI_PATH_SEGMENTS = ["/cli/", "/bin/", "/commands/", "/scripts/"];
15
+ var isCliByPath = (path) => {
16
+ const posix = path.replace(/\\/g, "/");
17
+ const padded = `/${posix}/`;
18
+ for (const seg of CLI_PATH_SEGMENTS) {
19
+ if (padded.includes(seg)) return true;
20
+ }
21
+ return false;
22
+ };
23
+ function* walk(node, type) {
24
+ const stack = [node];
25
+ while (stack.length > 0) {
26
+ const cur = stack.pop();
27
+ if (!cur) continue;
28
+ if (cur.type === type) yield cur;
29
+ for (let i = cur.namedChildCount - 1; i >= 0; i--) {
30
+ const child = cur.namedChild(i);
31
+ if (child) stack.push(child);
32
+ }
33
+ }
34
+ }
35
+ var isCliFile = (rootNode) => {
36
+ for (const imp of walk(rootNode, "import_statement")) {
37
+ for (let i = 0; i < imp.namedChildCount; i++) {
38
+ const child = imp.namedChild(i);
39
+ if (!child) continue;
40
+ if (child.type !== "string") continue;
41
+ const raw = child.text;
42
+ const inner = raw.replace(/^['"]|['"]$/g, "");
43
+ if (CLI_FRAMEWORK_IMPORTS.has(inner)) return true;
44
+ }
45
+ }
46
+ return false;
47
+ };
48
+ var findConsoleLogCalls = (rootNode, filePath) => {
49
+ const findings = [];
50
+ for (const call of walk(rootNode, "call_expression")) {
51
+ const fn = call.childForFieldName("function");
52
+ if (!fn || fn.type !== "member_expression") continue;
53
+ const obj = fn.childForFieldName("object");
54
+ const prop = fn.childForFieldName("property");
55
+ if (!obj || !prop) continue;
56
+ if (obj.type !== "identifier" || obj.text !== "console") continue;
57
+ if (prop.text !== "log") continue;
58
+ findings.push({
59
+ message: "D\xF9ng logger thay v\xEC console.log.",
60
+ file: filePath,
61
+ range: {
62
+ line: call.startPosition.row + 1,
63
+ column: call.startPosition.column + 1
64
+ },
65
+ suggestion: "Inject logger t\u1EEB @code-sentinel/shared (createLogger) v\xE0 g\u1ECDi logger.info / logger.debug.",
66
+ fix: {
67
+ safety: "unsafe",
68
+ description: "Replace `console.log` with `logger.info`",
69
+ edits: [
70
+ {
71
+ file: filePath,
72
+ startLine: fn.startPosition.row + 1,
73
+ startColumn: fn.startPosition.column + 1,
74
+ endLine: fn.endPosition.row + 1,
75
+ endColumn: fn.endPosition.column + 1,
76
+ // exclusive — matches LSP shape
77
+ newText: "logger.info"
78
+ }
79
+ ]
80
+ }
81
+ });
82
+ }
83
+ return findings;
84
+ };
85
+ var rule = {
86
+ id: "general/no-console-log",
87
+ // version: 3 — Phase 14.3 invalidates Phase-10-era cache (rule logic
88
+ // unchanged; output gained `fix` field). Bumping is forward-only per
89
+ // DEVELOPMENT.md "cache invalidation via rule.version is one-way".
90
+ version: 3,
91
+ kind: "static-ts",
92
+ title: "Kh\xF4ng d\xF9ng console.log trong source code",
93
+ 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.",
94
+ severity: "warning",
95
+ category: "logging",
96
+ languages: ["typescript", "javascript"],
97
+ scope: "general",
98
+ requires: "syntactic",
99
+ baseConfidence: 85,
100
+ check(ctx) {
101
+ if (isCliByPath(ctx.file.path)) return [];
102
+ const tree = asTreeSitterTree(ctx.parsed);
103
+ if (isCliFile(tree.rootNode)) return [];
104
+ return findConsoleLogCalls(tree.rootNode, ctx.file.path);
105
+ }
106
+ };
107
+
108
+ export { rule };
109
+ //# sourceMappingURL=no-console-log.rule.js.map
110
+ //# sourceMappingURL=no-console-log.rule.js.map
@@ -0,0 +1,56 @@
1
+ id: general/no-empty-catch
2
+ # version: 3 — fix recipe no longer inserts a TODO marker that would trigger
3
+ # `general/no-todo-comment`; detector logic unchanged.
4
+ version: 3
5
+ kind: static-yaml
6
+ title: "Không để catch block rỗng — log hoặc rethrow lỗi"
7
+ description: |
8
+ catch block rỗng nuốt mất exception, làm bug ẩn rất khó debug. Tối thiểu
9
+ phải log lỗi (logger.error / logger.warn) hoặc rethrow. Nếu cố ý ignore
10
+ cho test code, thêm comment giải thích tại sao.
11
+
12
+ Phase 8 đơn giản: flag mọi `statement_block` thuộc `catch_clause` mà text
13
+ chỉ chứa `{}` + whitespace. Block có comment vẫn được phép (vì comment đã
14
+ ghi rõ ý đồ).
15
+ severity: warning
16
+ category: error-handling
17
+ languages: [typescript, javascript]
18
+ scope: general
19
+ baseConfidence: 90
20
+ detection:
21
+ type: tree-sitter
22
+ captureName: violation
23
+ query: |
24
+ (catch_clause body: (statement_block) @violation)
25
+ (#match? @violation "^\\{\\s*\\}$")
26
+ message: "catch block rỗng — log lỗi hoặc rethrow."
27
+ suggestion: "Tối thiểu `logger.warn({ err }, 'context')`. Nếu cố ý nuốt, thêm comment giải thích."
28
+ # Phase 14.3/2026-06-07 — UNSAFE fix: replace `{}` with a neutral marker
29
+ # that does NOT trigger `general/no-todo-comment`.
30
+ # Rationale:
31
+ # - SATISFIES this rule's own logic: the regex `^\\{\\s*\\}$` no longer
32
+ # matches because the block contains a comment (per the description:
33
+ # "Block có comment vẫn được phép").
34
+ # - Does NOT introduce a new `general/no-todo-comment` finding. Earlier v2
35
+ # used a TODO marker, which made one unsafe fix create another finding.
36
+ # - Compile-safe: a comment-only catch block is valid in TS/JS.
37
+ # - UNSAFE because: the comment is a marker — the user still needs to
38
+ # add real error handling. Marking unsafe forces opt-in via `--unsafe`
39
+ # so the fix doesn't silently green-light empty-catch-with-comment in
40
+ # a pre-commit hook.
41
+ fix:
42
+ safety: unsafe
43
+ description: "Insert an unhandled-error marker comment (you still need to write the handler)"
44
+ replacement: "{ /* unhandled error: log or rethrow */ }"
45
+ examples:
46
+ good: |
47
+ try {
48
+ doWork();
49
+ } catch (err) {
50
+ logger.error({ err }, 'doWork failed');
51
+ throw err;
52
+ }
53
+ bad: |
54
+ try {
55
+ doWork();
56
+ } catch (err) {}