code-gauge 10.1.0 → 10.2.1

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 (42) hide show
  1. package/README.md +37 -15
  2. package/THIRD-PARTY-NOTICES.txt +8 -8
  3. package/dist/checkCommand.cjs +1 -1
  4. package/dist/checkCommand.cjs.map +1 -1
  5. package/dist/checkCommand.js +1 -1
  6. package/dist/checkCommand.js.map +1 -1
  7. package/dist/crossFileDuplication.cjs +1 -1
  8. package/dist/crossFileDuplication.cjs.map +1 -1
  9. package/dist/crossFileDuplication.d.ts +3 -2
  10. package/dist/crossFileDuplication.js +1 -1
  11. package/dist/crossFileDuplication.js.map +1 -1
  12. package/dist/crossFileNearMiss.cjs +1 -1
  13. package/dist/crossFileNearMiss.cjs.map +1 -1
  14. package/dist/crossFileNearMiss.d.ts +9 -4
  15. package/dist/crossFileNearMiss.js +1 -1
  16. package/dist/crossFileNearMiss.js.map +1 -1
  17. package/dist/duplication.cjs +1 -1
  18. package/dist/duplication.cjs.map +1 -1
  19. package/dist/duplication.d.ts +28 -7
  20. package/dist/duplication.js +1 -1
  21. package/dist/duplication.js.map +1 -1
  22. package/dist/thresholdCheck.cjs +1 -1
  23. package/dist/thresholdCheck.cjs.map +1 -1
  24. package/dist/thresholdCheck.d.ts +2 -0
  25. package/dist/thresholdCheck.js +1 -1
  26. package/dist/thresholdCheck.js.map +1 -1
  27. package/dist/thresholds.cjs.map +1 -1
  28. package/dist/thresholds.d.ts +2 -3
  29. package/dist/thresholds.js.map +1 -1
  30. package/dist/types.d.ts +20 -8
  31. package/native/Cargo.lock +16 -16
  32. package/native/Cargo.toml +8 -8
  33. package/native/code-gauge.wasm +0 -0
  34. package/native/src/complexity.rs +10 -1
  35. package/native/src/container.rs +158 -7
  36. package/native/src/dep_degree.rs +13 -14
  37. package/native/src/duplication.rs +302 -137
  38. package/native/src/functions.rs +112 -24
  39. package/native/src/languages.rs +5 -0
  40. package/native/src/measure.rs +9 -4
  41. package/native/src/near_miss.rs +303 -52
  42. package/package.json +8 -8
@@ -72,7 +72,6 @@ const DECLARATOR_WRAPPER_TYPES: &[&str] = &[
72
72
  "parenthesized_declarator",
73
73
  "function_declarator",
74
74
  "attributed_declarator",
75
- "pointer_type_declarator",
76
75
  "qualified_identifier",
77
76
  ];
78
77
 
@@ -149,16 +148,10 @@ pub fn measure_dep_degree(
149
148
  pairs
150
149
  }
151
150
 
152
- /// A C++ member-pointer variable (`int C::* p`, also `int C::* arr[1]`) is declared as a
153
- /// `type_identifier` under the `pointer_type_declarator` spelling `C::*`, possibly through further
154
- /// declarator wrappers; every other `type_identifier` names a type, not a variable. Kotlin spells
155
- /// type names as identifiers: in a `user_type`, or as a type parameter's fieldless name (C# puts its
156
- /// type parameter in a `name` field).
151
+ /// Kotlin spells type names as identifiers: in a `user_type`, or as a type parameter's fieldless
152
+ /// name (C# puts its type parameter in a `name` field).
157
153
  fn is_variable_leaf(leaf: &DepDegreeLeaf<'_>) -> bool {
158
154
  let node = leaf.node;
159
- if node.kind_name() == "type_identifier" {
160
- return is_member_pointer_name(node);
161
- }
162
155
  VARIABLE_NODE_TYPES.contains(&node.kind_name())
163
156
  && !node.parent_node().is_some_and(|parent| {
164
157
  parent.kind_name() == "user_type"
@@ -166,15 +159,21 @@ fn is_variable_leaf(leaf: &DepDegreeLeaf<'_>) -> bool {
166
159
  })
167
160
  }
168
161
 
162
+ /// Whether the identifier is the name a C++ member pointer declares (`int C::* p`, also
163
+ /// `int C::* arr[1]`): its `pointer_declarator`, possibly around further declarator wrappers, is
164
+ /// the `name` of the `qualified_identifier` spelling the class.
169
165
  fn is_member_pointer_name(node: Node<'_>) -> bool {
170
166
  let mut current = node;
171
167
  while let Some(parent) = current.parent_node() {
172
- if parent.kind_name() == "pointer_type_declarator" {
173
- return true;
168
+ // The kind is tested before the field is looked up: this runs for every variable read,
169
+ // and scanning the children of a high-arity parent (a list of arguments) each time would
170
+ // cost the square of its length.
171
+ if parent.kind_name() == "qualified_identifier" {
172
+ return current.kind_name() == "pointer_declarator"
173
+ && field_name_in_parent(current, parent) == Some("name");
174
174
  }
175
175
  // The climb follows the declared-name position only, exactly like unwrap_declarator_wrappers.
176
176
  if !DECLARATOR_WRAPPER_TYPES.contains(&parent.kind_name())
177
- || parent.kind_name() == "qualified_identifier"
178
177
  || field_name_in_parent(current, parent).is_some_and(|field| field != "declarator")
179
178
  {
180
179
  return false;
@@ -338,7 +337,7 @@ fn is_definition_field(holder: Node<'_>, field_name: Option<&str>) -> bool {
338
337
 
339
338
  /// Climbs from the identifier through the C/C++ declarator wrappers it is the declared name of
340
339
  /// (`reference_declarator` and `parenthesized_declarator` expose no field, so their name is the
341
- /// fieldless child; a member pointer's `pointer_type_declarator` is the `name` of a
340
+ /// fieldless child; a member pointer's `pointer_declarator` is the `name` of a
342
341
  /// `qualified_identifier`; an `array_declarator` size or a nested parameter has another field and
343
342
  /// stops the climb) to the outermost wrapper and its field in the declaration.
344
343
  fn unwrap_declarator_wrappers<'t>(leaf: &DepDegreeLeaf<'t>) -> (Node<'t>, Option<&'t str>) {
@@ -400,7 +399,7 @@ fn is_parameter_definition(leaf: &DepDegreeLeaf<'_>) -> bool {
400
399
  // O(1).
401
400
  let continues_member_pointer = declares_member_pointer
402
401
  && parent.kind_name() == "qualified_identifier"
403
- && (current.kind_name() == "pointer_type_declarator" || in_member_pointer)
402
+ && (current.kind_name() == "pointer_declarator" || in_member_pointer)
404
403
  && field_name_in_parent(current, parent) == Some("name");
405
404
  in_member_pointer = continues_member_pointer;
406
405
  if depth >= 1