dart-decimate 0.0.29 → 0.0.30

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 (70) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +36 -60
  4. package/npm/bin/runner.js +26 -14
  5. package/npm/scripts/postinstall.js +89 -63
  6. package/package.json +3 -2
  7. package/src/baseline.rs +38 -0
  8. package/src/cli/health_args.rs +36 -7
  9. package/src/cli/html_open.rs +4 -0
  10. package/src/cli/issue_filter_args.rs +1 -0
  11. package/src/cli/security_summary_run.rs +1 -0
  12. package/src/config/health.rs +22 -2
  13. package/src/config/rule_aliases.rs +43 -0
  14. package/src/config/rules.rs +46 -1
  15. package/src/config.rs +2 -1
  16. package/src/dart_parser/test_support.rs +51 -0
  17. package/src/dart_parser.rs +8 -0
  18. package/src/dependencies/analyze.rs +3 -1
  19. package/src/dependencies/tests.rs +111 -7
  20. package/src/dependencies/usage.rs +5 -1
  21. package/src/dependencies.rs +7 -3
  22. package/src/explain/flutter_style.rs +43 -0
  23. package/src/explain/misc.rs +72 -0
  24. package/src/explain.rs +23 -67
  25. package/src/flutter_style/scanner.rs +883 -0
  26. package/src/flutter_style/types.rs +90 -0
  27. package/src/flutter_style/usage.rs +349 -0
  28. package/src/flutter_style.rs +72 -0
  29. package/src/generated.rs +154 -0
  30. package/src/health/large_units.rs +49 -0
  31. package/src/health/tests.rs +212 -1
  32. package/src/health/threshold_types.rs +31 -1
  33. package/src/health/thresholds.rs +49 -0
  34. package/src/health/types.rs +35 -0
  35. package/src/health.rs +72 -6
  36. package/src/inspect.rs +8 -0
  37. package/src/lib.rs +17 -5
  38. package/src/manifest.rs +7 -3
  39. package/src/output/dependency_findings.rs +14 -1
  40. package/src/output/flutter_style.rs +189 -0
  41. package/src/output/health_findings.rs +93 -10
  42. package/src/output/health_inventory.rs +121 -0
  43. package/src/output/html/tests.rs +20 -0
  44. package/src/output/html.rs +10 -1
  45. package/src/output/human.rs +85 -1
  46. package/src/output/human_details.rs +93 -12
  47. package/src/output/scope.rs +62 -2
  48. package/src/output/security_findings.rs +101 -76
  49. package/src/output/security_sarif.rs +24 -13
  50. package/src/output/suppressions.rs +4 -0
  51. package/src/output/types.rs +38 -2
  52. package/src/output/verdict.rs +12 -0
  53. package/src/output.rs +77 -74
  54. package/src/report_schema/inventory.rs +268 -4
  55. package/src/report_schema.rs +94 -60
  56. package/src/security/catalogue.rs +103 -0
  57. package/src/security/detect/weak_randomness.rs +762 -0
  58. package/src/security/detect.rs +1535 -221
  59. package/src/security/security_matchers.toml +172 -0
  60. package/src/security/tests.rs +336 -2
  61. package/src/security.rs +292 -56
  62. package/src/security_gate.rs +28 -0
  63. package/src/semantic.rs +276 -0
  64. package/src/symbols/semantic_evidence.rs +342 -0
  65. package/src/symbols.rs +20 -10
  66. package/src/trace/rendering.rs +54 -0
  67. package/src/trace/semantic.rs +126 -0
  68. package/src/trace.rs +54 -62
  69. package/src/widgets/inheritance.rs +63 -0
  70. package/src/widgets.rs +33 -3
@@ -23,12 +23,15 @@ pub fn report_schema() -> Value {
23
23
  "findings",
24
24
  "clone_groups",
25
25
  "complexity",
26
+ "large_functions",
27
+ "flutter_style",
26
28
  "file_scores",
27
29
  "hotspots",
28
30
  "refactoring_targets",
29
31
  "threshold_overrides",
30
32
  "feature_flags",
31
33
  "security_candidates",
34
+ "security_blind_spots",
32
35
  "attack_surface",
33
36
  "next_steps"
34
37
  ],
@@ -45,12 +48,16 @@ pub fn report_schema() -> Value {
45
48
  },
46
49
  "clone_groups": array_ref_schema("clone_group"),
