code-gauge 4.7.0 → 4.8.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 (78) hide show
  1. package/README.md +1 -1
  2. package/THIRD-PARTY-NOTICES.txt +595 -29
  3. package/dist/cli.cjs +1 -1
  4. package/dist/cli.cjs.map +1 -1
  5. package/dist/cli.js +1 -1
  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.js +1 -1
  10. package/dist/cliConfig.js.map +1 -1
  11. package/dist/crossFileDuplication.cjs +1 -1
  12. package/dist/crossFileDuplication.cjs.map +1 -1
  13. package/dist/crossFileDuplication.js +1 -1
  14. package/dist/crossFileDuplication.js.map +1 -1
  15. package/dist/crossFileNearMiss.cjs +1 -1
  16. package/dist/crossFileNearMiss.cjs.map +1 -1
  17. package/dist/crossFileNearMiss.js +1 -1
  18. package/dist/crossFileNearMiss.js.map +1 -1
  19. package/dist/diffCommand.cjs +3 -3
  20. package/dist/diffCommand.cjs.map +1 -1
  21. package/dist/diffCommand.js +3 -3
  22. package/dist/diffCommand.js.map +1 -1
  23. package/dist/duplicateSelection.cjs +1 -1
  24. package/dist/duplicateSelection.cjs.map +1 -1
  25. package/dist/duplicateSelection.js +1 -1
  26. package/dist/duplicateSelection.js.map +1 -1
  27. package/dist/duplication.cjs +1 -1
  28. package/dist/duplication.cjs.map +1 -1
  29. package/dist/duplication.js +1 -1
  30. package/dist/duplication.js.map +1 -1
  31. package/dist/git.cjs +1 -1
  32. package/dist/git.cjs.map +1 -1
  33. package/dist/git.js +1 -1
  34. package/dist/git.js.map +1 -1
  35. package/dist/languages.cjs +1 -1
  36. package/dist/languages.cjs.map +1 -1
  37. package/dist/languages.js +1 -1
  38. package/dist/languages.js.map +1 -1
  39. package/dist/metrics.cjs +1 -1
  40. package/dist/metrics.cjs.map +1 -1
  41. package/dist/metrics.d.ts +8 -3
  42. package/dist/metrics.js +1 -1
  43. package/dist/metrics.js.map +1 -1
  44. package/dist/nativeMetrics.cjs +3 -3
  45. package/dist/nativeMetrics.cjs.map +1 -1
  46. package/dist/nativeMetrics.d.ts +19 -3
  47. package/dist/nativeMetrics.js +3 -3
  48. package/dist/nativeMetrics.js.map +1 -1
  49. package/dist/regressionGate.cjs +1 -1
  50. package/dist/regressionGate.cjs.map +1 -1
  51. package/dist/regressionGate.js +1 -1
  52. package/dist/regressionGate.js.map +1 -1
  53. package/dist/scan.cjs +1 -1
  54. package/dist/scan.cjs.map +1 -1
  55. package/dist/scan.d.ts +2 -2
  56. package/dist/scan.js +1 -1
  57. package/dist/scan.js.map +1 -1
  58. package/dist/wasmBinding.cjs +1 -1
  59. package/dist/wasmBinding.cjs.map +1 -1
  60. package/dist/wasmBinding.js +1 -1
  61. package/dist/wasmBinding.js.map +1 -1
  62. package/native/Cargo.lock +48 -15
  63. package/native/Cargo.toml +11 -10
  64. package/native/code-gauge.wasm +0 -0
  65. package/native/src/complexity.rs +152 -255
  66. package/native/src/dep_degree.rs +79 -65
  67. package/native/src/duplication.rs +114 -97
  68. package/native/src/functions.rs +181 -206
  69. package/native/src/languages.rs +48 -7
  70. package/native/src/lib.rs +10 -5
  71. package/native/src/measure.rs +125 -150
  72. package/native/src/napi.rs +61 -2
  73. package/native/src/ncss.rs +108 -104
  74. package/native/src/near_miss.rs +7 -7
  75. package/native/src/tree_index.rs +119 -0
  76. package/native/src/util.rs +15 -55
  77. package/native/src/worker_pool.rs +53 -0
  78. package/package.json +10 -10
@@ -1,3 +1,4 @@
1
+ use std::sync::OnceLock;
1
2
  use tree_sitter::Language;
2
3
 
3
4
  /// Per-language node-type configuration mirroring src/languages.ts.
@@ -14,6 +15,9 @@ pub struct LanguageDefinition {
14
15
  pub nesting_node_types: &'static [&'static str],
15
16
  pub ncss_node_types: &'static [&'static str],
16
17
  pub ncss_container_node_types: &'static [&'static str],
18
+ /// Parents whose braceless `consequence`/`alternative`/`body` child counts like the single
19
+ /// statement of a braced body, for grammars that wrap it in no statement node.
20
+ pub ncss_bare_body_parent_node_types: &'static [&'static str],
17
21
  }
18
22
 
19
23
  #[derive(Clone, Copy)]
