measure-code 1.0.0
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/LICENSE +201 -0
- package/README.md +41 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/languages.cjs +2 -0
- package/dist/languages.cjs.map +1 -0
- package/dist/languages.d.ts +4 -0
- package/dist/languages.js +2 -0
- package/dist/languages.js.map +1 -0
- package/dist/metrics.cjs +2 -0
- package/dist/metrics.cjs.map +1 -0
- package/dist/metrics.d.ts +9 -0
- package/dist/metrics.js +2 -0
- package/dist/metrics.js.map +1 -0
- package/dist/types.d.ts +58 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# tree-measurer
|
|
2
|
+
|
|
3
|
+
[](https://github.com/WillBooster/tree-measurer/actions/workflows/test.yml)
|
|
4
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
5
|
+
|
|
6
|
+
A library for measuring code metrics with tree-sitter.
|
|
7
|
+
|
|
8
|
+
## Metrics
|
|
9
|
+
|
|
10
|
+
- Physical LOC, code lines, comment-only lines, and blank lines
|
|
11
|
+
- Function and class counts
|
|
12
|
+
- Cyclomatic complexity
|
|
13
|
+
- Cognitive complexity
|
|
14
|
+
- Maximum per-function complexity
|
|
15
|
+
- Nesting depth
|
|
16
|
+
- Halstead metrics
|
|
17
|
+
- Maintainability index
|
|
18
|
+
|
|
19
|
+
## Supported languages
|
|
20
|
+
|
|
21
|
+
Built-in parsers are registered for JavaScript, JSX, TypeScript, TSX, Python, and Go. Additional tree-sitter grammars can be registered with `TreeMeasurer.registerLanguage`.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { measureCode } from 'measure-code';
|
|
27
|
+
|
|
28
|
+
const metrics = measureCode(
|
|
29
|
+
`
|
|
30
|
+
function score(value) {
|
|
31
|
+
if (value < 0 || value == null) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
return value > 10 ? 10 : value;
|
|
35
|
+
}
|
|
36
|
+
`,
|
|
37
|
+
{ language: 'javascript' }
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
console.log(metrics.cyclomaticComplexity);
|
|
41
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("./languages.cjs"),r=require("./metrics.cjs");exports.defaultLanguages=e.defaultLanguages,exports.supportedLanguages=e.supportedLanguages,exports.TreeMeasurer=r.TreeMeasurer,exports.defaultMeasurer=r.defaultMeasurer,exports.measureCode=r.measureCode;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { defaultLanguages, supportedLanguages } from './languages.js';
|
|
2
|
+
export { TreeMeasurer, defaultMeasurer, measureCode } from './metrics.js';
|
|
3
|
+
export type { CodeMetrics, FunctionMetrics, HalsteadMetrics, LanguageDefinition, LanguageName, LineMetrics, MeasureOptions, SupportedLanguage, } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("tree-sitter-go"),t=require("tree-sitter-javascript"),a=require("tree-sitter-python"),n=require("tree-sitter-typescript");const s=["function","function_declaration","function_definition","function_item","function_declarator","method_declaration","method_definition","method_spec","arrow_function","generator_function","generator_function_declaration","lambda","lambda_expression"],r=["class","class_declaration","class_definition","interface_declaration","trait_item","impl_item","struct_item","enum_item"],i=["if_statement","elif_clause","else_if_clause","for_statement","for_in_statement","while_statement","do_statement","catch_clause","except_clause","case_clause","switch_case","match_arm","conditional_expression","ternary_expression"];function o(e){return function(e,t){if("object"!=typeof e||null===e||!(t in e))return!1;return Boolean(e[t])}(e,"default")?e.default:e}function c(e){return n[e]}const u=[{name:"javascript",aliases:["js","mjs","cjs"],parserLanguage:o(t)},{name:"jsx",parserLanguage:o(t)},{name:"typescript",aliases:["ts"],parserLanguage:c("typescript")},{name:"tsx",parserLanguage:c("tsx")},{name:"python",aliases:["py"],parserLanguage:o(a)},{name:"go",parserLanguage:o(e)}].map(e=>({functionNodeTypes:s,classNodeTypes:r,decisionNodeTypes:i,nestingNodeTypes:i,...e}));const p=u.map(e=>e.name);exports.createLanguageRegistry=function(e=u){const t=new Map;for(const a of e){t.set(a.name,a);for(const e of a.aliases??[])t.set(e,a)}return t},exports.defaultLanguages=u,exports.supportedLanguages=p;
|
|
2
|
+
//# sourceMappingURL=languages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languages.cjs","sources":["../src/languages.ts"],"sourcesContent":["import Go from 'tree-sitter-go';\nimport JavaScript from 'tree-sitter-javascript';\nimport Python from 'tree-sitter-python';\nimport TypeScript from 'tree-sitter-typescript';\nimport type { LanguageDefinition, LanguageName, ParserLanguage } from './types.js';\n\ntype GrammarModule = unknown;\n\nconst commonFunctionNodes = [\n 'function',\n 'function_declaration',\n 'function_definition',\n 'function_item',\n 'function_declarator',\n 'method_declaration',\n 'method_definition',\n 'method_spec',\n 'arrow_function',\n 'generator_function',\n 'generator_function_declaration',\n 'lambda',\n 'lambda_expression',\n] as const;\n\nconst commonClassNodes = [\n 'class',\n 'class_declaration',\n 'class_definition',\n 'interface_declaration',\n 'trait_item',\n 'impl_item',\n 'struct_item',\n 'enum_item',\n] as const;\n\nconst commonDecisionNodes = [\n 'if_statement',\n 'elif_clause',\n 'else_if_clause',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'except_clause',\n 'case_clause',\n 'switch_case',\n 'match_arm',\n 'conditional_expression',\n 'ternary_expression',\n] as const;\n\nfunction normalizeGrammar(module: GrammarModule): ParserLanguage {\n if (isGrammarWrapper(module, 'default')) {\n return module.default;\n }\n\n return module;\n}\n\nfunction getTypeScriptGrammar(name: 'typescript' | 'tsx'): ParserLanguage {\n const grammars = TypeScript as unknown as Record<string, GrammarModule>;\n return grammars[name];\n}\n\nfunction isGrammarWrapper(value: GrammarModule, key: 'default'): value is Record<typeof key, ParserLanguage> {\n if (typeof value !== 'object' || value === null || !(key in value)) {\n return false;\n }\n\n return Boolean((value as Record<string, ParserLanguage>)[key]);\n}\n\nexport const defaultLanguages: readonly LanguageDefinition[] = [\n {\n name: 'javascript',\n aliases: ['js', 'mjs', 'cjs'],\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'jsx',\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'typescript',\n aliases: ['ts'],\n parserLanguage: getTypeScriptGrammar('typescript'),\n },\n {\n name: 'tsx',\n parserLanguage: getTypeScriptGrammar('tsx'),\n },\n {\n name: 'python',\n aliases: ['py'],\n parserLanguage: normalizeGrammar(Python as unknown as GrammarModule),\n },\n {\n name: 'go',\n parserLanguage: normalizeGrammar(Go as unknown as GrammarModule),\n },\n].map((language) => ({\n functionNodeTypes: commonFunctionNodes,\n classNodeTypes: commonClassNodes,\n decisionNodeTypes: commonDecisionNodes,\n nestingNodeTypes: commonDecisionNodes,\n ...language,\n}));\n\nexport function createLanguageRegistry(\n languages: readonly LanguageDefinition[] = defaultLanguages\n): Map<LanguageName, LanguageDefinition> {\n const registry = new Map<LanguageName, LanguageDefinition>();\n\n for (const language of languages) {\n registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n registry.set(alias, language);\n }\n }\n\n return registry;\n}\n\nexport const supportedLanguages = defaultLanguages.map((language) => language.name);\n"],"names":["commonFunctionNodes","commonClassNodes","commonDecisionNodes","normalizeGrammar","module","value","key","Boolean","isGrammarWrapper","default","getTypeScriptGrammar","name","TypeScript","defaultLanguages","aliases","parserLanguage","JavaScript","Python","Go","map","language","functionNodeTypes","classNodeTypes","decisionNodeTypes","nestingNodeTypes","supportedLanguages","languages","registry","Map","set","alias"],"mappings":"qJAQA,MAAMA,EAAsB,CAC1B,WACA,uBACA,sBACA,gBACA,sBACA,qBACA,oBACA,cACA,iBACA,qBACA,iCACA,SACA,qBAGIC,EAAmB,CACvB,QACA,oBACA,mBACA,wBACA,aACA,YACA,cACA,aAGIC,EAAsB,CAC1B,eACA,cACA,iBACA,gBACA,mBACA,kBACA,eACA,eACA,gBACA,cACA,cACA,YACA,yBACA,sBAGF,SAASC,EAAiBC,GACxB,OAYF,SAA0BC,EAAsBC,GAC9C,GAAqB,iBAAVD,GAAgC,OAAVA,KAAoBC,KAAOD,GAC1D,OAAO,EAGT,OAAOE,QAASF,EAAyCC,GAC3D,CAlBME,CAAiBJ,EAAQ,WACpBA,EAAOK,QAGTL,CACT,CAEA,SAASM,EAAqBC,GAE5B,OADiBC,EACDD,EAClB,CAUO,MAAME,EAAkD,CAC7D,CACEF,KAAM,aACNG,QAAS,CAAC,KAAM,MAAO,OACvBC,eAAgBZ,EAAiBa,IAEnC,CACEL,KAAM,MACNI,eAAgBZ,EAAiBa,IAEnC,CACEL,KAAM,aACNG,QAAS,CAAC,MACVC,eAAgBL,EAAqB,eAEvC,CACEC,KAAM,MACNI,eAAgBL,EAAqB,QAEvC,CACEC,KAAM,SACNG,QAAS,CAAC,MACVC,eAAgBZ,EAAiBc,IAEnC,CACEN,KAAM,KACNI,eAAgBZ,EAAiBe,KAEnCC,IAAKC,IAAQ,CACbC,kBAAmBrB,EACnBsB,eAAgBrB,EAChBsB,kBAAmBrB,EACnBsB,iBAAkBtB,KACfkB,KAkBE,MAAMK,EAAqBZ,EAAiBM,IAAKC,GAAaA,EAAST,qCAfvE,SACLe,EAA2Cb,GAE3C,MAAMc,EAAW,IAAIC,IAErB,IAAK,MAAMR,KAAYM,EAAW,CAChCC,EAASE,IAAIT,EAAST,KAAMS,GAC5B,IAAK,MAAMU,KAASV,EAASN,SAAW,GACtCa,EAASE,IAAIC,EAAOV,EAExB,CAEA,OAAOO,CACT"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LanguageDefinition, LanguageName } from './types.js';
|
|
2
|
+
export declare const defaultLanguages: readonly LanguageDefinition[];
|
|
3
|
+
export declare function createLanguageRegistry(languages?: readonly LanguageDefinition[]): Map<LanguageName, LanguageDefinition>;
|
|
4
|
+
export declare const supportedLanguages: LanguageName[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"tree-sitter-go";import t from"tree-sitter-javascript";import n from"tree-sitter-python";import a from"tree-sitter-typescript";const s=["function","function_declaration","function_definition","function_item","function_declarator","method_declaration","method_definition","method_spec","arrow_function","generator_function","generator_function_declaration","lambda","lambda_expression"],r=["class","class_declaration","class_definition","interface_declaration","trait_item","impl_item","struct_item","enum_item"],i=["if_statement","elif_clause","else_if_clause","for_statement","for_in_statement","while_statement","do_statement","catch_clause","except_clause","case_clause","switch_case","match_arm","conditional_expression","ternary_expression"];function o(e){return function(e,t){if("object"!=typeof e||null===e||!(t in e))return!1;return Boolean(e[t])}(e,"default")?e.default:e}function c(e){return a[e]}const m=[{name:"javascript",aliases:["js","mjs","cjs"],parserLanguage:o(t)},{name:"jsx",parserLanguage:o(t)},{name:"typescript",aliases:["ts"],parserLanguage:c("typescript")},{name:"tsx",parserLanguage:c("tsx")},{name:"python",aliases:["py"],parserLanguage:o(n)},{name:"go",parserLanguage:o(e)}].map(e=>({functionNodeTypes:s,classNodeTypes:r,decisionNodeTypes:i,nestingNodeTypes:i,...e}));function p(e=m){const t=new Map;for(const n of e){t.set(n.name,n);for(const e of n.aliases??[])t.set(e,n)}return t}const _=m.map(e=>e.name);export{p as createLanguageRegistry,m as defaultLanguages,_ as supportedLanguages};
|
|
2
|
+
//# sourceMappingURL=languages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languages.js","sources":["../src/languages.ts"],"sourcesContent":["import Go from 'tree-sitter-go';\nimport JavaScript from 'tree-sitter-javascript';\nimport Python from 'tree-sitter-python';\nimport TypeScript from 'tree-sitter-typescript';\nimport type { LanguageDefinition, LanguageName, ParserLanguage } from './types.js';\n\ntype GrammarModule = unknown;\n\nconst commonFunctionNodes = [\n 'function',\n 'function_declaration',\n 'function_definition',\n 'function_item',\n 'function_declarator',\n 'method_declaration',\n 'method_definition',\n 'method_spec',\n 'arrow_function',\n 'generator_function',\n 'generator_function_declaration',\n 'lambda',\n 'lambda_expression',\n] as const;\n\nconst commonClassNodes = [\n 'class',\n 'class_declaration',\n 'class_definition',\n 'interface_declaration',\n 'trait_item',\n 'impl_item',\n 'struct_item',\n 'enum_item',\n] as const;\n\nconst commonDecisionNodes = [\n 'if_statement',\n 'elif_clause',\n 'else_if_clause',\n 'for_statement',\n 'for_in_statement',\n 'while_statement',\n 'do_statement',\n 'catch_clause',\n 'except_clause',\n 'case_clause',\n 'switch_case',\n 'match_arm',\n 'conditional_expression',\n 'ternary_expression',\n] as const;\n\nfunction normalizeGrammar(module: GrammarModule): ParserLanguage {\n if (isGrammarWrapper(module, 'default')) {\n return module.default;\n }\n\n return module;\n}\n\nfunction getTypeScriptGrammar(name: 'typescript' | 'tsx'): ParserLanguage {\n const grammars = TypeScript as unknown as Record<string, GrammarModule>;\n return grammars[name];\n}\n\nfunction isGrammarWrapper(value: GrammarModule, key: 'default'): value is Record<typeof key, ParserLanguage> {\n if (typeof value !== 'object' || value === null || !(key in value)) {\n return false;\n }\n\n return Boolean((value as Record<string, ParserLanguage>)[key]);\n}\n\nexport const defaultLanguages: readonly LanguageDefinition[] = [\n {\n name: 'javascript',\n aliases: ['js', 'mjs', 'cjs'],\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'jsx',\n parserLanguage: normalizeGrammar(JavaScript as unknown as GrammarModule),\n },\n {\n name: 'typescript',\n aliases: ['ts'],\n parserLanguage: getTypeScriptGrammar('typescript'),\n },\n {\n name: 'tsx',\n parserLanguage: getTypeScriptGrammar('tsx'),\n },\n {\n name: 'python',\n aliases: ['py'],\n parserLanguage: normalizeGrammar(Python as unknown as GrammarModule),\n },\n {\n name: 'go',\n parserLanguage: normalizeGrammar(Go as unknown as GrammarModule),\n },\n].map((language) => ({\n functionNodeTypes: commonFunctionNodes,\n classNodeTypes: commonClassNodes,\n decisionNodeTypes: commonDecisionNodes,\n nestingNodeTypes: commonDecisionNodes,\n ...language,\n}));\n\nexport function createLanguageRegistry(\n languages: readonly LanguageDefinition[] = defaultLanguages\n): Map<LanguageName, LanguageDefinition> {\n const registry = new Map<LanguageName, LanguageDefinition>();\n\n for (const language of languages) {\n registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n registry.set(alias, language);\n }\n }\n\n return registry;\n}\n\nexport const supportedLanguages = defaultLanguages.map((language) => language.name);\n"],"names":["commonFunctionNodes","commonClassNodes","commonDecisionNodes","normalizeGrammar","module","value","key","Boolean","isGrammarWrapper","default","getTypeScriptGrammar","name","TypeScript","defaultLanguages","aliases","parserLanguage","JavaScript","Python","Go","map","language","functionNodeTypes","classNodeTypes","decisionNodeTypes","nestingNodeTypes","createLanguageRegistry","languages","registry","Map","set","alias","supportedLanguages"],"mappings":"4IAQA,MAAMA,EAAsB,CAC1B,WACA,uBACA,sBACA,gBACA,sBACA,qB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require("./languages.cjs");const n=new Set(["&&","||","and","or"]),o=new Set(["+","-","*","/","%","**","=","+=","-=","*=","/=","%=","==","!=","===","!==","<","<=",">",">=","!","~","&","|","^","<<",">>","=>","return","throw","yield","await","break","continue"]),i=new Set(["identifier","property_identifier","field_identifier","type_identifier","number","integer","float","string","string_literal","template_string","character_literal","true","false","null","undefined","nil"]);class r{registry=e.createLanguageRegistry();registerLanguage(t){this.registry.set(t.name,t);for(const e of t.aliases??[])this.registry.set(e,t)}getSupportedLanguages(){return[...new Set([...this.registry.values()].map(t=>t.name))]}measure(e,n){const r=this.registry.get(n.language);if(!r)throw new Error(`Unsupported language: ${n.language}`);const s=new t;s.setLanguage(r.parserLanguage);const d=s.parse(e).rootNode,y=c(d,new Set(r.functionNodeTypes)).map(t=>function(t,e){const n=a(t,e,0);return{name:u(t),startLine:t.startPosition.row+1,endLine:t.endPosition.row+1,cyclomaticComplexity:n.cyclomaticComplexity,cognitiveComplexity:n.cognitiveComplexity}}(t,r)),h=a(d,r,0),x=function(t,e){const n=0===t.length?[]:t.split(/\r\n|\n|\r/),o=function(t){const e=[];function n(t){if("comment"===t.type||"line_comment"===t.type||"block_comment"===t.type)for(let n=t.startPosition.row;n<=t.endPosition.row;n+=1)e.push({line:n,startColumn:n===t.startPosition.row?t.startPosition.column:0,endColumn:n===t.endPosition.row?t.endPosition.column:Number.POSITIVE_INFINITY});for(const e of t.namedChildren)n(e)}return n(t),e}(e);let i=0,r=0;for(const[t,e]of n.entries())""!==e.trim()?l(e,t,o)&&(r+=1):i+=1;return{total:n.length,code:n.length-i-r,comment:r,blank:i}}(e,d),C=function(t,e){const n=new Map,r=new Map;function s(t){if("comment"!==t.type){if(0===t.childCount){const s=e.slice(t.startIndex,t.endIndex);return void(o.has(s)||o.has(t.type)?f(n,s||t.type):i.has(t.type)&&f(r,s))}o.has(t.type)&&f(n,t.type);for(const e of t.children)s(e)}}s(t);const a=n.size,c=r.size,l=p(n.values()),u=p(r.values()),m=a+c,g=l+u,d=0===m?0:g*Math.log2(m),y=0===c?0:a/2*(u/c),h=y*d;return{distinctOperators:a,distinctOperands:c,totalOperators:l,totalOperands:u,vocabulary:m,length:g,volume:d,difficulty:y,effort:h,time:h/18,bugs:d/3e3}}(d,e);return{language:r.name,bytes:Buffer.byteLength(e),lines:x,functions:y,classCount:c(d,new Set(r.classNodeTypes)).length,functionCount:y.length,cyclomaticComplexity:h.cyclomaticComplexity,maxCyclomaticComplexity:g(y,"cyclomaticComplexity"),cognitiveComplexity:h.cognitiveComplexity,maxCognitiveComplexity:g(y,"cognitiveComplexity"),nestingDepth:h.nestingDepth,halstead:C,maintainabilityIndex:m(C.volume,h.cyclomaticComplexity,x.code),syntaxTree:n.includeSyntaxTree?d.toString():void 0}}}const s=new r;function a(t,e,o){let i=1,r=0,s=o;const a=new Set(e.decisionNodeTypes),c=new Set(e.nestingNodeTypes);function l(t,e){const o=a.has(t.type),u=c.has(t.type);o&&(i+=1,r+=1+e),function(t){if(t.isNamed)return!1;return n.has(t.text)}(t)&&(i+=1,r+=1);const m=u?e+1:e;s=Math.max(s,m);for(const e of t.children)l(e,m)}for(const e of t.children)l(e,o);return{cyclomaticComplexity:i,cognitiveComplexity:r,nestingDepth:s}}function c(t,e){const n=[];return function t(o){e.has(o.type)&&n.push(o);for(const e of o.namedChildren)t(e)}(t),n}function l(t,e,n){const o=n.filter(t=>t.line===e);if(0===o.length)return!1;const i=t.search(/\S/),r=t.trimEnd().length;return o.some(t=>t.startColumn<=i&&t.endColumn>=r)}function u(t){const e=t.childForFieldName("name");if(e)return e.text;const n=t.parent;if(!n)return;const o=n.childForFieldName("name");return o?.text}function m(t,e,n){if(0===n)return 100;const o=171-5.2*Math.log(Math.max(t,1))-.23*e-16.2*Math.log(n);return Math.max(0,Math.min(100,100*o/171))}function f(t,e){t.set(e,(t.get(e)??0)+1)}function g(t,e){return 0===t.length?0:Math.max(...t.map(t=>t[e]))}function p(t){let e=0;for(const n of t)e+=n;return e}exports.TreeMeasurer=r,exports.defaultMeasurer=s,exports.measureCode=function(t,e){return s.measure(t,e)};
|
|
2
|
+
//# sourceMappingURL=metrics.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.cjs","sources":["../src/metrics.ts"],"sourcesContent":["import Parser from 'tree-sitter';\nimport { createLanguageRegistry } from './languages.js';\nimport type {\n CodeMetrics,\n FunctionMetrics,\n HalsteadMetrics,\n LanguageDefinition,\n LanguageName,\n MeasureOptions,\n} from './types.js';\n\nconst booleanOperators = new Set(['&&', '||', 'and', 'or']);\nconst operatorTexts = new Set([\n '+',\n '-',\n '*',\n '/',\n '%',\n '**',\n '=',\n '+=',\n '-=',\n '*=',\n '/=',\n '%=',\n '==',\n '!=',\n '===',\n '!==',\n '<',\n '<=',\n '>',\n '>=',\n '!',\n '~',\n '&',\n '|',\n '^',\n '<<',\n '>>',\n '=>',\n 'return',\n 'throw',\n 'yield',\n 'await',\n 'break',\n 'continue',\n]);\n\nconst operandNodeTypes = new Set([\n 'identifier',\n 'property_identifier',\n 'field_identifier',\n 'type_identifier',\n 'number',\n 'integer',\n 'float',\n 'string',\n 'string_literal',\n 'template_string',\n 'character_literal',\n 'true',\n 'false',\n 'null',\n 'undefined',\n 'nil',\n]);\n\ninterface ComplexityResult {\n cyclomaticComplexity: number;\n cognitiveComplexity: number;\n nestingDepth: number;\n}\n\ninterface CommentSpan {\n line: number;\n startColumn: number;\n endColumn: number;\n}\n\nexport class TreeMeasurer {\n private readonly registry = createLanguageRegistry();\n\n registerLanguage(language: LanguageDefinition): void {\n this.registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n this.registry.set(alias, language);\n }\n }\n\n getSupportedLanguages(): LanguageName[] {\n return [...new Set([...this.registry.values()].map((language) => language.name))];\n }\n\n measure(code: string, options: MeasureOptions): CodeMetrics {\n const language = this.registry.get(options.language);\n if (!language) {\n throw new Error(`Unsupported language: ${options.language}`);\n }\n\n const parser = new Parser();\n parser.setLanguage(language.parserLanguage);\n const tree = parser.parse(code);\n const root = tree.rootNode;\n const functions = collectNodes(root, new Set(language.functionNodeTypes));\n const functionMetrics = functions.map((node) => measureFunction(node, language));\n const globalComplexity = measureComplexity(root, language, 0);\n const lines = measureLines(code, root);\n const halstead = measureHalstead(root, code);\n\n return {\n language: language.name,\n bytes: Buffer.byteLength(code),\n lines,\n functions: functionMetrics,\n classCount: collectNodes(root, new Set(language.classNodeTypes)).length,\n functionCount: functionMetrics.length,\n cyclomaticComplexity: globalComplexity.cyclomaticComplexity,\n maxCyclomaticComplexity: maxMetric(functionMetrics, 'cyclomaticComplexity'),\n cognitiveComplexity: globalComplexity.cognitiveComplexity,\n maxCognitiveComplexity: maxMetric(functionMetrics, 'cognitiveComplexity'),\n nestingDepth: globalComplexity.nestingDepth,\n halstead,\n maintainabilityIndex: calculateMaintainabilityIndex(\n halstead.volume,\n globalComplexity.cyclomaticComplexity,\n lines.code\n ),\n syntaxTree: options.includeSyntaxTree ? root.toString() : undefined,\n };\n }\n}\n\nexport const defaultMeasurer = new TreeMeasurer();\n\nexport function measureCode(code: string, options: MeasureOptions): CodeMetrics {\n return defaultMeasurer.measure(code, options);\n}\n\nfunction measureFunction(node: Parser.SyntaxNode, language: LanguageDefinition): FunctionMetrics {\n const complexity = measureComplexity(node, language, 0);\n\n return {\n name: findFunctionName(node),\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n cyclomaticComplexity: complexity.cyclomaticComplexity,\n cognitiveComplexity: complexity.cognitiveComplexity,\n };\n}\n\nfunction measureComplexity(node: Parser.SyntaxNode, language: LanguageDefinition, nesting: number): ComplexityResult {\n let cyclomaticComplexity = 1;\n let cognitiveComplexity = 0;\n let nestingDepth = nesting;\n const decisionNodes = new Set(language.decisionNodeTypes);\n const nestingNodes = new Set(language.nestingNodeTypes);\n\n function visit(current: Parser.SyntaxNode, currentNesting: number): void {\n const isDecision = decisionNodes.has(current.type);\n const isNesting = nestingNodes.has(current.type);\n\n if (isDecision) {\n cyclomaticComplexity += 1;\n cognitiveComplexity += 1 + currentNesting;\n }\n\n if (isBooleanOperator(current)) {\n cyclomaticComplexity += 1;\n cognitiveComplexity += 1;\n }\n\n const childNesting = isNesting ? currentNesting + 1 : currentNesting;\n nestingDepth = Math.max(nestingDepth, childNesting);\n\n for (const child of current.children) {\n visit(child, childNesting);\n }\n }\n\n for (const child of node.children) {\n visit(child, nesting);\n }\n\n return { cyclomaticComplexity, cognitiveComplexity, nestingDepth };\n}\n\nfunction isBooleanOperator(node: Parser.SyntaxNode): boolean {\n if (node.isNamed) {\n return false;\n }\n\n return booleanOperators.has(node.text);\n}\n\nfunction collectNodes(root: Parser.SyntaxNode, nodeTypes: Set<string>): Parser.SyntaxNode[] {\n const nodes: Parser.SyntaxNode[] = [];\n\n function visit(node: Parser.SyntaxNode): void {\n if (nodeTypes.has(node.type)) {\n nodes.push(node);\n }\n\n for (const child of node.namedChildren) {\n visit(child);\n }\n }\n\n visit(root);\n return nodes;\n}\n\nfunction measureLines(code: string, root: Parser.SyntaxNode): CodeMetrics['lines'] {\n const sourceLines = code.length === 0 ? [] : code.split(/\\r\\n|\\n|\\r/);\n const commentSpans = collectCommentSpans(root);\n let blank = 0;\n let comment = 0;\n\n for (const [index, line] of sourceLines.entries()) {\n if (line.trim() === '') {\n blank += 1;\n continue;\n }\n\n if (isCommentOnlyLine(line, index, commentSpans)) {\n comment += 1;\n }\n }\n\n return {\n total: sourceLines.length,\n code: sourceLines.length - blank - comment,\n comment,\n blank,\n };\n}\n\nfunction collectCommentSpans(root: Parser.SyntaxNode): CommentSpan[] {\n const spans: CommentSpan[] = [];\n\n function visit(node: Parser.SyntaxNode): void {\n if (node.type === 'comment' || node.type === 'line_comment' || node.type === 'block_comment') {\n for (let row = node.startPosition.row; row <= node.endPosition.row; row += 1) {\n spans.push({\n line: row,\n startColumn: row === node.startPosition.row ? node.startPosition.column : 0,\n endColumn: row === node.endPosition.row ? node.endPosition.column : Number.POSITIVE_INFINITY,\n });\n }\n }\n\n for (const child of node.namedChildren) {\n visit(child);\n }\n }\n\n visit(root);\n return spans;\n}\n\nfunction isCommentOnlyLine(line: string, lineIndex: number, spans: CommentSpan[]): boolean {\n const relevantSpans = spans.filter((span) => span.line === lineIndex);\n if (relevantSpans.length === 0) {\n return false;\n }\n\n const firstContentColumn = line.search(/\\S/);\n const lastContentColumn = line.trimEnd().length;\n\n return relevantSpans.some((span) => span.startColumn <= firstContentColumn && span.endColumn >= lastContentColumn);\n}\n\nfunction measureHalstead(root: Parser.SyntaxNode, code: string): HalsteadMetrics {\n const operators = new Map<string, number>();\n const operands = new Map<string, number>();\n\n function visit(node: Parser.SyntaxNode): void {\n if (node.type === 'comment') {\n return;\n }\n\n if (node.childCount === 0) {\n const text = code.slice(node.startIndex, node.endIndex);\n if (operatorTexts.has(text) || operatorTexts.has(node.type)) {\n incrementCount(operators, text || node.type);\n } else if (operandNodeTypes.has(node.type)) {\n incrementCount(operands, text);\n }\n return;\n }\n\n if (operatorTexts.has(node.type)) {\n incrementCount(operators, node.type);\n }\n\n for (const child of node.children) {\n visit(child);\n }\n }\n\n visit(root);\n\n const distinctOperators = operators.size;\n const distinctOperands = operands.size;\n const totalOperators = sum(operators.values());\n const totalOperands = sum(operands.values());\n const vocabulary = distinctOperators + distinctOperands;\n const length = totalOperators + totalOperands;\n const volume = vocabulary === 0 ? 0 : length * Math.log2(vocabulary);\n const difficulty = distinctOperands === 0 ? 0 : (distinctOperators / 2) * (totalOperands / distinctOperands);\n const effort = difficulty * volume;\n\n return {\n distinctOperators,\n distinctOperands,\n totalOperators,\n totalOperands,\n vocabulary,\n length,\n volume,\n difficulty,\n effort,\n time: effort / 18,\n bugs: volume / 3000,\n };\n}\n\nfunction findFunctionName(node: Parser.SyntaxNode): string | undefined {\n const nameNode = node.childForFieldName('name');\n if (nameNode) {\n return nameNode.text;\n }\n\n const parent = node.parent;\n if (!parent) {\n return undefined;\n }\n\n const parentName = parent.childForFieldName('name');\n return parentName?.text;\n}\n\nfunction calculateMaintainabilityIndex(volume: number, complexity: number, loc: number): number {\n if (loc === 0) {\n return 100;\n }\n\n const raw = 171 - 5.2 * Math.log(Math.max(volume, 1)) - 0.23 * complexity - 16.2 * Math.log(loc);\n return Math.max(0, Math.min(100, (raw * 100) / 171));\n}\n\nfunction incrementCount(map: Map<string, number>, value: string): void {\n map.set(value, (map.get(value) ?? 0) + 1);\n}\n\nfunction maxMetric(functions: FunctionMetrics[], key: 'cyclomaticComplexity' | 'cognitiveComplexity'): number {\n return functions.length === 0 ? 0 : Math.max(...functions.map((fn) => fn[key]));\n}\n\nfunction sum(values: Iterable<number>): number {\n let total = 0;\n for (const value of values) {\n total += value;\n }\n return total;\n}\n"],"names":["booleanOperators","Set","operatorTexts","operandNodeTypes","TreeMeasurer","registry","createLanguageRegistry","registerLanguage","language","this","set","name","alias","aliases","getSupportedLanguages","values","map","measure","code","options","get","Error","parser","Parser","setLanguage","parserLanguage","root","parse","rootNode","functionMetrics","collectNodes","functionNodeTypes","node","complexity","measureComplexity","findFunctionName","startLine","startPosition","row","endLine","endPosition","cyclomaticComplexity","cognitiveComplexity","measureFunction","globalComplexity","lines","sourceLines","length","split","commentSpans","spans","visit","type","push","line","startColumn","column","endColumn","Number","POSITIVE_INFINITY","child","namedChildren","collectCommentSpans","blank","comment","index","entries","trim","isCommentOnlyLine","total","measureLines","halstead","operators","Map","operands","childCount","text","slice","startIndex","endIndex","has","incrementCount","children","distinctOperators","size","distinctOperands","totalOperators","sum","totalOperands","vocabulary","volume","Math","log2","difficulty","effort","time","bugs","measureHalstead","bytes","Buffer","byteLength","functions","classCount","classNodeTypes","functionCount","maxCyclomaticComplexity","maxMetric","maxCognitiveComplexity","nestingDepth","maintainabilityIndex","calculateMaintainabilityIndex","syntaxTree","includeSyntaxTree","toString","undefined","defaultMeasurer","nesting","decisionNodes","decisionNodeTypes","nestingNodes","nestingNodeTypes","current","currentNesting","isDecision","isNesting","isNamed","isBooleanOperator","childNesting","max","nodeTypes","nodes","lineIndex","relevantSpans","filter","span","firstContentColumn","search","lastContentColumn","trimEnd","some","nameNode","childForFieldName","parent","parentName","loc","raw","log","min","value","key","fn"],"mappings":"uEAWA,MAAMA,EAAmB,IAAIC,IAAI,CAAC,KAAM,KAAM,MAAO,OAC/CC,EAAgB,IAAID,IAAI,CAC5B,IACA,IACA,IACA,IACA,IACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,MACA,IACA,KACA,IACA,KACA,IACA,IACA,IACA,IACA,IACA,KACA,KACA,KACA,SACA,QACA,QACA,QACA,QACA,aAGIE,EAAmB,IAAIF,IAAI,CAC/B,aACA,sBACA,mBACA,kBACA,SACA,UACA,QACA,SACA,iBACA,kBACA,oBACA,OACA,QACA,OACA,YACA,QAeK,MAAMG,EACMC,SAAWC,EAAAA,yBAE5BC,gBAAAA,CAAiBC,GACfC,KAAKJ,SAASK,IAAIF,EAASG,KAAMH,GACjC,IAAK,MAAMI,KAASJ,EAASK,SAAW,GACtCJ,KAAKJ,SAASK,IAAIE,EAAOJ,EAE7B,CAEAM,qBAAAA,GACE,MAAO,IAAI,IAAIb,IAAI,IAAIQ,KAAKJ,SAASU,UAAUC,IAAKR,GAAaA,EAASG,OAC5E,CAEAM,OAAAA,CAAQC,EAAcC,GACpB,MAAMX,EAAWC,KAAKJ,SAASe,IAAID,EAAQX,UAC3C,IAAKA,EACH,MAAM,IAAIa,MAAM,yBAAyBF,EAAQX,YAGnD,MAAMc,EAAS,IAAIC,EACnBD,EAAOE,YAAYhB,EAASiB,gBAC5B,MACMC,EADOJ,EAAOK,MAAMT,GACRU,SAEZC,EADYC,EAAaJ,EAAM,IAAIzB,IAAIO,EAASuB,oBACpBf,IAAKgB,GAkC3C,SAAyBA,EAAyBxB,GAChD,MAAMyB,EAAaC,EAAkBF,EAAMxB,EAAU,GAErD,MAAO,CACLG,KAAMwB,EAAiBH,GACvBI,UAAWJ,EAAKK,cAAcC,IAAM,EACpCC,QAASP,EAAKQ,YAAYF,IAAM,EAChCG,qB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F,UAAU3F,OAEzC,OAAOqF,EAAcO,KAAML,GAASA,EAAK/E,aAAegF,GAAsBD,EAAK7E,WAAagF,EAClG,CAyDA,SAAStG,EAAiBH,GACxB,MAAM4G,EAAW5G,EAAK6G,kBAAkB,QACxC,GAAID,EACF,OAAOA,EAAShE,KAGlB,MAAMkE,EAAS9G,EAAK8G,OACpB,IAAKA,EACH,OAGF,MAAMC,EAAaD,EAAOD,kBAAkB,QAC5C,OAAOE,GAAYnE,IACrB,CAEA,SAASkC,EAA8BpB,EAAgBzD,EAAoB+G,GACzE,GAAY,IAARA,EACF,OAAO,IAGT,MAAMC,EAAM,IAAM,IAAMtD,KAAKuD,IAAIvD,KAAKqC,IAAItC,EAAQ,IAAM,IAAOzD,EAAa,KAAO0D,KAAKuD,IAAIF,GAC5F,OAAOrD,KAAKqC,IAAI,EAAGrC,KAAKwD,IAAI,IAAY,IAANF,EAAa,KACjD,CAEA,SAAShE,EAAejE,EAA0BoI,GAChDpI,EAAIN,IAAI0I,GAAQpI,EAAII,IAAIgI,IAAU,GAAK,EACzC,CAEA,SAAS1C,EAAUL,EAA8BgD,GAC/C,OAA4B,IAArBhD,EAAUtD,OAAe,EAAI4C,KAAKqC,OAAO3B,EAAUrF,IAAKsI,GAAOA,EAAGD,IAC3E,CAEA,SAAS9D,EAAIxE,GACX,IAAIsD,EAAQ,EACZ,IAAK,MAAM+E,KAASrI,EAClBsD,GAAS+E,EAEX,OAAO/E,CACT,sEAtOO,SAAqBnD,EAAcC,GACxC,OAAOgG,EAAgBlG,QAAQC,EAAMC,EACvC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CodeMetrics, LanguageDefinition, LanguageName, MeasureOptions } from './types.js';
|
|
2
|
+
export declare class TreeMeasurer {
|
|
3
|
+
private readonly registry;
|
|
4
|
+
registerLanguage(language: LanguageDefinition): void;
|
|
5
|
+
getSupportedLanguages(): LanguageName[];
|
|
6
|
+
measure(code: string, options: MeasureOptions): CodeMetrics;
|
|
7
|
+
}
|
|
8
|
+
export declare const defaultMeasurer: TreeMeasurer;
|
|
9
|
+
export declare function measureCode(code: string, options: MeasureOptions): CodeMetrics;
|
package/dist/metrics.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import t from"tree-sitter";import{createLanguageRegistry as e}from"./languages.js";const n=new Set(["&&","||","and","or"]),o=new Set(["+","-","*","/","%","**","=","+=","-=","*=","/=","%=","==","!=","===","!==","<","<=",">",">=","!","~","&","|","^","<<",">>","=>","return","throw","yield","await","break","continue"]),i=new Set(["identifier","property_identifier","field_identifier","type_identifier","number","integer","float","string","string_literal","template_string","character_literal","true","false","null","undefined","nil"]);class r{registry=e();registerLanguage(t){this.registry.set(t.name,t);for(const e of t.aliases??[])this.registry.set(e,t)}getSupportedLanguages(){return[...new Set([...this.registry.values()].map(t=>t.name))]}measure(e,n){const r=this.registry.get(n.language);if(!r)throw new Error(`Unsupported language: ${n.language}`);const s=new t;s.setLanguage(r.parserLanguage);const a=s.parse(e).rootNode,d=l(a,new Set(r.functionNodeTypes)).map(t=>function(t,e){const n=c(t,e,0);return{name:m(t),startLine:t.startPosition.row+1,endLine:t.endPosition.row+1,cyclomaticComplexity:n.cyclomaticComplexity,cognitiveComplexity:n.cognitiveComplexity}}(t,r)),h=c(a,r,0),x=function(t,e){const n=0===t.length?[]:t.split(/\r\n|\n|\r/),o=function(t){const e=[];function n(t){if("comment"===t.type||"line_comment"===t.type||"block_comment"===t.type)for(let n=t.startPosition.row;n<=t.endPosition.row;n+=1)e.push({line:n,startColumn:n===t.startPosition.row?t.startPosition.column:0,endColumn:n===t.endPosition.row?t.endPosition.column:Number.POSITIVE_INFINITY});for(const e of t.namedChildren)n(e)}return n(t),e}(e);let i=0,r=0;for(const[t,e]of n.entries())""!==e.trim()?u(e,t,o)&&(r+=1):i+=1;return{total:n.length,code:n.length-i-r,comment:r,blank:i}}(e,a),C=function(t,e){const n=new Map,r=new Map;function s(t){if("comment"!==t.type){if(0===t.childCount){const s=e.slice(t.startIndex,t.endIndex);return void(o.has(s)||o.has(t.type)?p(n,s||t.type):i.has(t.type)&&p(r,s))}o.has(t.type)&&p(n,t.type);for(const e of t.children)s(e)}}s(t);const a=n.size,c=r.size,l=y(n.values()),u=y(r.values()),m=a+c,f=l+u,g=0===m?0:f*Math.log2(m),d=0===c?0:a/2*(u/c),h=d*g;return{distinctOperators:a,distinctOperands:c,totalOperators:l,totalOperands:u,vocabulary:m,length:f,volume:g,difficulty:d,effort:h,time:h/18,bugs:g/3e3}}(a,e);return{language:r.name,bytes:Buffer.byteLength(e),lines:x,functions:d,classCount:l(a,new Set(r.classNodeTypes)).length,functionCount:d.length,cyclomaticComplexity:h.cyclomaticComplexity,maxCyclomaticComplexity:g(d,"cyclomaticComplexity"),cognitiveComplexity:h.cognitiveComplexity,maxCognitiveComplexity:g(d,"cognitiveComplexity"),nestingDepth:h.nestingDepth,halstead:C,maintainabilityIndex:f(C.volume,h.cyclomaticComplexity,x.code),syntaxTree:n.includeSyntaxTree?a.toString():void 0}}}const s=new r;function a(t,e){return s.measure(t,e)}function c(t,e,o){let i=1,r=0,s=o;const a=new Set(e.decisionNodeTypes),c=new Set(e.nestingNodeTypes);function l(t,e){const o=a.has(t.type),u=c.has(t.type);o&&(i+=1,r+=1+e),function(t){if(t.isNamed)return!1;return n.has(t.text)}(t)&&(i+=1,r+=1);const m=u?e+1:e;s=Math.max(s,m);for(const e of t.children)l(e,m)}for(const e of t.children)l(e,o);return{cyclomaticComplexity:i,cognitiveComplexity:r,nestingDepth:s}}function l(t,e){const n=[];return function t(o){e.has(o.type)&&n.push(o);for(const e of o.namedChildren)t(e)}(t),n}function u(t,e,n){const o=n.filter(t=>t.line===e);if(0===o.length)return!1;const i=t.search(/\S/),r=t.trimEnd().length;return o.some(t=>t.startColumn<=i&&t.endColumn>=r)}function m(t){const e=t.childForFieldName("name");if(e)return e.text;const n=t.parent;if(!n)return;const o=n.childForFieldName("name");return o?.text}function f(t,e,n){if(0===n)return 100;const o=171-5.2*Math.log(Math.max(t,1))-.23*e-16.2*Math.log(n);return Math.max(0,Math.min(100,100*o/171))}function p(t,e){t.set(e,(t.get(e)??0)+1)}function g(t,e){return 0===t.length?0:Math.max(...t.map(t=>t[e]))}function y(t){let e=0;for(const n of t)e+=n;return e}export{r as TreeMeasurer,s as defaultMeasurer,a as measureCode};
|
|
2
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sources":["../src/metrics.ts"],"sourcesContent":["import Parser from 'tree-sitter';\nimport { createLanguageRegistry } from './languages.js';\nimport type {\n CodeMetrics,\n FunctionMetrics,\n HalsteadMetrics,\n LanguageDefinition,\n LanguageName,\n MeasureOptions,\n} from './types.js';\n\nconst booleanOperators = new Set(['&&', '||', 'and', 'or']);\nconst operatorTexts = new Set([\n '+',\n '-',\n '*',\n '/',\n '%',\n '**',\n '=',\n '+=',\n '-=',\n '*=',\n '/=',\n '%=',\n '==',\n '!=',\n '===',\n '!==',\n '<',\n '<=',\n '>',\n '>=',\n '!',\n '~',\n '&',\n '|',\n '^',\n '<<',\n '>>',\n '=>',\n 'return',\n 'throw',\n 'yield',\n 'await',\n 'break',\n 'continue',\n]);\n\nconst operandNodeTypes = new Set([\n 'identifier',\n 'property_identifier',\n 'field_identifier',\n 'type_identifier',\n 'number',\n 'integer',\n 'float',\n 'string',\n 'string_literal',\n 'template_string',\n 'character_literal',\n 'true',\n 'false',\n 'null',\n 'undefined',\n 'nil',\n]);\n\ninterface ComplexityResult {\n cyclomaticComplexity: number;\n cognitiveComplexity: number;\n nestingDepth: number;\n}\n\ninterface CommentSpan {\n line: number;\n startColumn: number;\n endColumn: number;\n}\n\nexport class TreeMeasurer {\n private readonly registry = createLanguageRegistry();\n\n registerLanguage(language: LanguageDefinition): void {\n this.registry.set(language.name, language);\n for (const alias of language.aliases ?? []) {\n this.registry.set(alias, language);\n }\n }\n\n getSupportedLanguages(): LanguageName[] {\n return [...new Set([...this.registry.values()].map((language) => language.name))];\n }\n\n measure(code: string, options: MeasureOptions): CodeMetrics {\n const language = this.registry.get(options.language);\n if (!language) {\n throw new Error(`Unsupported language: ${options.language}`);\n }\n\n const parser = new Parser();\n parser.setLanguage(language.parserLanguage);\n const tree = parser.parse(code);\n const root = tree.rootNode;\n const functions = collectNodes(root, new Set(language.functionNodeTypes));\n const functionMetrics = functions.map((node) => measureFunction(node, language));\n const globalComplexity = measureComplexity(root, language, 0);\n const lines = measureLines(code, root);\n const halstead = measureHalstead(root, code);\n\n return {\n language: language.name,\n bytes: Buffer.byteLength(code),\n lines,\n functions: functionMetrics,\n classCount: collectNodes(root, new Set(language.classNodeTypes)).length,\n functionCount: functionMetrics.length,\n cyclomaticComplexity: globalComplexity.cyclomaticComplexity,\n maxCyclomaticComplexity: maxMetric(functionMetrics, 'cyclomaticComplexity'),\n cognitiveComplexity: globalComplexity.cognitiveComplexity,\n maxCognitiveComplexity: maxMetric(functionMetrics, 'cognitiveComplexity'),\n nestingDepth: globalComplexity.nestingDepth,\n halstead,\n maintainabilityIndex: calculateMaintainabilityIndex(\n halstead.volume,\n globalComplexity.cyclomaticComplexity,\n lines.code\n ),\n syntaxTree: options.includeSyntaxTree ? root.toString() : undefined,\n };\n }\n}\n\nexport const defaultMeasurer = new TreeMeasurer();\n\nexport function measureCode(code: string, options: MeasureOptions): CodeMetrics {\n return defaultMeasurer.measure(code, options);\n}\n\nfunction measureFunction(node: Parser.SyntaxNode, language: LanguageDefinition): FunctionMetrics {\n const complexity = measureComplexity(node, language, 0);\n\n return {\n name: findFunctionName(node),\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n cyclomaticComplexity: complexity.cyclomaticComplexity,\n cognitiveComplexity: complexity.cognitiveComplexity,\n };\n}\n\nfunction measureComplexity(node: Parser.SyntaxNode, language: LanguageDefinition, nesting: number): ComplexityResult {\n let cyclomaticComplexity = 1;\n let cognitiveComplexity = 0;\n let nestingDepth = nesting;\n const decisionNodes = new Set(language.decisionNodeTypes);\n const nestingNodes = new Set(language.nestingNodeTypes);\n\n function visit(current: Parser.SyntaxNode, currentNesting: number): void {\n const isDecision = decisionNodes.has(current.type);\n const isNesting = nestingNodes.has(current.type);\n\n if (isDecision) {\n cyclomaticComplexity += 1;\n cognitiveComplexity += 1 + currentNesting;\n }\n\n if (isBooleanOperator(current)) {\n cyclomaticComplexity += 1;\n cognitiveComplexity += 1;\n }\n\n const childNesting = isNesting ? currentNesting + 1 : currentNesting;\n nestingDepth = Math.max(nestingDepth, childNesting);\n\n for (const child of current.children) {\n visit(child, childNesting);\n }\n }\n\n for (const child of node.children) {\n visit(child, nesting);\n }\n\n return { cyclomaticComplexity, cognitiveComplexity, nestingDepth };\n}\n\nfunction isBooleanOperator(node: Parser.SyntaxNode): boolean {\n if (node.isNamed) {\n return false;\n }\n\n return booleanOperators.has(node.text);\n}\n\nfunction collectNodes(root: Parser.SyntaxNode, nodeTypes: Set<string>): Parser.SyntaxNode[] {\n const nodes: Parser.SyntaxNode[] = [];\n\n function visit(node: Parser.SyntaxNode): void {\n if (nodeTypes.has(node.type)) {\n nodes.push(node);\n }\n\n for (const child of node.namedChildren) {\n visit(child);\n }\n }\n\n visit(root);\n return nodes;\n}\n\nfunction measureLines(code: string, root: Parser.SyntaxNode): CodeMetrics['lines'] {\n const sourceLines = code.length === 0 ? [] : code.split(/\\r\\n|\\n|\\r/);\n const commentSpans = collectCommentSpans(root);\n let blank = 0;\n let comment = 0;\n\n for (const [index, line] of sourceLines.entries()) {\n if (line.trim() === '') {\n blank += 1;\n continue;\n }\n\n if (isCommentOnlyLine(line, index, commentSpans)) {\n comment += 1;\n }\n }\n\n return {\n total: sourceLines.length,\n code: sourceLines.length - blank - comment,\n comment,\n blank,\n };\n}\n\nfunction collectCommentSpans(root: Parser.SyntaxNode): CommentSpan[] {\n const spans: CommentSpan[] = [];\n\n function visit(node: Parser.SyntaxNode): void {\n if (node.type === 'comment' || node.type === 'line_comment' || node.type === 'block_comment') {\n for (let row = node.startPosition.row; row <= node.endPosition.row; row += 1) {\n spans.push({\n line: row,\n startColumn: row === node.startPosition.row ? node.startPosition.column : 0,\n endColumn: row === node.endPosition.row ? node.endPosition.column : Number.POSITIVE_INFINITY,\n });\n }\n }\n\n for (const child of node.namedChildren) {\n visit(child);\n }\n }\n\n visit(root);\n return spans;\n}\n\nfunction isCommentOnlyLine(line: string, lineIndex: number, spans: CommentSpan[]): boolean {\n const relevantSpans = spans.filter((span) => span.line === lineIndex);\n if (relevantSpans.length === 0) {\n return false;\n }\n\n const firstContentColumn = line.search(/\\S/);\n const lastContentColumn = line.trimEnd().length;\n\n return relevantSpans.some((span) => span.startColumn <= firstContentColumn && span.endColumn >= lastContentColumn);\n}\n\nfunction measureHalstead(root: Parser.SyntaxNode, code: string): HalsteadMetrics {\n const operators = new Map<string, number>();\n const operands = new Map<string, number>();\n\n function visit(node: Parser.SyntaxNode): void {\n if (node.type === 'comment') {\n return;\n }\n\n if (node.childCount === 0) {\n const text = code.slice(node.startIndex, node.endIndex);\n if (operatorTexts.has(text) || operatorTexts.has(node.type)) {\n incrementCount(operators, text || node.type);\n } else if (operandNodeTypes.has(node.type)) {\n incrementCount(operands, text);\n }\n return;\n }\n\n if (operatorTexts.has(node.type)) {\n incrementCount(operators, node.type);\n }\n\n for (const child of node.children) {\n visit(child);\n }\n }\n\n visit(root);\n\n const distinctOperators = operators.size;\n const distinctOperands = operands.size;\n const totalOperators = sum(operators.values());\n const totalOperands = sum(operands.values());\n const vocabulary = distinctOperators + distinctOperands;\n const length = totalOperators + totalOperands;\n const volume = vocabulary === 0 ? 0 : length * Math.log2(vocabulary);\n const difficulty = distinctOperands === 0 ? 0 : (distinctOperators / 2) * (totalOperands / distinctOperands);\n const effort = difficulty * volume;\n\n return {\n distinctOperators,\n distinctOperands,\n totalOperators,\n totalOperands,\n vocabulary,\n length,\n volume,\n difficulty,\n effort,\n time: effort / 18,\n bugs: volume / 3000,\n };\n}\n\nfunction findFunctionName(node: Parser.SyntaxNode): string | undefined {\n const nameNode = node.childForFieldName('name');\n if (nameNode) {\n return nameNode.text;\n }\n\n const parent = node.parent;\n if (!parent) {\n return undefined;\n }\n\n const parentName = parent.childForFieldName('name');\n return parentName?.text;\n}\n\nfunction calculateMaintainabilityIndex(volume: number, complexity: number, loc: number): number {\n if (loc === 0) {\n return 100;\n }\n\n const raw = 171 - 5.2 * Math.log(Math.max(volume, 1)) - 0.23 * complexity - 16.2 * Math.log(loc);\n return Math.max(0, Math.min(100, (raw * 100) / 171));\n}\n\nfunction incrementCount(map: Map<string, number>, value: string): void {\n map.set(value, (map.get(value) ?? 0) + 1);\n}\n\nfunction maxMetric(functions: FunctionMetrics[], key: 'cyclomaticComplexity' | 'cognitiveComplexity'): number {\n return functions.length === 0 ? 0 : Math.max(...functions.map((fn) => fn[key]));\n}\n\nfunction sum(values: Iterable<number>): number {\n let total = 0;\n for (const value of values) {\n total += value;\n }\n return total;\n}\n"],"names":["booleanOperators","Set","operatorTexts","operandNodeTypes","TreeMeasurer","registry","createLanguageRegistry","registerLanguage","language","this","set","name","alias","aliases","getSupportedLanguages","values","map","measure","code","options","get","Error","parser","Parser","setLanguage","parserLanguage","root","parse","rootNode","functionMetrics","collectNodes","functionNodeTypes","node","complexity","measureComplexity","findFunctionName","startLine","startPosition","row","endLine","endPosition","cyclomaticComplexity","cognitiveComplexity","measureFunction","globalComplexity","lines","sourceLines","length","split","commentSpans","spans","visit","type","push","line","startColumn","column","endColumn","Number","POSITIVE_INFINITY","child","namedChildren","collectCommentSpans","blank","comment","index","entries","trim","isCommentOnlyLine","total","measureLines","halstead","operators","Map","operands","childCount","text","slice","startIndex","endIndex","has","incrementCount","children","distinctOperators","size","distinctOperands","totalOperators","sum","totalOperands","vocabulary","volume","Math","log2","difficulty","effort","time","bugs","measureHalstead","bytes","Buffer","byteLength","functions","classCount","classNodeTypes","functionCount","maxCyclomaticComplexity","maxMetric","maxCognitiveComplexity","nestingDepth","maintainabilityIndex","calculateMaintainabilityIndex","syntaxTree","includeSyntaxTree","toString","undefined","defaultMeasurer","measureCode","nesting","decisionNodes","decisionNodeTypes","nestingNodes","nestingNodeTypes","current","currentNesting","isDecision","isNesting","isNamed","isBooleanOperator","childNesting","max","nodeTypes","nodes","lineIndex","relevantSpans","filter","span","firstContentColumn","search","lastContentColumn","trimEnd","some","nameNode","childForFieldName","parent","parentName","loc","raw","log","min","value","key","fn"],"mappings":"mFAWA,MAAMA,EAAmB,IAAIC,IAAI,CAAC,KAAM,KAAM,MAAO,OAC/CC,EAAgB,IAAID,IAAI,CAC5B,IACA,IACA,IACA,IACA,IACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,MACA,IACA,KACA,IACA,KACA,IACA,IACA,IACA,IACA,IACA,KACA,KACA,KACA,SACA,QACA,QACA,QACA,QACA,aAGIE,EAAmB,IAAIF,IAAI,CAC/B,aACA,sBACA,mBACA,kBACA,SACA,UACA,QACA,SACA,iBACA,kBACA,oBACA,OACA,QACA,OACA,YACA,QAeK,MAAMG,EACMC,SAAWC,IAE5BC,gBAAAA,CAAiBC,GACfC,KAAKJ,SAASK,IAAIF,EAASG,KAAMH,GACjC,IAAK,MAAMI,KAASJ,EAASK,SAAW,GACtCJ,KAAKJ,SAASK,IAAIE,EAAOJ,EAE7B,CAEAM,qBAAAA,GACE,MAAO,IAAI,IAAIb,IAAI,IAAIQ,KAAKJ,SAASU,UAAUC,IAAKR,GAAaA,EAASG,OAC5E,CAEAM,OAAAA,CAAQC,EAAcC,GACpB,MAAMX,EAAWC,KAAKJ,SAASe,IAAID,EAAQX,UAC3C,IAAKA,EACH,MAAM,IAAIa,MAAM,yBAAyBF,EAAQX,YAGnD,MAAMc,EAAS,IAAIC,EACnBD,EAAOE,YAAYhB,EAASiB,gBAC5B,MACMC,EADOJ,EAAOK,MAAMT,GACRU,SAEZC,EADYC,EAAaJ,EAAM,IAAIzB,IAAIO,EAASuB,oBACpBf,IAAKgB,GAkC3C,SAAyBA,EAAyBxB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| 'typescript' | 'tsx';
|
|
2
|
+
export type LanguageName = SupportedLanguage | (string & {});
|
|
3
|
+
export type ParserLanguage = unknown;
|
|
4
|
+
export interface LanguageDefinition {
|
|
5
|
+
name: LanguageName;
|
|
6
|
+
parserLanguage: ParserLanguage;
|
|
7
|
+
aliases?: readonly string[];
|
|
8
|
+
functionNodeTypes?: readonly string[];
|
|
9
|
+
classNodeTypes?: readonly string[];
|
|
10
|
+
decisionNodeTypes?: readonly string[];
|
|
11
|
+
nestingNodeTypes?: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export interface MeasureOptions {
|
|
14
|
+
language: LanguageName;
|
|
15
|
+
includeSyntaxTree?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface LineMetrics {
|
|
18
|
+
total: number;
|
|
19
|
+
code: number;
|
|
20
|
+
comment: number;
|
|
21
|
+
blank: number;
|
|
22
|
+
}
|
|
23
|
+
export interface HalsteadMetrics {
|
|
24
|
+
distinctOperators: number;
|
|
25
|
+
distinctOperands: number;
|
|
26
|
+
totalOperators: number;
|
|
27
|
+
totalOperands: number;
|
|
28
|
+
vocabulary: number;
|
|
29
|
+
length: number;
|
|
30
|
+
volume: number;
|
|
31
|
+
difficulty: number;
|
|
32
|
+
effort: number;
|
|
33
|
+
time: number;
|
|
34
|
+
bugs: number;
|
|
35
|
+
}
|
|
36
|
+
export interface FunctionMetrics {
|
|
37
|
+
name?: string;
|
|
38
|
+
startLine: number;
|
|
39
|
+
endLine: number;
|
|
40
|
+
cyclomaticComplexity: number;
|
|
41
|
+
cognitiveComplexity: number;
|
|
42
|
+
}
|
|
43
|
+
export interface CodeMetrics {
|
|
44
|
+
language: LanguageName;
|
|
45
|
+
bytes: number;
|
|
46
|
+
lines: LineMetrics;
|
|
47
|
+
functions: FunctionMetrics[];
|
|
48
|
+
classCount: number;
|
|
49
|
+
functionCount: number;
|
|
50
|
+
cyclomaticComplexity: number;
|
|
51
|
+
maxCyclomaticComplexity: number;
|
|
52
|
+
cognitiveComplexity: number;
|
|
53
|
+
maxCognitiveComplexity: number;
|
|
54
|
+
nestingDepth: number;
|
|
55
|
+
halstead: HalsteadMetrics;
|
|
56
|
+
maintainabilityIndex: number;
|
|
57
|
+
syntaxTree?: string;
|
|
58
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "measure-code",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Measure code metrics with tree-sitter.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tree-sitter",
|
|
7
|
+
"metrics",
|
|
8
|
+
"loc",
|
|
9
|
+
"cyclomatic-complexity",
|
|
10
|
+
"cognitive-complexity"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/WillBooster/tree-measurer.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"author": "WillBooster Inc.",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"require": "./dist/index.cjs",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"main": "dist/index.cjs",
|
|
27
|
+
"module": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "build-ts lib",
|
|
34
|
+
"cleanup": "yarn format && yarn lint-fix",
|
|
35
|
+
"format": "sort-package-json && yarn format-code",
|
|
36
|
+
"format-code": "oxfmt --write --no-error-on-unmatched-pattern . '!**/package.json'",
|
|
37
|
+
"lint": "oxlint --no-error-on-unmatched-pattern .",
|
|
38
|
+
"lint-fix": "yarn lint --fix",
|
|
39
|
+
"prepare": "lefthook install || true",
|
|
40
|
+
"test": "vitest",
|
|
41
|
+
"typecheck": "wb typecheck",
|
|
42
|
+
"verify": "wb verify",
|
|
43
|
+
"verify-full": "wb verify --full"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"tree-sitter": "^0.21.1",
|
|
47
|
+
"tree-sitter-go": "^0.21.2",
|
|
48
|
+
"tree-sitter-javascript": "^0.21.4",
|
|
49
|
+
"tree-sitter-python": "^0.21.0",
|
|
50
|
+
"tree-sitter-typescript": "^0.21.2"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@tsconfig/node-lts": "24.0.0",
|
|
54
|
+
"@tsconfig/node-ts": "23.6.4",
|
|
55
|
+
"@types/node": "25.9.4",
|
|
56
|
+
"@typescript/native-preview": "7.0.0-dev.20260615.1",
|
|
57
|
+
"@willbooster/oxfmt-config": "1.2.2",
|
|
58
|
+
"@willbooster/oxlint-config": "1.4.8",
|
|
59
|
+
"@willbooster/wb": "13.22.18",
|
|
60
|
+
"build-ts": "17.1.27",
|
|
61
|
+
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
62
|
+
"lefthook": "2.1.9",
|
|
63
|
+
"oxfmt": "0.56.0",
|
|
64
|
+
"oxlint": "1.71.0",
|
|
65
|
+
"oxlint-tsgolint": "0.23.0",
|
|
66
|
+
"semantic-release": "25.0.5",
|
|
67
|
+
"sort-package-json": "4.0.0",
|
|
68
|
+
"vitest": "4.1.9"
|
|
69
|
+
},
|
|
70
|
+
"packageManager": "yarn@4.17.0",
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=24"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
}
|
|
77
|
+
}
|