code-gauge 4.7.1 → 5.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.
Files changed (80) hide show
  1. package/README.md +35 -10
  2. package/THIRD-PARTY-NOTICES.txt +595 -29
  3. package/dist/cli.cjs +3 -3
  4. package/dist/cli.cjs.map +1 -1
  5. package/dist/cli.js +3 -3
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cliConfig.cjs +1 -1
  8. package/dist/cliConfig.cjs.map +1 -1
  9. package/dist/cliConfig.d.ts +13 -3
  10. package/dist/cliConfig.js +1 -1
  11. package/dist/cliConfig.js.map +1 -1
  12. package/dist/crossFileDuplication.cjs +1 -1
  13. package/dist/crossFileDuplication.cjs.map +1 -1
  14. package/dist/crossFileDuplication.js +1 -1
  15. package/dist/crossFileDuplication.js.map +1 -1
  16. package/dist/crossFileNearMiss.cjs +1 -1
  17. package/dist/crossFileNearMiss.cjs.map +1 -1
  18. package/dist/crossFileNearMiss.js +1 -1
  19. package/dist/crossFileNearMiss.js.map +1 -1
  20. package/dist/diffCommand.cjs +3 -3
  21. package/dist/diffCommand.cjs.map +1 -1
  22. package/dist/diffCommand.js +3 -3
  23. package/dist/diffCommand.js.map +1 -1
  24. package/dist/duplicateSelection.cjs +1 -1
  25. package/dist/duplicateSelection.cjs.map +1 -1
  26. package/dist/duplicateSelection.js +1 -1
  27. package/dist/duplicateSelection.js.map +1 -1
  28. package/dist/duplication.cjs +1 -1
  29. package/dist/duplication.cjs.map +1 -1
  30. package/dist/duplication.js +1 -1
  31. package/dist/duplication.js.map +1 -1
  32. package/dist/exclusion.cjs +2 -0
  33. package/dist/exclusion.cjs.map +1 -0
  34. package/dist/exclusion.d.ts +30 -0
  35. package/dist/exclusion.js +2 -0
  36. package/dist/exclusion.js.map +1 -0
  37. package/dist/git.cjs +1 -1
  38. package/dist/git.cjs.map +1 -1
  39. package/dist/git.d.ts +16 -0
  40. package/dist/git.js +1 -1
  41. package/dist/git.js.map +1 -1
  42. package/dist/index.cjs +1 -1
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.js +1 -1
  45. package/dist/languages.cjs +1 -1
  46. package/dist/languages.cjs.map +1 -1
  47. package/dist/languages.js +1 -1
  48. package/dist/languages.js.map +1 -1
  49. package/dist/newDuplication.cjs +2 -0
  50. package/dist/newDuplication.cjs.map +1 -0
  51. package/dist/newDuplication.d.ts +40 -0
  52. package/dist/newDuplication.js +2 -0
  53. package/dist/newDuplication.js.map +1 -0
  54. package/dist/regressionGate.cjs +1 -1
  55. package/dist/regressionGate.cjs.map +1 -1
  56. package/dist/regressionGate.d.ts +8 -6
  57. package/dist/regressionGate.js +1 -1
  58. package/dist/regressionGate.js.map +1 -1
  59. package/dist/scan.cjs +1 -1
  60. package/dist/scan.cjs.map +1 -1
  61. package/dist/scan.d.ts +12 -3
  62. package/dist/scan.js +1 -1
  63. package/dist/scan.js.map +1 -1
  64. package/dist/worker.cjs +1 -1
  65. package/dist/worker.cjs.map +1 -1
  66. package/dist/worker.js +1 -1
  67. package/dist/worker.js.map +1 -1
  68. package/native/Cargo.lock +47 -15
  69. package/native/Cargo.toml +9 -9
  70. package/native/code-gauge.wasm +0 -0
  71. package/native/src/complexity.rs +26 -33
  72. package/native/src/dep_degree.rs +43 -32
  73. package/native/src/duplication.rs +158 -40
  74. package/native/src/functions.rs +20 -62
  75. package/native/src/languages.rs +28 -7
  76. package/native/src/measure.rs +16 -27
  77. package/native/src/ncss.rs +32 -23
  78. package/native/src/tree_index.rs +9 -0
  79. package/native/src/util.rs +12 -57
  80. package/package.json +10 -10
@@ -53,30 +53,12 @@ pub fn node_text<'a>(node: Node<'_>, code: &Source<'a>) -> &'a str {
53
53
  &code.code[code.utf8_offset(node.start_byte())..code.utf8_offset(node.end_byte())]
54
54
  }
55
55
 
56
- /// Kotlin spells the bound receiver of a callable reference (`xs::size`) as a `type_identifier`,
57
- /// the same kind as an unbound type (`List::size`); the receiver position is what distinguishes
58
- /// it, and only a visible definition then tells a variable from a type.
59
- pub fn is_kotlin_callable_receiver(node: Node<'_>) -> bool {
60
- node.kind_name() == "type_identifier"
61
- && node.parent_node().is_some_and(|parent| {
62
- parent.kind_name() == "callable_reference"
63
- && parent
64
- .named_child(0)
65
- .is_some_and(|first| first.id() == node.id())
66
- })
67
- }
68
-
69
- /// Whether the node is a leaf for token-level walks. Kotlin soft keywords used as names (`value`,
70
- /// `data`, `get`, ...) parse as a `simple_identifier` — or its aliases `interpolated_identifier`
71
- /// (`"$value"`) and `type_identifier` (`value::size`) — wrapping an anonymous keyword token, so a
72
- /// plain leaf check would see the keyword instead of the identifier. Every other grammar's
73
- /// identifier kinds are already leaves.
74
- pub fn is_identifier_leaf(node: Node<'_>) -> bool {
75
- node.child_count() == 0
76
- || matches!(
77
- node.kind_name(),
78
- "simple_identifier" | "interpolated_identifier" | "type_identifier"
79
- )
56
+ /// Kotlin spells `true`, `false`, and `null` as plain identifiers, which the other grammars give
57
+ /// literal node kinds of their own (an identifier with that text, e.g. Go's `null`, is a variable).
58
+ pub fn is_kotlin_keyword_literal(node: Node<'_>, code: &Source<'_>) -> bool {
59
+ crate::tree_index::language_name() == "kotlin"
60
+ && node.kind_name() == "identifier"
61
+ && matches!(node_text(node, code), "true" | "false" | "null")
80
62
  }
81
63
 
82
64
  pub fn named_children<'t>(node: Node<'t>) -> Vec<Node<'t>> {
