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.
- package/README.md +1 -1
- package/THIRD-PARTY-NOTICES.txt +595 -29
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cliConfig.cjs +1 -1
- package/dist/cliConfig.cjs.map +1 -1
- package/dist/cliConfig.js +1 -1
- package/dist/cliConfig.js.map +1 -1
- package/dist/crossFileDuplication.cjs +1 -1
- package/dist/crossFileDuplication.cjs.map +1 -1
- package/dist/crossFileDuplication.js +1 -1
- package/dist/crossFileDuplication.js.map +1 -1
- package/dist/crossFileNearMiss.cjs +1 -1
- package/dist/crossFileNearMiss.cjs.map +1 -1
- package/dist/crossFileNearMiss.js +1 -1
- package/dist/crossFileNearMiss.js.map +1 -1
- package/dist/diffCommand.cjs +3 -3
- package/dist/diffCommand.cjs.map +1 -1
- package/dist/diffCommand.js +3 -3
- package/dist/diffCommand.js.map +1 -1
- package/dist/duplicateSelection.cjs +1 -1
- package/dist/duplicateSelection.cjs.map +1 -1
- package/dist/duplicateSelection.js +1 -1
- package/dist/duplicateSelection.js.map +1 -1
- package/dist/duplication.cjs +1 -1
- package/dist/duplication.cjs.map +1 -1
- package/dist/duplication.js +1 -1
- package/dist/duplication.js.map +1 -1
- package/dist/git.cjs +1 -1
- package/dist/git.cjs.map +1 -1
- package/dist/git.js +1 -1
- package/dist/git.js.map +1 -1
- package/dist/languages.cjs +1 -1
- package/dist/languages.cjs.map +1 -1
- package/dist/languages.js +1 -1
- package/dist/languages.js.map +1 -1
- package/dist/metrics.cjs +1 -1
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.ts +8 -3
- package/dist/metrics.js +1 -1
- package/dist/metrics.js.map +1 -1
- package/dist/nativeMetrics.cjs +3 -3
- package/dist/nativeMetrics.cjs.map +1 -1
- package/dist/nativeMetrics.d.ts +19 -3
- package/dist/nativeMetrics.js +3 -3
- package/dist/nativeMetrics.js.map +1 -1
- package/dist/regressionGate.cjs +1 -1
- package/dist/regressionGate.cjs.map +1 -1
- package/dist/regressionGate.js +1 -1
- package/dist/regressionGate.js.map +1 -1
- package/dist/scan.cjs +1 -1
- package/dist/scan.cjs.map +1 -1
- package/dist/scan.d.ts +2 -2
- package/dist/scan.js +1 -1
- package/dist/scan.js.map +1 -1
- package/dist/wasmBinding.cjs +1 -1
- package/dist/wasmBinding.cjs.map +1 -1
- package/dist/wasmBinding.js +1 -1
- package/dist/wasmBinding.js.map +1 -1
- package/native/Cargo.lock +48 -15
- package/native/Cargo.toml +11 -10
- package/native/code-gauge.wasm +0 -0
- package/native/src/complexity.rs +152 -255
- package/native/src/dep_degree.rs +79 -65
- package/native/src/duplication.rs +114 -97
- package/native/src/functions.rs +181 -206
- package/native/src/languages.rs +48 -7
- package/native/src/lib.rs +10 -5
- package/native/src/measure.rs +125 -150
- package/native/src/napi.rs +61 -2
- package/native/src/ncss.rs +108 -104
- package/native/src/near_miss.rs +7 -7
- package/native/src/tree_index.rs +119 -0
- package/native/src/util.rs +15 -55
- package/native/src/worker_pool.rs +53 -0
- package/package.json +10 -10
package/native/src/languages.rs
CHANGED
|
@@ -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::
|
|
44
|
-
GrammarId::Kotlin => tree_sitter_kotlin::
|
|
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
|
-
// `
|
|
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
|
-
"
|
|
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
|
|
21
|
-
/// differs from the one it expects, so a stale prebuilt addon fails with a
|
|
22
|
-
/// instead of silently returning an incompatible payload
|
|
23
|
-
///
|
|
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
|
-
|
|
31
|
+
8
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
/// Measures code metrics for the given source, returning the NativeMetrics payload as JSON; with
|