pi-lens 4.4.7 → 4.4.9
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/CHANGELOG-USER.md +31 -0
- package/CHANGELOG.md +327 -0
- package/README.md +13 -2
- package/config/dependency-cruiser-eager-allowlist.json +1 -1
- package/config/markdownlint/run-no-fix.mjs +36 -0
- package/dist/{chunk-4LM3VAZH.js → chunk-2VZ3VN3N.js} +2 -2
- package/dist/{chunk-PUZ3E2J4.js → chunk-3HTZDY3C.js} +8 -6
- package/dist/{chunk-RORGS5II.js → chunk-3NPWO5UO.js} +7 -13
- package/dist/{chunk-MNJIXFX4.js → chunk-47UCC4MM.js} +1 -1
- package/dist/chunk-4ENEJHF4.js +198 -0
- package/dist/chunk-5GEYJJHG.js +22 -0
- package/dist/{chunk-U6VN4NVL.js → chunk-5YSEQHJN.js} +3 -3
- package/dist/{chunk-6IR3ZYIB.js → chunk-6GPB3JLL.js} +3 -3
- package/dist/{chunk-MB6PXBUA.js → chunk-7R5GZIA6.js} +7 -15
- package/dist/{chunk-DH5JPM3K.js → chunk-7UTSNTWM.js} +10 -9
- package/dist/{chunk-24BILSZW.js → chunk-7YTRG6YW.js} +2 -2
- package/dist/{chunk-KW5JQPO5.js → chunk-AACN5GNE.js} +2 -2
- package/dist/{chunk-PKES3ISE.js → chunk-ACRJ2GZ5.js} +2 -2
- package/dist/{chunk-4ZYJHQMB.js → chunk-C3YRO3EU.js} +10 -12
- package/dist/{chunk-PQJFG24Z.js → chunk-CB7PEVOJ.js} +1300 -946
- package/dist/{chunk-ABPKUVA4.js → chunk-CDFJF5YD.js} +1 -1
- package/dist/{chunk-T7A2HK2B.js → chunk-CJS6WE66.js} +17 -18
- package/dist/{chunk-3YY7IXIL.js → chunk-CM6BDY4E.js} +14 -60
- package/dist/{chunk-RZOXUSPC.js → chunk-CZCAZVTD.js} +16 -2
- package/dist/chunk-DGKFWQK4.js +23 -0
- package/dist/{chunk-NA7SEXHE.js → chunk-E65WJVI5.js} +7 -9
- package/dist/{chunk-2TF6RXWB.js → chunk-EKNYSXFB.js} +8 -10
- package/dist/{chunk-RRV3FNNM.js → chunk-EY6LY2HO.js} +27 -30
- package/dist/{chunk-LBLBAFG3.js → chunk-F6BEQWAK.js} +17 -5
- package/dist/{chunk-4L36HG27.js → chunk-FGNSESAC.js} +12 -14
- package/dist/{chunk-3FRLWYBG.js → chunk-FRUBVFXV.js} +39 -42
- package/dist/{chunk-FB5SCCPT.js → chunk-G22UNQID.js} +14 -15
- package/dist/{chunk-LV4UMYVH.js → chunk-GQTQUNCG.js} +26 -27
- package/dist/{chunk-E7HJ56Y7.js → chunk-H3BVMK47.js} +64 -73
- package/dist/chunk-H6FLQ5NW.js +28 -0
- package/dist/{chunk-QHSNL7B2.js → chunk-HEA3EM23.js} +15 -19
- package/dist/{chunk-AWDSEDER.js → chunk-HSOBIN22.js} +2 -2
- package/dist/{chunk-EAOK7MIZ.js → chunk-HYSKJMZK.js} +17 -4
- package/dist/{chunk-VUZWQ7UG.js → chunk-IICERRFF.js} +46 -72
- package/dist/{chunk-OXOI55RU.js → chunk-IILEH3ZC.js} +8 -10
- package/dist/{chunk-ZKXQKGWZ.js → chunk-J3Q2NYJR.js} +4 -3
- package/dist/{chunk-YHC2O2WO.js → chunk-JUZ67QZQ.js} +20 -9
- package/dist/chunk-KR5VGMVT.js +25 -0
- package/dist/{chunk-F7K5IBZG.js → chunk-KV6GQOGN.js} +41 -44
- package/dist/{chunk-SNDXCFRS.js → chunk-KXMJLOZF.js} +25 -23
- package/dist/{chunk-CB4WHS4H.js → chunk-L4Y3ROKQ.js} +3 -3
- package/dist/{chunk-3F6BMY53.js → chunk-L6WBJGQS.js} +1 -1
- package/dist/{chunk-MPKRJBPK.js → chunk-L7O774U7.js} +30 -32
- package/dist/{chunk-URCQWAQ4.js → chunk-LAHHGNAY.js} +21 -21
- package/dist/{chunk-V63BC55Q.js → chunk-LT62P654.js} +1 -1
- package/dist/{chunk-ZMAUPOMG.js → chunk-LWOM6LVS.js} +34 -34
- package/dist/{chunk-HO6LWE2E.js → chunk-MKPDIAZH.js} +21 -1
- package/dist/{chunk-2PHMIAKO.js → chunk-MN635QYA.js} +3 -4
- package/dist/{chunk-KDX35VXP.js → chunk-MQ4PPCJB.js} +166 -149
- package/dist/{chunk-QOE342SU.js → chunk-MRLH4MYU.js} +2 -2
- package/dist/{chunk-CE6VMBCB.js → chunk-N56BNAA6.js} +20 -21
- package/dist/{chunk-L3CMBQMH.js → chunk-N5CEGQPG.js} +14 -17
- package/dist/{chunk-7E2563GA.js → chunk-NCLO6E6N.js} +13 -33
- package/dist/{chunk-J6JP25XU.js → chunk-NL5LSKVD.js} +4 -3
- package/dist/{chunk-U7BD2QL7.js → chunk-NMUSOZ2D.js} +10 -12
- package/dist/{chunk-BZARLRJW.js → chunk-NOWH2VA2.js} +8 -33
- package/dist/{chunk-U2SDMG7C.js → chunk-NUSXS6YB.js} +6 -5
- package/dist/{chunk-ZJTT47IG.js → chunk-OSEKJEUU.js} +2 -2
- package/dist/{chunk-FZKFVUEC.js → chunk-OUYAUXAT.js} +647 -355
- package/dist/{chunk-ZE3KXHS7.js → chunk-PBZNYHMM.js} +84 -4
- package/dist/{chunk-U5HPROLA.js → chunk-PIIUNJIT.js} +2 -4
- package/dist/chunk-PKLB2XJL.js +8 -0
- package/dist/{chunk-RC2Z6K47.js → chunk-PRHYIA6X.js} +15 -6
- package/dist/{chunk-RQS4QQSD.js → chunk-PXQ45SGD.js} +2 -2
- package/dist/chunk-Q6JQKWPK.js +25 -0
- package/dist/{chunk-F6X3YJWD.js → chunk-QB7T2PHK.js} +2 -2
- package/dist/{chunk-TIQJPRDD.js → chunk-QGITU23N.js} +3 -2
- package/dist/chunk-QJJKOHLH.js +57 -0
- package/dist/{chunk-4LOE5R5P.js → chunk-QP33NKYC.js} +18 -15
- package/dist/{chunk-N5WSK2K7.js → chunk-QVBOXT3L.js} +12 -17
- package/dist/{chunk-DPGEAHZT.js → chunk-RNJFRXEN.js} +10 -18
- package/dist/{chunk-EKWX4WD3.js → chunk-RNXOWDM6.js} +10 -10
- package/dist/{chunk-O4BJFESU.js → chunk-RTFMDIKV.js} +1 -1
- package/dist/{chunk-LS3QJRUB.js → chunk-SIQHOB6P.js} +11 -13
- package/dist/{chunk-3K2F6UDZ.js → chunk-SLSMJPEF.js} +43 -42
- package/dist/chunk-T5QSLSMM.js +50 -0
- package/dist/chunk-TGQDAG4B.js +88 -0
- package/dist/{chunk-4YHYPW2G.js → chunk-THYHUIDR.js} +44 -13
- package/dist/{chunk-YVHBNSME.js → chunk-TMNUTMT5.js} +1099 -1100
- package/dist/{chunk-WDBICWH3.js → chunk-TOE2RRCS.js} +1 -1
- package/dist/chunk-TYHPVE5H.js +25 -0
- package/dist/chunk-UAKO2M6B.js +73 -0
- package/dist/chunk-UC5AXW5Z.js +20 -0
- package/dist/chunk-UTJP6WOS.js +28 -0
- package/dist/{chunk-DQZFQSR5.js → chunk-UXTQ3QPD.js} +4 -4
- package/dist/chunk-UYXV5NIS.js +20 -0
- package/dist/{chunk-KKCK636N.js → chunk-V2WDBOLZ.js} +10 -12
- package/dist/{chunk-PR6PO3ES.js → chunk-V67D6TMU.js} +22 -20
- package/dist/{chunk-VSFLRN5Y.js → chunk-VCRVNLE7.js} +135 -2
- package/dist/{chunk-CPSR3AVL.js → chunk-VO4JFPTV.js} +2 -2
- package/dist/{chunk-XT2HTCJ5.js → chunk-VWLSU3XV.js} +6 -5
- package/dist/{chunk-WME2OQST.js → chunk-W5E72HJA.js} +66 -24
- package/dist/{chunk-LLS45EWB.js → chunk-W7TY6HYX.js} +6 -8
- package/dist/{chunk-CCV2EU7T.js → chunk-WSSLVMDA.js} +12 -13
- package/dist/{chunk-YISME6ON.js → chunk-WTB4GKMH.js} +10 -1
- package/dist/{chunk-KPPJTH44.js → chunk-X5BJ3G2P.js} +64 -35
- package/dist/{chunk-JMEKXFOL.js → chunk-XKFO2SZV.js} +39 -34
- package/dist/{chunk-HR3OJ3TH.js → chunk-XLAI7UYY.js} +84 -31
- package/dist/{chunk-H7OR7DFZ.js → chunk-XO756WE5.js} +53 -37
- package/dist/{chunk-F5Z6URKM.js → chunk-XVB3Q2PG.js} +2 -4
- package/dist/{chunk-R5MOQM2H.js → chunk-YOXCCJDF.js} +607 -366
- package/dist/{chunk-ZGSJDWQU.js → chunk-ZCQBNPRH.js} +2 -2
- package/dist/chunk-ZD4KVFXI.js +234 -0
- package/dist/{chunk-WGRJOXED.js → chunk-ZDMFGACN.js} +1295 -966
- package/dist/{chunk-OSTKYB55.js → chunk-ZMMHHXSW.js} +1 -1
- package/dist/{chunk-75GAYVNO.js → chunk-ZPM7ZIFL.js} +6 -6
- package/dist/{chunk-LUBPZN36.js → chunk-ZVCDHYWZ.js} +9 -11
- package/dist/{chunk-Y7F7IEE3.js → chunk-ZZN74OGD.js} +102 -7
- package/dist/{chunk-L5JYIU47.js → chunk-ZZSJAR76.js} +39 -20
- package/dist/index.js +10933 -8644
- package/dist/mcp/analyze-cli.js +12 -17
- package/dist/mcp/cli.js +43 -42
- package/dist/mcp/server.js +3073 -1147
- package/dist/mcp/worker.js +61 -61
- package/dist/probes/installer.js +18 -19
- package/docs/adr/0003-git-guard-latch-writer.md +11 -6
- package/docs/agent-tools.md +58 -16
- package/docs/alignment-families.md +29 -0
- package/docs/analysisall.md +1 -1
- package/docs/ast-grep_rules_catalog.md +6 -4
- package/docs/ci-bot-pr-checks.md +128 -0
- package/docs/configuration.md +150 -12
- package/docs/defect-shapes.md +107 -15
- package/docs/engineering-principles.md +27 -2
- package/docs/environment-variables.md +18 -1
- package/docs/features.md +14 -7
- package/docs/globalconfig.md +11 -3
- package/docs/invariants/git-guard-host.md +7 -3
- package/docs/invariants/language-config.md +15 -4
- package/docs/invariants/lsp-trust-exec.md +25 -4
- package/docs/invariants/paths-os.md +4 -2
- package/docs/invariants/session-telemetry.md +2 -2
- package/docs/language-coverage.md +1 -0
- package/docs/lsp-capability-matrix.md +167 -65
- package/docs/lsp-idle-eviction.md +4 -1
- package/docs/merge-queue-rollout.md +10 -8
- package/docs/module-report-read-symbol.md +34 -23
- package/docs/pi-lens-fixer.md +34 -17
- package/docs/pi-lens-investigator.md +3 -0
- package/docs/pi-lens-merge-policy.md +34 -17
- package/docs/pi-lens-monitor.md +9 -0
- package/docs/pi-lens-orchestration.md +4 -1
- package/docs/pi-lens-reviewer.md +6 -6
- package/docs/pi-lens-subagent.md +19 -3
- package/docs/public-api-stability.md +57 -7
- package/docs/release-qa-baseline.md +7 -4
- package/docs/schema/pi-lens-config-v1.json +21 -2
- package/docs/servercapabilities.md +3 -1
- package/docs/settings.md +11 -7
- package/docs/word-index.md +20 -7
- package/package.json +11 -4
- package/rules/ast-grep-rules/rule-tests/no-accumulating-spread-js-test.yml +37 -0
- package/rules/ast-grep-rules/rule-tests/ts-redundant-filter-map-test.yml +12 -1
- package/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-js-test.yml +12 -0
- package/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-test.yml +25 -0
- package/rules/ast-grep-rules/rules/no-accumulating-spread-js.yml +49 -1
- package/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +1 -2
- package/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +1 -2
- package/rules/ast-grep-rules/rules/ts-redundant-filter-map.yml +9 -1
- package/rules/ast-grep-rules/rules-disabled/filter-then-map-js.yml +17 -0
- package/rules/ast-grep-rules/rules-disabled/filter-then-map.yml +36 -0
- package/rules/ast-grep-rules/self-scan-baseline.json +1 -1
- package/scripts/download-grammars.js +3 -2
- package/skills/pi-lens-lsp-navigation/SKILL.md +5 -1
- package/dist/chunk-46TNM7XZ.js +0 -88
- package/dist/chunk-72OKUXSD.js +0 -31
- package/dist/chunk-7GLOLOSH.js +0 -57
- package/dist/chunk-AKUUMGD5.js +0 -26
- package/dist/chunk-ASUXV767.js +0 -22
- package/dist/chunk-CTADOKYM.js +0 -25
- package/dist/chunk-GNSIWBAT.js +0 -106
- package/dist/chunk-HWDAVBFU.js +0 -49
- package/dist/chunk-JJ2RRESP.js +0 -58
- package/dist/chunk-KXF5R4UN.js +0 -48
- package/dist/chunk-LSC3VADM.js +0 -23
- package/dist/chunk-OE5ZBP7F.js +0 -443
- package/dist/chunk-SHLDT3OI.js +0 -27
- package/dist/chunk-UF7RTZSO.js +0 -27
- package/dist/chunk-W4WP2ERB.js +0 -30
- package/dist/chunk-YES5CACN.js +0 -73
- package/dist/chunk-Z2XAOKHK.js +0 -136
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
isExcludedDirName
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TMNUTMT5.js";
|
|
5
5
|
import {
|
|
6
6
|
createDeadline,
|
|
7
7
|
yieldIfOverBudget
|
|
8
8
|
} from "./chunk-QYF5S6P6.js";
|
|
9
9
|
import {
|
|
10
10
|
isGeneratedArtifactDirectoryName
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-X5BJ3G2P.js";
|
|
12
12
|
|
|
13
13
|
// dist/clients/source-walker.js
|
|
14
14
|
import * as fs from "node:fs";
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// dist/clients/metrics/function-metrics.js
|
|
4
|
+
var JSTS = {
|
|
5
|
+
functions: /* @__PURE__ */ new Set([
|
|
6
|
+
"function_declaration",
|
|
7
|
+
"function_expression",
|
|
8
|
+
"arrow_function",
|
|
9
|
+
"method_definition",
|
|
10
|
+
"generator_function",
|
|
11
|
+
"generator_function_declaration"
|
|
12
|
+
]),
|
|
13
|
+
// `switch_default` is not a decision.
|
|
14
|
+
decisions: /* @__PURE__ */ new Set([
|
|
15
|
+
"if_statement",
|
|
16
|
+
"for_statement",
|
|
17
|
+
"for_in_statement",
|
|
18
|
+
"while_statement",
|
|
19
|
+
"do_statement",
|
|
20
|
+
"switch_case",
|
|
21
|
+
"catch_clause",
|
|
22
|
+
"ternary_expression"
|
|
23
|
+
]),
|
|
24
|
+
cognitive: /* @__PURE__ */ new Set([
|
|
25
|
+
"if_statement",
|
|
26
|
+
"for_statement",
|
|
27
|
+
"for_in_statement",
|
|
28
|
+
"while_statement",
|
|
29
|
+
"do_statement",
|
|
30
|
+
"switch_statement",
|
|
31
|
+
"catch_clause",
|
|
32
|
+
"ternary_expression"
|
|
33
|
+
]),
|
|
34
|
+
nesting: /* @__PURE__ */ new Set([
|
|
35
|
+
"if_statement",
|
|
36
|
+
"for_statement",
|
|
37
|
+
"for_in_statement",
|
|
38
|
+
"while_statement",
|
|
39
|
+
"do_statement",
|
|
40
|
+
"switch_statement",
|
|
41
|
+
"try_statement"
|
|
42
|
+
]),
|
|
43
|
+
logical: /* @__PURE__ */ new Set(["&&", "||", "??"])
|
|
44
|
+
};
|
|
45
|
+
var PYTHON = {
|
|
46
|
+
functions: /* @__PURE__ */ new Set(["function_definition", "lambda"]),
|
|
47
|
+
decisions: /* @__PURE__ */ new Set([
|
|
48
|
+
"if_statement",
|
|
49
|
+
"elif_clause",
|
|
50
|
+
"for_statement",
|
|
51
|
+
"while_statement",
|
|
52
|
+
"case_clause",
|
|
53
|
+
"conditional_expression",
|
|
54
|
+
"except_clause"
|
|
55
|
+
]),
|
|
56
|
+
cognitive: /* @__PURE__ */ new Set([
|
|
57
|
+
"if_statement",
|
|
58
|
+
"elif_clause",
|
|
59
|
+
"for_statement",
|
|
60
|
+
"while_statement",
|
|
61
|
+
"match_statement",
|
|
62
|
+
"conditional_expression",
|
|
63
|
+
"except_clause"
|
|
64
|
+
]),
|
|
65
|
+
nesting: /* @__PURE__ */ new Set([
|
|
66
|
+
"if_statement",
|
|
67
|
+
"for_statement",
|
|
68
|
+
"while_statement",
|
|
69
|
+
"match_statement",
|
|
70
|
+
"try_statement"
|
|
71
|
+
]),
|
|
72
|
+
logical: /* @__PURE__ */ new Set(["and", "or"])
|
|
73
|
+
};
|
|
74
|
+
var GO = {
|
|
75
|
+
functions: /* @__PURE__ */ new Set([
|
|
76
|
+
"function_declaration",
|
|
77
|
+
"method_declaration",
|
|
78
|
+
"func_literal"
|
|
79
|
+
]),
|
|
80
|
+
// `default_case` is not a decision.
|
|
81
|
+
decisions: /* @__PURE__ */ new Set([
|
|
82
|
+
"if_statement",
|
|
83
|
+
"for_statement",
|
|
84
|
+
"expression_case",
|
|
85
|
+
"type_case",
|
|
86
|
+
"communication_case"
|
|
87
|
+
]),
|
|
88
|
+
cognitive: /* @__PURE__ */ new Set([
|
|
89
|
+
"if_statement",
|
|
90
|
+
"for_statement",
|
|
91
|
+
"expression_switch_statement",
|
|
92
|
+
"type_switch_statement",
|
|
93
|
+
"select_statement"
|
|
94
|
+
]),
|
|
95
|
+
nesting: /* @__PURE__ */ new Set([
|
|
96
|
+
"if_statement",
|
|
97
|
+
"for_statement",
|
|
98
|
+
"expression_switch_statement",
|
|
99
|
+
"type_switch_statement",
|
|
100
|
+
"select_statement"
|
|
101
|
+
]),
|
|
102
|
+
logical: /* @__PURE__ */ new Set(["&&", "||"])
|
|
103
|
+
};
|
|
104
|
+
var RUST = {
|
|
105
|
+
functions: /* @__PURE__ */ new Set(["function_item", "closure_expression"]),
|
|
106
|
+
decisions: /* @__PURE__ */ new Set([
|
|
107
|
+
"if_expression",
|
|
108
|
+
"while_expression",
|
|
109
|
+
"for_expression",
|
|
110
|
+
"loop_expression",
|
|
111
|
+
"match_arm"
|
|
112
|
+
]),
|
|
113
|
+
cognitive: /* @__PURE__ */ new Set([
|
|
114
|
+
"if_expression",
|
|
115
|
+
"while_expression",
|
|
116
|
+
"for_expression",
|
|
117
|
+
"loop_expression",
|
|
118
|
+
"match_expression"
|
|
119
|
+
]),
|
|
120
|
+
nesting: /* @__PURE__ */ new Set([
|
|
121
|
+
"if_expression",
|
|
122
|
+
"while_expression",
|
|
123
|
+
"for_expression",
|
|
124
|
+
"loop_expression",
|
|
125
|
+
"match_expression"
|
|
126
|
+
]),
|
|
127
|
+
logical: /* @__PURE__ */ new Set(["&&", "||"])
|
|
128
|
+
};
|
|
129
|
+
var TABLES = {
|
|
130
|
+
typescript: JSTS,
|
|
131
|
+
tsx: JSTS,
|
|
132
|
+
javascript: JSTS,
|
|
133
|
+
python: PYTHON,
|
|
134
|
+
go: GO,
|
|
135
|
+
rust: RUST
|
|
136
|
+
};
|
|
137
|
+
var NOT_PARAMETERS = /* @__PURE__ */ new Set([
|
|
138
|
+
"comment",
|
|
139
|
+
"line_comment",
|
|
140
|
+
"block_comment",
|
|
141
|
+
"attribute_item",
|
|
142
|
+
"keyword_separator",
|
|
143
|
+
"positional_separator"
|
|
144
|
+
]);
|
|
145
|
+
function isLogicalOperator(type, children, table) {
|
|
146
|
+
if (type !== "binary_expression" && type !== "boolean_operator")
|
|
147
|
+
return false;
|
|
148
|
+
return children.some((c) => table.logical.has(c?.type));
|
|
149
|
+
}
|
|
150
|
+
function step(walk, node, depth, cognitiveDepth, inFunction) {
|
|
151
|
+
const { table, tally: tally2 } = walk;
|
|
152
|
+
const type = node.type;
|
|
153
|
+
const children = node.children ?? [];
|
|
154
|
+
walk.visit?.(node, type, children);
|
|
155
|
+
tally2.nesting = Math.max(tally2.nesting, depth);
|
|
156
|
+
if (table.decisions.has(type))
|
|
157
|
+
tally2.cyclomatic++;
|
|
158
|
+
if (table.cognitive.has(type))
|
|
159
|
+
tally2.cognitive += 1 + cognitiveDepth;
|
|
160
|
+
if (isLogicalOperator(type, children, table)) {
|
|
161
|
+
tally2.cyclomatic++;
|
|
162
|
+
tally2.cognitive++;
|
|
163
|
+
}
|
|
164
|
+
if ((type === "break_statement" || type === "continue_statement") && children.some((c) => c?.type === "statement_identifier" || c?.type === "label_name")) {
|
|
165
|
+
tally2.cognitive++;
|
|
166
|
+
}
|
|
167
|
+
const nests = table.nesting.has(type);
|
|
168
|
+
const isFunction = table.functions.has(type);
|
|
169
|
+
const nextDepth = nests ? depth + 1 : depth;
|
|
170
|
+
const deepens = nests || isFunction && inFunction;
|
|
171
|
+
const nextCognitiveDepth = deepens ? cognitiveDepth + 1 : cognitiveDepth;
|
|
172
|
+
for (const child of children) {
|
|
173
|
+
if (child)
|
|
174
|
+
step(walk, child, nextDepth, nextCognitiveDepth, inFunction || isFunction);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function tally(scope, table, insideFunction, visit) {
|
|
178
|
+
const walk = {
|
|
179
|
+
table,
|
|
180
|
+
visit,
|
|
181
|
+
tally: { cyclomatic: 1, cognitive: 0, nesting: 0 }
|
|
182
|
+
};
|
|
183
|
+
if (scope)
|
|
184
|
+
step(walk, scope, 0, 0, insideFunction);
|
|
185
|
+
return walk.tally;
|
|
186
|
+
}
|
|
187
|
+
function bodyOf(fn) {
|
|
188
|
+
const id = fn.childForFieldName("body")?.id;
|
|
189
|
+
if (id === void 0)
|
|
190
|
+
return null;
|
|
191
|
+
return (fn.children ?? []).find((c) => c?.id === id) ?? null;
|
|
192
|
+
}
|
|
193
|
+
function countParameters(fn) {
|
|
194
|
+
const list = fn.childForFieldName("parameters");
|
|
195
|
+
if (!list)
|
|
196
|
+
return fn.childForFieldName("parameter") ? 1 : 0;
|
|
197
|
+
let count = 0;
|
|
198
|
+
for (const param of list.namedChildren ?? []) {
|
|
199
|
+
if (!param || NOT_PARAMETERS.has(param.type))
|
|
200
|
+
continue;
|
|
201
|
+
count += Math.max(1, param.childrenForFieldName("name").length);
|
|
202
|
+
}
|
|
203
|
+
return count;
|
|
204
|
+
}
|
|
205
|
+
function measureFunction(fn, languageId, visit) {
|
|
206
|
+
const { cyclomatic, cognitive, nesting } = tally(bodyOf(fn), TABLES[languageId], true, visit);
|
|
207
|
+
return {
|
|
208
|
+
cyclomatic,
|
|
209
|
+
cognitive,
|
|
210
|
+
nesting,
|
|
211
|
+
length: fn.endPosition.row - fn.startPosition.row + 1,
|
|
212
|
+
parameters: countParameters(fn)
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function measureFile(root, languageId) {
|
|
216
|
+
const table = TABLES[languageId];
|
|
217
|
+
const functions = [];
|
|
218
|
+
const { cognitive, nesting } = tally(root, table, false, (node, type) => {
|
|
219
|
+
if (!table.functions.has(type) || !node.isNamed)
|
|
220
|
+
return;
|
|
221
|
+
const line = node.startPosition.row + 1;
|
|
222
|
+
functions.push({
|
|
223
|
+
name: node.childForFieldName("name")?.text ?? `<anonymous@L${line}>`,
|
|
224
|
+
line,
|
|
225
|
+
...measureFunction(node, languageId)
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
return { cognitive, nesting, functions };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export {
|
|
232
|
+
measureFunction,
|
|
233
|
+
measureFile
|
|
234
|
+
};
|