47
50
  "complexity": array_ref_schema("complexity_finding"),
51
+ "large_functions": array_ref_schema("large_function"),
52
+ "flutter_style": array_ref_schema("flutter_style_finding"),
53
+ "semantic": { "$ref": "#/$defs/semantic_report" },
48
54
  "file_scores": array_ref_schema("file_health_score"),
49
55
  "hotspots": array_ref_schema("health_hotspot"),
50
56
  "refactoring_targets": array_ref_schema("refactoring_target"),
51
57
  "threshold_overrides": threshold_overrides_schema(),
52
58
  "feature_flags": array_ref_schema("feature_flag"),
53
59
  "security_candidates": array_ref_schema("security_candidate"),
60
+ "security_blind_spots": array_ref_schema("security_blind_spot"),
54
61
  "attack_surface": array_ref_schema("attack_surface"),
55
62
  "runtime_coverage": { "$ref": "#/$defs/runtime_coverage" },
56
63
  "next_steps": {
@@ -69,6 +76,13 @@ pub fn report_schema() -> Value {
69
76
  "clone_instance": inventory::clone_instance_schema(),
70
77
  "complexity_finding": inventory::complexity_finding_schema(),
71
78
  "complexity_contribution": inventory::complexity_contribution_schema(),
79
+ "large_function": inventory::large_function_schema(),
80
+ "flutter_style_finding": inventory::flutter_style_finding_schema(),
81
+ "theme_token_evidence": inventory::theme_token_evidence_schema(),
82
+ "semantic_report": inventory::semantic_report_schema(),
83
+ "semantic_identity": inventory::semantic_identity_schema(),
84
+ "semantic_evidence": inventory::semantic_evidence_schema(),
85
+ "semantic_type_coupling": inventory::semantic_type_coupling_schema(),
72
86
  "effective_thresholds": inventory::effective_thresholds_schema(),
73
87
  "file_health_score": inventory::file_health_score_schema(),
74
88
  "health_hotspot": inventory::health_hotspot_schema(),
@@ -77,6 +91,7 @@ pub fn report_schema() -> Value {
77
91
  "feature_flag_occurrence": inventory::feature_flag_occurrence_schema(),
78
92
  "security_candidate": inventory::security_candidate_schema(),
79
93
  "security_occurrence": inventory::security_occurrence_schema(),
94
+ "security_blind_spot": inventory::security_blind_spot_schema(),
80
95
  "attack_surface": inventory::attack_surface_schema(),
81
96
  "runtime_coverage": runtime_coverage_schema(),
82
97
  "threshold_override": threshold_override_schema(),
@@ -111,68 +126,81 @@ fn kind_values() -> Value {
111
126
  ])
112
127
  }
113
128
 
129
+ const SUMMARY_INTEGER_FIELDS: &[&str] = &[
130
+ "files",
131
+ "edges",
132
+ "unresolved_dependencies",
133
+ "part_of_violations",
134
+ "unused_dependencies",
135
+ "unused_dev_dependencies",
136
+ "dev_dependencies_in_production",
137
+ "test_only_dependencies",
138
+ "dependency_overrides",
139
+ "unused_dependency_overrides",
140
+ "misconfigured_dependency_overrides",
141
+ "unlisted_dependencies",
142
+ "private_src_imports",
143
+ "dead_files",
144
+ "unused_exports",
145
+ "unused_types",
146
+ "private_type_leaks",
147
+ "unused_enum_members",
148
+ "unused_class_members",
149
+ "duplicate_exports",
150
+ "route_collisions",
151
+ "mixed_go_router_styles",
152
+ "private_widget_classes",
153
+ "widget_top_level_functions",
154
+ "unused_widget_params",
155
+ "unrendered_widgets",
156
+ "missing_context_mounted_after_await",
157
+ "code_duplications",
158
+ "duplication_analyzed_lines",
159
+ "duplicated_lines",
160
+ "duplication_percentage_basis_points",
161
+ "quality_score",
162
+ "health_files",
163
+ "functions",
164
+ "complex_functions",
165
+ "large_functions",
166
+ "raw_flutter_style_values",
167
+ "near_duplicate_theme_tokens",
168
+ "unused_theme_extension_tokens",
169
+ "semantic_evidence",
170
+ "type_couplings",
171
+ "max_cyclomatic_complexity",
172
+ "max_cognitive_complexity",
173
+ "coverage_files",
174
+ "coverage_gaps",
175
+ "crap_functions",
176
+ "max_crap_score",
177
+ "file_scores",
178
+ "hotspots",
179
+ "refactoring_targets",
180
+ "feature_flags",
181
+ "feature_flag_occurrences",
182
+ "security_candidates",
183
+ "security_candidate_occurrences",
184
+ "security_blind_spots",
185
+ "attack_surface",
186
+ "missing_entry_points",
187
+ "cycles",
188
+ "re_export_cycles",
189
+ "boundary_violations",
190
+ "boundary_coverage",
191
+ "boundary_call_violations",
192
+ "policy_violations",
193
+ "missing_suppression_reasons",
194
+ "findings",
195
+ ];
196
+
114
197
  fn summary_schema() -> Value {
115
198
  let mut properties = serde_json::Map::new();
116
- for key in [
117
- "files",
118
- "edges",
119
- "unresolved_dependencies",
120
- "part_of_violations",
121
- "unused_dependencies",
122
- "unused_dev_dependencies",
123
- "test_only_dependencies",
124
- "dependency_overrides",
125
- "unused_dependency_overrides",
126
- "misconfigured_dependency_overrides",
127
- "unlisted_dependencies",
128
- "private_src_imports",
129
- "dead_files",
130
- "unused_exports",
131
- "unused_types",
132
- "private_type_leaks",
133
- "unused_enum_members",
134
- "unused_class_members",
135
- "duplicate_exports",
136
- "route_collisions",
137
- "mixed_go_router_styles",
138
- "private_widget_classes",
139
- "widget_top_level_functions",
140
- "unused_widget_params",
141
- "unrendered_widgets",
142
- "missing_context_mounted_after_await",
143
- "code_duplications",
144
- "duplication_analyzed_lines",
145
- "duplicated_lines",
146
- "duplication_percentage_basis_points",
147
- "quality_score",
148
- "health_files",
149
- "functions",
150
- "complex_functions",
151
- "max_cyclomatic_complexity",
152
- "max_cognitive_complexity",
153
- "coverage_files",
154
- "coverage_gaps",
155
- "crap_functions",
156
- "max_crap_score",
157
- "file_scores",
158
- "hotspots",
159
- "refactoring_targets",
160
- "feature_flags",
161
- "feature_flag_occurrences",
162
- "security_candidates",
163
- "security_candidate_occurrences",
164
- "attack_surface",
165
- "missing_entry_points",
166
- "cycles",
167
- "re_export_cycles",
168
- "boundary_violations",
169
- "boundary_coverage",
170
- "boundary_call_violations",
171
- "policy_violations",
172
- "missing_suppression_reasons",
173
- "findings",
174
- ] {
175
- properties.insert(key.to_owned(), json!({ "type": "integer", "minimum": 0 }));
199
+ for key in SUMMARY_INTEGER_FIELDS {
200
+ properties.insert(
201
+ (*key).to_owned(),
202
+ json!({ "type": "integer", "minimum": 0 }),
203
+ );
176
204
  }
177
205
  properties.insert(
178
206
  "risk_score".to_owned(),
@@ -317,6 +345,7 @@ fn finding_kind_values() -> Value {
317
345
  "part-of-violation",
318
346
  "unused-dependency",
319
347
  "unused-dev-dependency",
348
+ "dev-dependency-in-production",
320
349
  "test-only-dependency",
321
350
  "unused-dependency-override",
322
351
  "misconfigured-dependency-override",
@@ -330,6 +359,9 @@ fn finding_kind_values() -> Value {
330
359
  "high-crap-score",
331
360
  "health-hotspot",
332
361
  "refactoring-target",
362
+ "raw-flutter-style-value",
363
+ "near-duplicate-theme-token",
364
+ "unused-theme-extension-token",
333
365
  "feature-flag",
334
366
  "security-candidate",
335
367
  "stale-suppression",
@@ -443,6 +475,7 @@ fn threshold_override_schema() -> Value {
443
475
  "max_cyclomatic",
444
476
  "max_cognitive",
445
477
  "max_crap",
478
+ "max_unit_size",
446
479
  "reason",
447
480
  "active",
448
481
  "stale",
@@ -456,6 +489,7 @@ fn threshold_override_schema() -> Value {
456
489
  "max_cyclomatic": { "type": ["integer", "null"], "minimum": 1 },
457
490
  "max_cognitive": { "type": ["integer", "null"], "minimum": 1 },
458
491
  "max_crap": { "type": ["integer", "null"], "minimum": 1 },
492
+ "max_unit_size": { "type": ["integer", "null"], "minimum": 1 },
459
493
  "reason": { "type": ["string", "null"] },
460
494
  "active": { "type": "boolean" },
461
495
  "stale": { "type": "boolean" },
@@ -0,0 +1,103 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ use super::{SecurityCategory, SecurityError};
4
+
5
+ const MATCHERS_TOML: &str = include_str!("security_matchers.toml");
6
+
7
+ #[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
8
+ pub(super) struct MatcherCatalogue {
9
+ pub(super) version: usize,
10
+ pub(super) matchers: Vec<SecurityMatcher>,
11
+ }
12
+
13
+ #[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
14
+ pub(super) struct SecurityMatcher {
15
+ pub(super) category: SecurityCategory,
16
+ pub(super) rule_id: String,
17
+ pub(super) detector: String,
18
+ pub(super) sink_shape: String,
19
+ pub(super) argument_index: usize,
20
+ pub(super) literal_predicate: String,
21
+ pub(super) context_predicate: String,
22
+ pub(super) import_provenance: String,
23
+ pub(super) callees: Vec<String>,
24
+ pub(super) cwe: Vec<String>,
25
+ pub(super) effect: String,
26
+ pub(super) evidence_template: String,
27
+ pub(super) source: String,
28
+ pub(super) boundary: String,
29
+ pub(super) trace_role: String,
30
+ pub(super) default_severity: SecurityDefaultSeverity,
31
+ pub(super) verification_prompt: String,
32
+ }
33
+
34
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
35
+ #[serde(rename_all = "kebab-case")]
36
+ pub enum SecurityDefaultSeverity {
37
+ Warning,
38
+ Error,
39
+ }
40
+
41
+ impl MatcherCatalogue {
42
+ pub(super) fn parse() -> Result<Self, SecurityError> {
43
+ let catalogue =
44
+ toml::from_str::<Self>(MATCHERS_TOML).map_err(SecurityError::MatcherCatalogue)?;
45
+ catalogue.validate()?;
46
+ Ok(catalogue)
47
+ }
48
+
49
+ pub(super) fn matcher(&self, category: SecurityCategory) -> &SecurityMatcher {
50
+ self.matchers
51
+ .iter()
52
+ .find(|matcher| matcher.category == category)
53
+ .unwrap_or_else(|| unreachable!("validated matcher catalogue covers every category"))
54
+ }
55
+
56
+ pub(super) fn by_detector(&self, detector: &str) -> &SecurityMatcher {
57
+ self.matchers
58
+ .iter()
59
+ .find(|matcher| matcher.detector == detector)
60
+ .unwrap_or_else(|| unreachable!("validated matcher catalogue covers every detector"))
61
+ }
62
+
63
+ fn validate(&self) -> Result<(), SecurityError> {
64
+ if self.version != 1 {
65
+ return Err(SecurityError::InvalidMatcherCatalogue(format!(
66
+ "unsupported version {}",
67
+ self.version
68
+ )));
69
+ }
70
+ for category in SecurityCategory::ALL {
71
+ let matches = self
72
+ .matchers
73
+ .iter()
74
+ .filter(|matcher| matcher.category == category)
75
+ .count();
76
+ if matches != 1 {
77
+ return Err(SecurityError::InvalidMatcherCatalogue(format!(
78
+ "expected one matcher for {category:?}, found {matches}"
79
+ )));
80
+ }
81
+ }
82
+ for matcher in &self.matchers {
83
+ if matcher.rule_id.is_empty()
84
+ || matcher.cwe.is_empty()
85
+ || matcher.effect.is_empty()
86
+ || matcher.evidence_template.is_empty()
87
+ || matcher.source.is_empty()
88
+ || matcher.boundary.is_empty()
89
+ || matcher.trace_role.is_empty()
90
+ || matcher.sink_shape.is_empty()
91
+ || matcher.literal_predicate.is_empty()
92
+ || matcher.context_predicate.is_empty()
93
+ || matcher.import_provenance.is_empty()
94
+ {
95
+ return Err(SecurityError::InvalidMatcherCatalogue(format!(
96
+ "matcher {} has an empty contract field",
97
+ matcher.detector
98
+ )));
99
+ }
100
+ }
101
+ Ok(())
102
+ }
103
+ }