@@ -32,6 +36,8 @@ enum GrammarId {
32
36
  Tsx,
33
37
  }
34
38
 
39
+ const GRAMMAR_COUNT: usize = GrammarId::Tsx as usize + 1;
40
+
35
41
  impl LanguageDefinition {
36
42
  pub fn grammar(&self) -> Language {
37
43
  match self.grammar_id {
@@ -40,8 +46,8 @@ impl LanguageDefinition {
40
46
  GrammarId::CSharp => tree_sitter_c_sharp::language(),
41
47
  GrammarId::Go => tree_sitter_go::language(),
42
48
  GrammarId::Java => tree_sitter_java::language(),
43
- GrammarId::JavaScript => tree_sitter_javascript::language(),
44
- GrammarId::Kotlin => tree_sitter_kotlin::language(),
49
+ GrammarId::JavaScript => tree_sitter_javascript::LANGUAGE.into(),
50
+ GrammarId::Kotlin => tree_sitter_kotlin::LANGUAGE.into(),
45
51
  GrammarId::Python => tree_sitter_python::language(),
46
52
  GrammarId::Ruby => tree_sitter_ruby::language(),
47
53
  GrammarId::Rust => tree_sitter_rust::language(),
@@ -49,6 +55,23 @@ impl LanguageDefinition {
49
55
  GrammarId::Tsx => tree_sitter_typescript::language_tsx(),
50
56
  }
51
57
  }
58
+
59
+ /// The grammar's node kind names, indexed by kind id.
60
+ pub fn kind_names(&self) -> &'static [&'static str] {
61
+ static KIND_NAMES: [OnceLock<Vec<&'static str>>; GRAMMAR_COUNT] =
62
+ [const { OnceLock::new() }; GRAMMAR_COUNT];
63
+ KIND_NAMES[self.grammar_id as usize].get_or_init(|| {
64
+ let grammar = self.grammar();
65
+ (0..grammar.node_kind_count())
66
+ .map(|id| {
67
+ u16::try_from(id)
68
+ .ok()
69
+ .and_then(|id| grammar.node_kind_for_id(id))
70
+ .unwrap_or_default()
71
+ })
72
+ .collect()
73
+ })
74
+ }
52
75
  }
53
76
 
54
77
  const COMMON_FUNCTION_NODES: &[&str] = &[
@@ -641,16 +664,21 @@ const KOTLIN_NCSS_NODES: &[&str] = &[
641
664
  "getter",
642
665
  "setter",
643
666
  ];
644
- // `control_structure_body` holds a braceless branch/loop body (`if (x) foo()`), which counts like
645
- // the single statement of a braced one; `function_body` holds an expression body (`fun f() = x`).
667
+ // `function_body` holds an expression body (`fun f() = x`).
646
668
  const KOTLIN_NCSS_CONTAINERS: &[&str] = &[
647
669
  "source_file",
648
- "import_list",
649
- "statements",
670
+ "block",
650
671
  "class_body",
651
672
  "enum_class_body",
652
- "control_structure_body",
653
673
  "function_body",
674
+ "lambda_literal",
675
+ ];
676
+ const KOTLIN_NCSS_BARE_BODY_PARENTS: &[&str] = &[
677
+ "if_expression",
678
+ "for_statement",
679
+ "while_statement",
680
+ "do_while_statement",
681
+ "when_entry",
654
682
  ];
655
683
 
656
684
  pub const LANGUAGES: &[LanguageDefinition] = &[
@@ -664,6 +692,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
664
692
  nesting_node_types: COMMON_NESTING_NODES,
665
693
  ncss_node_types: JS_NCSS_NODES,
666
694
  ncss_container_node_types: &[],
695
+ ncss_bare_body_parent_node_types: &[],
667
696
  },
668
697
  LanguageDefinition {
669
698
  name: "jsx",
@@ -675,6 +704,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
675
704
  nesting_node_types: COMMON_NESTING_NODES,
676
705
  ncss_node_types: JS_NCSS_NODES,
677
706
  ncss_container_node_types: &[],
707
+ ncss_bare_body_parent_node_types: &[],
678
708
  },
679
709
  LanguageDefinition {
680
710
  name: "typescript",
@@ -686,6 +716,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
686
716
  nesting_node_types: COMMON_NESTING_NODES,
687
717
  ncss_node_types: JS_NCSS_NODES,
688
718
  ncss_container_node_types: &[],
719
+ ncss_bare_body_parent_node_types: &[],
689
720
  },
690
721
  LanguageDefinition {
691
722
  name: "tsx",
@@ -697,6 +728,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
697
728
  nesting_node_types: COMMON_NESTING_NODES,
698
729
  ncss_node_types: JS_NCSS_NODES,
699
730
  ncss_container_node_types: &[],
731
+ ncss_bare_body_parent_node_types: &[],
700
732
  },
701
733
  LanguageDefinition {
702
734
  name: "python",
@@ -708,6 +740,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
708
740
  nesting_node_types: COMMON_NESTING_NODES,
709
741
  ncss_node_types: PYTHON_NCSS_NODES,
710
742
  ncss_container_node_types: &[],
743
+ ncss_bare_body_parent_node_types: &[],
711
744
  },
712
745
  LanguageDefinition {
713
746
  name: "go",
@@ -719,6 +752,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
719
752
  nesting_node_types: GO_NESTING_NODES,
720
753
  ncss_node_types: GO_NCSS_NODES,
721
754
  ncss_container_node_types: &[],
755
+ ncss_bare_body_parent_node_types: &[],
722
756
  },
723
757
  LanguageDefinition {
724
758
  name: "rust",
@@ -730,6 +764,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
730
764
  nesting_node_types: COMMON_NESTING_NODES,
731
765
  ncss_node_types: RUST_NCSS_NODES,
732
766
  ncss_container_node_types: RUST_NCSS_CONTAINERS,
767
+ ncss_bare_body_parent_node_types: &[],
733
768
  },
734
769
  LanguageDefinition {
735
770
  name: "java",
@@ -741,6 +776,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
741
776
  nesting_node_types: JAVA_DECISION_NODES,
742
777
  ncss_node_types: JAVA_NCSS_NODES,
743
778
  ncss_container_node_types: &[],
779
+ ncss_bare_body_parent_node_types: &[],
744
780
  },
745
781
  LanguageDefinition {
746
782
  name: "ruby",
@@ -752,6 +788,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
752
788
  nesting_node_types: RUBY_DECISION_NODES,
753
789
  ncss_node_types: RUBY_NCSS_NODES,
754
790
  ncss_container_node_types: RUBY_NCSS_CONTAINERS,
791
+ ncss_bare_body_parent_node_types: &[],
755
792
  },
756
793
  LanguageDefinition {
757
794
  name: "c",
@@ -763,6 +800,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
763
800
  nesting_node_types: C_DECISION_NODES,
764
801
  ncss_node_types: C_NCSS_NODES,
765
802
  ncss_container_node_types: &[],
803
+ ncss_bare_body_parent_node_types: &[],
766
804
  },
767
805
  LanguageDefinition {
768
806
  name: "cpp",
@@ -774,6 +812,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
774
812
  nesting_node_types: CPP_DECISION_NODES,
775
813
  ncss_node_types: CPP_NCSS_NODES,
776
814
  ncss_container_node_types: &[],
815
+ ncss_bare_body_parent_node_types: &[],
777
816
  },
778
817
  LanguageDefinition {
779
818
  name: "csharp",
@@ -785,6 +824,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
785
824
  nesting_node_types: CSHARP_DECISION_NODES,
786
825
  ncss_node_types: CSHARP_NCSS_NODES,
787
826
  ncss_container_node_types: &[],
827
+ ncss_bare_body_parent_node_types: &[],
788
828
  },
789
829
  LanguageDefinition {
790
830
  name: "kotlin",
@@ -796,6 +836,7 @@ pub const LANGUAGES: &[LanguageDefinition] = &[
796
836
  nesting_node_types: KOTLIN_DECISION_NODES,
797
837
  ncss_node_types: KOTLIN_NCSS_NODES,
798
838
  ncss_container_node_types: KOTLIN_NCSS_CONTAINERS,
839
+ ncss_bare_body_parent_node_types: KOTLIN_NCSS_BARE_BODY_PARENTS,
799
840
  },
800
841
  ];
801
842
 
package/native/src/lib.rs CHANGED
@@ -12,18 +12,23 @@ mod measure;
12
12
  mod napi;
13
13
  mod ncss;
14
14
  mod near_miss;
15
+ mod tree_index;
15
16
  mod types;
16
17
  mod util;
17
18
  #[cfg(target_family = "wasm")]
18
19
  mod wasm;
20
+ #[cfg(not(target_family = "wasm"))]
21
+ mod worker_pool;
19
22
 
20
- /// Version of the native payload schema. The TypeScript wrapper refuses a binding whose version
21
- /// differs from the one it expects, so a stale prebuilt addon fails with a clear rebuild message
22
- /// instead of silently returning an incompatible payload. Bump on every payload-shape change,
23
- /// together with `expectedPayloadVersion` in src/nativeMetrics.ts.
23
+ /// Version of the native payload schema and binding functions. The TypeScript wrapper refuses a
24
+ /// binding whose version differs from the one it expects, so a stale prebuilt addon fails with a
25
+ /// clear rebuild message instead of silently returning an incompatible payload or lacking a
26
+ /// function (a failure the scan would only report per file). Bump on every payload-shape change
27
+ /// and every change to the exported binding functions, together with `expectedPayloadVersion` in
28
+ /// src/nativeMetrics.ts.
24
29
  /// scripts/installNative.mjs parses the literal from this function's source.
25
30
  pub fn payload_version() -> u32 {
26
- 7
31
+ 8
27
32
  }
28
33
 
29
34
  /// Measures code metrics for the given source, returning the NativeMetrics payload as JSON; with