@@ -91,8 +73,8 @@ pub fn all_children<'t>(node: Node<'t>) -> Vec<Node<'t>> {
91
73
 
92
74
  /// Children carrying the field, with node-tree-sitter's vendored-core semantics: extra children
93
75
  /// (error-recovery nodes, comments) inherit the field of the preceding structural sibling.
94
- /// tree-sitter 0.22.6 instead reports no field for extras (ts_node_field_name_for_child gained an
95
- /// is_extra early return), which would desynchronize field-based extraction on malformed source.
76
+ /// The core instead reports no field for extras (ts_node_field_name_for_child returns early for
77
+ /// them), which would desynchronize field-based extraction on malformed source.
96
78
  pub fn find_children_by_field_name<'t>(node: Node<'t>, field_name: &str) -> Vec<Node<'t>> {
97
79
  let mut children = Vec::new();
98
80
  let mut preceding_structural_field: Option<&'static str> = None;
@@ -166,38 +148,11 @@ pub fn to_int32(value: i64) -> i32 {
166
148
  value as i32
167
149
  }
168
150
 
169
- /// The body following a Kotlin `if_expression`'s bare `else` keyword (the grammar has no else
170
- /// clause node and no fields), or None for other languages' if nodes and else-less ifs.
171
- pub fn kotlin_else_body(if_node: Node<'_>) -> Option<Node<'_>> {
172
- if if_node.kind_name() != "if_expression" {
173
- return None;
174
- }
175
- let children = all_children(if_node);
176
- let else_index = children
177
- .iter()
178
- .position(|child| !child.is_named() && child.kind_name() == "else")?;
179
- children[else_index + 1..]
180
- .iter()
181
- .copied()
182
- .find(|child| child.kind_name() == "control_structure_body")
183
- }
184
-
185
151
  /// Kotlin's `try { } catch { }` shares its node kind with Rust's `?` operator; only the Kotlin form
186
- /// holds a body or clause child.
152
+ /// starts with the `try` keyword.
187
153
  pub fn is_kotlin_try_expression(node: Node<'_>) -> bool {
188
154
  node.kind_name() == "try_expression"
189
- && named_children(node).iter().any(|child| {
190
- matches!(
191
- child.kind_name(),
192
- "statements" | "catch_block" | "finally_block"
193
- )
194
- })
195
- }
196
-
197
- /// Whether a Kotlin else body is a braceless `else if`: the nested if sits directly in the
198
- /// control_structure_body, whereas a braced `else { if ... }` wraps it in `statements`.
199
- pub fn is_kotlin_else_if_body(else_body: Node<'_>) -> bool {
200
- named_children(else_body)
201
- .iter()
202
- .any(|child| child.kind_name() == "if_expression")
155
+ && node
156
+ .child(0)
157
+ .is_some_and(|keyword| !keyword.is_named() && keyword.kind_name() == "try")
203
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-gauge",
3
- "version": "4.7.1",
3
+ "version": "5.0.0",
4
4
  "description": "Measure code metrics with tree-sitter.",
5
5
  "keywords": [
6
6
  "cli",
@@ -73,8 +73,8 @@
73
73
  "@types/node": "25.9.4",
74
74
  "@willbooster/oxfmt-config": "1.2.2",
75
75
  "@willbooster/oxlint-config": "1.4.8",
76
- "@willbooster/wb": "22.7.1",
77
- "build-ts": "21.0.16",
76
+ "@willbooster/wb": "22.8.0",
77
+ "build-ts": "21.0.19",
78
78
  "conventional-changelog-conventionalcommits": "9.3.1",
79
79
  "lefthook": "2.1.14",
80
80
  "oxfmt": "0.68.0",
@@ -94,12 +94,12 @@
94
94
  "registry": "https://registry.npmjs.org/"
95
95
  },
96
96
  "optionalDependencies": {
97
- "code-gauge-linux-x64-gnu": "4.7.1",
98
- "code-gauge-linux-arm64-gnu": "4.7.1",
99
- "code-gauge-linux-x64-musl": "4.7.1",
100
- "code-gauge-linux-arm64-musl": "4.7.1",
101
- "code-gauge-darwin-x64": "4.7.1",
102
- "code-gauge-darwin-arm64": "4.7.1",
103
- "code-gauge-win32-x64-msvc": "4.7.1"
97
+ "code-gauge-linux-x64-gnu": "5.0.0",
98
+ "code-gauge-linux-arm64-gnu": "5.0.0",
99
+ "code-gauge-linux-x64-musl": "5.0.0",
100
+ "code-gauge-linux-arm64-musl": "5.0.0",
101
+ "code-gauge-darwin-x64": "5.0.0",
102
+ "code-gauge-darwin-arm64": "5.0.0",
103
+ "code-gauge-win32-x64-msvc": "5.0.0"
104
104
  }
105
105
  }