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
@@ -19,6 +19,8 @@ pub struct HealthOptions {
19
19
  pub max_cyclomatic: usize,
20
20
  /// Maximum cognitive complexity before reporting.
21
21
  pub max_cognitive: usize,
22
+ /// Maximum inclusive physical lines in one function-like declaration.
23
+ pub max_unit_size: usize,
22
24
  /// Limit output to the N highest complexity findings.
23
25
  pub top: Option<usize>,
24
26
  /// Include per-decision-point contribution records.
@@ -45,6 +47,8 @@ pub struct HealthOptions {
45
47
  pub targets: HealthToggle,
46
48
  /// Attach CODEOWNERS ownership metadata to health inventories.
47
49
  pub ownership: HealthToggle,
50
+ /// Include advisory Flutter theme/style analysis.
51
+ pub flutter_style: HealthToggle,
48
52
  /// Minimum file health score before hotspot reporting.
49
53
  pub min_score: usize,
50
54
  /// Per-file/function local complexity ceilings.
@@ -56,6 +60,7 @@ impl Default for HealthOptions {
56
60
  Self {
57
61
  max_cyclomatic: 20,
58
62
  max_cognitive: 15,
63
+ max_unit_size: 60,
59
64
  top: None,
60
65
  complexity_breakdown: HealthToggle::Off,
61
66
  coverage_path: None,
@@ -69,6 +74,7 @@ impl Default for HealthOptions {
69
74
  hotspots: HealthToggle::Off,
70
75
  targets: HealthToggle::Off,
71
76
  ownership: HealthToggle::Off,
77
+ flutter_style: HealthToggle::Off,
72
78
  min_score: 70,
73
79
  threshold_overrides: Vec::new(),
74
80
  }
@@ -203,6 +209,10 @@ pub struct HealthReport {
203
209
  pub max_crap_score: usize,
204
210
  /// Functions exceeding configured thresholds.
205
211
  pub complexity: Vec<ComplexityFinding>,
212
+ /// Function-like declarations exceeding the effective unit-size threshold.
213
+ pub large_functions: Vec<LargeFunction>,
214
+ /// Opt-in advisory Flutter style analysis.
215
+ pub flutter_style: Option<crate::FlutterStyleReport>,
206
216
  /// Source files with no covered executable lines.
207
217
  pub coverage_gaps: Vec<CoverageGapFinding>,
208
218
  /// Functions exceeding configured CRAP threshold.
@@ -524,6 +534,8 @@ pub enum ComplexityFunctionKind {
524
534
  Setter,
525
535
  /// Class, mixin, extension, or enum method.
526
536
  Method,
537
+ /// `build` method owned by a syntactically identified Flutter widget or `State`.
538
+ FlutterBuildMethod,
527
539
  /// Constructor or factory constructor.
528
540
  Constructor,
529
541
  /// Operator overload.
@@ -532,6 +544,29 @@ pub enum ComplexityFunctionKind {
532
544
  Closure,
533
545
  }
534
546
 
547
+ /// Advisory record for one function-like declaration above its unit-size threshold.
548
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
549
+ pub struct LargeFunction {
550
+ /// Dart file path.
551
+ pub path: PathBuf,
552
+ /// Function-like declaration name.
553
+ pub symbol: String,
554
+ /// Function-like declaration kind.
555
+ pub kind: ComplexityFunctionKind,
556
+ /// Location of the declaration.
557
+ pub location: Location,
558
+ /// Inclusive 1-based ending line.
559
+ pub end_line: usize,
560
+ /// Inclusive physical line count.
561
+ pub line_count: usize,
562
+ /// Effective unit-size ceiling.
563
+ pub max_unit_size: usize,
564
+ /// Source of the effective threshold when overridden.
565
+ pub threshold_source: Option<ThresholdSource>,
566
+ /// Configured reason for the threshold override.
567
+ pub threshold_reason: Option<String>,
568
+ }
569
+
535
570
  /// Complexity threshold rule exceeded by a function.
536
571
  #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
537
572
  #[serde(rename_all = "kebab-case")]
package/src/health.rs CHANGED
@@ -1,3 +1,4 @@
1
+ use std::collections::BTreeSet;
1
2
  use std::fs;
2
3
  use std::path::{Path, PathBuf};
3
4
 
@@ -8,6 +9,7 @@ use crate::graph::normalize_against;
8
9
  use crate::{Location, ScannedProject};
9
10
 
10
11
  mod coverage;
12
+ mod large_units;
11
13
  mod ownership;
12
14
  mod runtime_coverage;
13
15
  mod runtime_intelligence;
@@ -16,6 +18,7 @@ mod threshold_types;
16
18
  mod thresholds;
17
19
  mod types;
18
20
  use coverage::{CoverageMap, coverage_gap_findings, crap_findings, load_lcov};
21
+ use large_units::large_functions;
19
22
  use runtime_coverage::load_runtime_coverage;
20
23
  pub use runtime_intelligence::{
21
24
  RuntimeBlastRadius, RuntimeBlastRisk, RuntimeCoverageAction, RuntimeCoverageIntelligence,
@@ -31,8 +34,8 @@ use thresholds::ThresholdContext;
31
34
  pub use types::{
32
35
  ComplexityContribution, ComplexityFinding, ComplexityFunctionKind, ComplexityRule,
33
36
  CoverageGapFinding, CoverageGapReason, CrapFinding, FileCoverageStatus, FileHealthScore,
34
- HealthError, HealthHotspot, HealthOptions, HealthReport, HealthToggle, LowTrafficThreshold,
35
- RefactoringTarget, RuntimeCoverageConfidence, RuntimeCoverageFinding,
37
+ HealthError, HealthHotspot, HealthOptions, HealthReport, HealthToggle, LargeFunction,
38
+ LowTrafficThreshold, RefactoringTarget, RuntimeCoverageConfidence, RuntimeCoverageFinding,
36
39
  RuntimeCoverageFindingKind, RuntimeCoverageFormat, RuntimeCoverageReport, RuntimeHotPath,
37
40
  SourceMapConfidence,
38
41
  };
@@ -42,6 +45,7 @@ struct FunctionMetrics {
42
45
  pub(super) path: PathBuf,
43
46
  pub(super) symbol: String,
44
47
  pub(super) kind: ComplexityFunctionKind,
48
+ owner_class: Option<String>,
45
49
  pub(super) location: Location,
46
50
  pub(super) end_line: usize,
47
51
  pub(super) cyclomatic: usize,
@@ -71,6 +75,12 @@ pub fn analyze_health(
71
75
  let runtime_coverage = load_runtime_coverage(project, options, &functions)?;
72
76
  let coverage_files = coverage.as_ref().map_or(0, CoverageMap::file_count);
73
77
  let complexity = complexity_findings(&functions, options, &mut threshold_context);
78
+ let large_functions = large_functions(&functions, &mut threshold_context);
79
+ let flutter_style = options
80
+ .flutter_style
81
+ .is_enabled()
82
+ .then(|| crate::analyze_flutter_style(project))
83
+ .transpose()?;
74
84
  let coverage_gaps = coverage
75
85
  .as_ref()
76
86
  .filter(|_| options.coverage_gaps.is_enabled())
@@ -123,6 +133,8 @@ pub fn analyze_health(
123
133
  coverage_files,
124
134
  max_crap_score: max_crap_score(&crap),
125
135
  complexity,
136
+ large_functions,
137
+ flutter_style,
126
138
  coverage_gaps,
127
139
  crap,
128
140
  threshold_overrides,
@@ -137,6 +149,10 @@ fn collect_project_functions(
137
149
  project: &ScannedProject,
138
150
  ) -> Result<(Vec<FunctionMetrics>, usize), HealthError> {
139
151
  let mut functions = Vec::new();
152
+ let mut widget_facts = Vec::new();
153
+ let mut widget_paths = crate::widgets::widget_analysis_paths(project, None)
154
+ .into_iter()
155
+ .collect::<BTreeSet<_>>();
140
156
  let mut analyzed_files = 0;
141
157
  for file in &project.files {
142
158
  let path = normalize_against(&project.root, &file.path);
@@ -150,13 +166,32 @@ fn collect_project_functions(
150
166
  })?;
151
167
  let parsed = crate::dart_parser::parse_dart_source_lossy(&path, &source)
152
168
  .map_err(health_parse_error)?;
153
- collect_functions(
169
+ let root = parsed.tree().root_node();
170
+ if widget_paths.remove(&path) {
171
+ widget_facts.push(crate::widgets::inheritance_file_facts(
172
+ &path,
173
+ root,
174
+ parsed.source(),
175
+ ));
176
+ }
177
+ collect_functions(root, parsed.source(), &path, &mut functions);
178
+ }
179
+ for path in widget_paths {
180
+ let source = fs::read_to_string(&path).map_err(|source| HealthError::ReadFile {
181
+ path: path.clone(),
182
+ source,
183
+ })?;
184
+ let parsed = crate::dart_parser::parse_dart_source_lossy(&path, &source)
185
+ .map_err(health_parse_error)?;
186
+ widget_facts.push(crate::widgets::inheritance_file_facts(
187
+ &path,
154
188
  parsed.tree().root_node(),
155
189
  parsed.source(),
156
- &path,
157
- &mut functions,
158
- );
190
+ ));
159
191
  }
192
+ let flutter_classes =
193
+ crate::widgets::flutter_framework_classes_from_facts(project, &widget_facts);
194
+ classify_flutter_build_methods(&mut functions, &flutter_classes);
160
195
 
161
196
  Ok((functions, analyzed_files))
162
197
  }
@@ -289,12 +324,16 @@ fn function_from_node(node: Node<'_>, source: &str, path: &Path) -> Option<Funct
289
324
  ),
290
325
  _ => return None,
291
326
  };
327
+ let owner_class = (symbol == "build" && kind == ComplexityFunctionKind::Method)
328
+ .then(|| enclosing_class_name(node, source))
329
+ .flatten();
292
330
 
293
331
  let state = score_body(body);
294
332
  Some(FunctionMetrics {
295
333
  path: path.to_path_buf(),
296
334
  symbol,
297
335
  kind,
336
+ owner_class,
298
337
  location: node.start_position().into(),
299
338
  end_line: node.end_position().row + 1,
300
339
  cyclomatic: state.cyclomatic,
@@ -303,6 +342,33 @@ fn function_from_node(node: Node<'_>, source: &str, path: &Path) -> Option<Funct
303
342
  })
304
343
  }
305
344
 
345
+ fn enclosing_class_name(node: Node<'_>, source: &str) -> Option<String> {
346
+ let mut ancestor = node.parent();
347
+ while let Some(candidate) = ancestor {
348
+ if candidate.kind() == "class_declaration" {
349
+ return field_text(candidate, "name", source);
350
+ }
351
+ ancestor = candidate.parent();
352
+ }
353
+ None
354
+ }
355
+
356
+ fn classify_flutter_build_methods(
357
+ functions: &mut [FunctionMetrics],
358
+ flutter_classes: &BTreeSet<(PathBuf, String)>,
359
+ ) {
360
+ for function in functions {
361
+ if function.symbol == "build"
362
+ && function.kind == ComplexityFunctionKind::Method
363
+ && function.owner_class.as_ref().is_some_and(|owner| {
364
+ flutter_classes.contains(&(function.path.clone(), owner.clone()))
365
+ })
366
+ {
367
+ function.kind = ComplexityFunctionKind::FlutterBuildMethod;
368
+ }
369
+ }
370
+ }
371
+
306
372
  fn named_function<'tree>(
307
373
  node: Node<'tree>,
308
374
  source: &str,
package/src/inspect.rs CHANGED
@@ -122,6 +122,14 @@ pub fn render_inspect_report(report: &InspectReport) -> String {
122
122
  );
123
123
  let _ = writeln!(rendered, "{}", report.file_trace.reason);
124
124
  if let Some(symbol_trace) = &report.symbol_trace {
125
+ let _ = writeln!(
126
+ rendered,
127
+ "semantic={} completeness={} impact_paths={} suggested_tests={}",
128
+ symbol_trace.semantic_decision.as_str(),
129
+ symbol_trace.completeness.status.as_str(),
130
+ symbol_trace.impact_paths.len(),
131
+ symbol_trace.suggested_tests.len()
132
+ );
125
133
  let _ = writeln!(rendered, "{}", symbol_trace.reason);
126
134
  }
127
135
  rendered
package/src/lib.rs CHANGED
@@ -22,6 +22,7 @@ pub mod extract;
22
22
  pub mod feature_flags;
23
23
  pub(crate) mod finding_identity;
24
24
  pub mod fix;
25
+ pub mod flutter_style;
25
26
  pub(crate) mod generated;
26
27
  pub(crate) mod git_command;
27
28
  pub mod graph;
@@ -42,6 +43,7 @@ pub mod routes;
42
43
  pub mod scan;
43
44
  pub mod security;
44
45
  pub(crate) mod security_gate;
46
+ pub mod semantic;
45
47
  pub mod symbols;
46
48
  pub mod trace;
47
49
  pub mod unsupported;
@@ -109,6 +111,10 @@ pub use fix::{
109
111
  FIX_SCHEMA_VERSION, FixChange, FixMode, FixReport, FixSkip, FixSummary, fix_findings,
110
112
  render_fix_report,
111
113
  };
114
+ pub use flutter_style::{
115
+ FlutterStyleFinding, FlutterStyleFindingKind, FlutterStyleReport, FlutterStyleValueKind,
116
+ ThemeTokenEvidence, analyze_flutter_style,
117
+ };
112
118
  pub use graph::{
113
119
  DependencyEdge, DependencyKind, DependencyVisibility, GraphError, GraphOptions,
114
120
  InvalidPartReason, InvalidPartRelationship, ModuleGraph, ModuleNode, ResolvedDependency,
@@ -119,8 +125,8 @@ pub use health::{
119
125
  CoverageGapFinding, CoverageGapReason, CrapFinding, EffectiveThresholds, FileCoverageStatus,
120
126
  FileHealthScore, HealthError, HealthHotspot, HealthOptions, HealthReport,
121
127
  HealthThresholdOverride, HealthThresholdOverrideReport, HealthThresholdOverrideStatus,
122
- HealthToggle, LowTrafficThreshold, RefactoringTarget, RuntimeBlastRadius, RuntimeBlastRisk,
123
- RuntimeCoverageAction, RuntimeCoverageConfidence, RuntimeCoverageFinding,
128
+ HealthToggle, LargeFunction, LowTrafficThreshold, RefactoringTarget, RuntimeBlastRadius,
129
+ RuntimeBlastRisk, RuntimeCoverageAction, RuntimeCoverageConfidence, RuntimeCoverageFinding,
124
130
  RuntimeCoverageFindingKind, RuntimeCoverageFormat, RuntimeCoverageIntelligence,
125
131
  RuntimeCoverageIntelligenceKind, RuntimeCoverageReport, RuntimeHotPath, RuntimeImportance,
126
132
  SourceMapConfidence, ThresholdSource, analyze_health,
@@ -176,10 +182,15 @@ pub use routes::{
176
182
  };
177
183
  pub use scan::{ScanError, ScanOptions, ScannedProject, scan_project, scan_project_with_options};
178
184
  pub use security::{
179
- AttackSurfaceEntry, SecurityCandidate, SecurityCategory, SecurityConfidence, SecurityError,
185
+ AttackSurfaceEntry, SecurityBlindSpot, SecurityBlindSpotReason, SecurityCandidate,
186
+ SecurityCategory, SecurityConfidence, SecurityDefaultSeverity, SecurityError,
180
187
  SecurityOccurrence, SecurityOptions, SecurityReachability, SecurityReport,
181
188
  SecurityTaintConfidence, analyze_security,
182
189
  };
190
+ pub use semantic::{
191
+ SemanticCompleteness, SemanticDecision, SemanticEvidence, SemanticIdentity,
192
+ SemanticOmissionReason, SemanticReport, SemanticTypeCoupling,
193
+ };
183
194
  pub use symbols::{
184
195
  DuplicateExport, DuplicateExportDeclaration, PrivateTypeLeak, SymbolAnalysisOptions,
185
196
  SymbolIndex, SymbolReport, UnusedExport, UnusedMember, analyze_symbols,
@@ -187,8 +198,9 @@ pub use symbols::{
187
198
  };
188
199
  pub use trace::{
189
200
  DependencyTraceReport, FileTraceReport, SymbolTraceReport, TraceDeclaration, TraceDependency,
190
- TraceDependencyDirective, TracePubspecDependency, TraceReference, render_dependency_trace,
191
- render_file_trace, render_symbol_trace, trace_dependency, trace_file, trace_symbol,
201
+ TraceDependencyDirective, TraceImpactPath, TracePubspecDependency, TraceReference,
202
+ TraceSemanticCompleteness, TraceTestSuggestion, render_dependency_trace, render_file_trace,
203
+ render_symbol_trace, trace_dependency, trace_file, trace_symbol,
192
204
  };
193
205
  pub use widgets::{
194
206
  MissingContextMountedAfterAwait, PrivateWidgetClass, UnrenderedWidgetClass, UnusedWidgetParam,
package/src/manifest.rs CHANGED
@@ -147,14 +147,14 @@ fn analysis_commands() -> Value {
147
147
  "kind": "combined",
148
148
  "description": "Run all enabled graph, symbol, dependency, duplicate, health, flag, and security checks.",
149
149
  "schema": SCHEMA_VERSION,
150
- "flags": ["--root", "--format", "--open", "--config", "--entry", "--dart-platform", "--production", "--no-production", "--file", "--workspace", "--changed-workspaces", "--changed-since", "--compare", "--regression-baseline", "--save-regression-baseline", "--fail-on-regression", "--tolerance", "--baseline", "--save-baseline", "--boundary", "--boundary-coverage", "--boundary-call", "--policy-pack", "--policy-violations", "--max-cyclomatic", "--max-cognitive", "--complexity-breakdown", "--coverage", "--coverage-gaps", "--max-crap", "--runtime-coverage", "--min-invocations-hot", "--min-observation-volume", "--low-traffic-threshold", "--file-scores", "--hotspots", "--targets", "--ownership", "--min-score", "--mode", "--min-tokens", "--min-lines", "--min-occurrences", "--top", "--threshold", "--cross-language", "--skip-local", "--ignore-imports", "--no-ignore-imports", "--include-entry-exports", "--private-type-leaks", "--unused-files", "--unused-exports", "--unused-types", "--unused-deps", "--unlisted-deps", "--private-src-imports", "--duplicate-exports", "--circular-deps", "--re-export-cycles", "--boundary-violations", "--unused-enum-members", "--unused-class-members", "--unresolved-imports", "--stale-suppressions", "--unused-dependency-overrides", "--misconfigured-dependency-overrides"]
150
+ "flags": ["--root", "--format", "--open", "--config", "--entry", "--dart-platform", "--production", "--no-production", "--file", "--workspace", "--changed-workspaces", "--changed-since", "--compare", "--regression-baseline", "--save-regression-baseline", "--fail-on-regression", "--tolerance", "--baseline", "--save-baseline", "--boundary", "--boundary-coverage", "--boundary-call", "--policy-pack", "--policy-violations", "--max-cyclomatic", "--max-cognitive", "--max-unit-size", "--complexity-breakdown", "--coverage", "--coverage-gaps", "--max-crap", "--runtime-coverage", "--min-invocations-hot", "--min-observation-volume", "--low-traffic-threshold", "--file-scores", "--hotspots", "--targets", "--ownership", "--min-score", "--mode", "--min-tokens", "--min-lines", "--min-occurrences", "--top", "--threshold", "--cross-language", "--skip-local", "--ignore-imports", "--no-ignore-imports", "--include-entry-exports", "--private-type-leaks", "--unused-files", "--unused-exports", "--unused-types", "--unused-deps", "--unlisted-deps", "--private-src-imports", "--duplicate-exports", "--circular-deps", "--re-export-cycles", "--boundary-violations", "--unused-enum-members", "--unused-class-members", "--unresolved-imports", "--stale-suppressions", "--unused-dependency-overrides", "--misconfigured-dependency-overrides"]
151
151
  },
152
152
  {
153
153
  "name": "audit",
154
154
  "kind": "audit",
155
155
  "description": "Run changed-code graph checks scoped from a Git base ref.",
156
156
  "schema": SCHEMA_VERSION,
157
- "flags": ["--root", "--brief", "--base", "--gate", "--dead-code-baseline", "--health-baseline", "--dupes-baseline", "--max-decisions", "--format", "--open", "--config", "--entry", "--dart-platform", "--production", "--no-production", "--file", "--workspace", "--changed-workspaces", "--changed-since", "--compare", "--boundary", "--boundary-coverage", "--boundary-call", "--policy-pack", "--policy-violations", "--max-cyclomatic", "--max-cognitive", "--complexity-breakdown", "--coverage", "--coverage-gaps", "--max-crap", "--runtime-coverage", "--min-invocations-hot", "--min-observation-volume", "--low-traffic-threshold", "--file-scores", "--hotspots", "--targets", "--ownership", "--min-score", "--mode", "--min-tokens", "--min-lines", "--min-occurrences", "--top", "--threshold", "--cross-language", "--skip-local", "--ignore-imports", "--no-ignore-imports", "--include-entry-exports", "--private-type-leaks"]
157
+ "flags": ["--root", "--brief", "--base", "--gate", "--dead-code-baseline", "--health-baseline", "--dupes-baseline", "--max-decisions", "--format", "--open", "--config", "--entry", "--dart-platform", "--production", "--no-production", "--file", "--workspace", "--changed-workspaces", "--changed-since", "--compare", "--boundary", "--boundary-coverage", "--boundary-call", "--policy-pack", "--policy-violations", "--max-cyclomatic", "--max-cognitive", "--max-unit-size", "--complexity-breakdown", "--coverage", "--coverage-gaps", "--max-crap", "--runtime-coverage", "--min-invocations-hot", "--min-observation-volume", "--low-traffic-threshold", "--file-scores", "--hotspots", "--targets", "--ownership", "--min-score", "--mode", "--min-tokens", "--min-lines", "--min-occurrences", "--top", "--threshold", "--cross-language", "--skip-local", "--ignore-imports", "--no-ignore-imports", "--include-entry-exports", "--private-type-leaks"]
158
158
  },
159
159
  {
160
160
  "name": "review",
@@ -196,7 +196,7 @@ fn analysis_commands() -> Value {
196
196
  "kind": "health",
197
197
  "description": "Find complex functions, coverage gaps, hotspots, and refactoring targets.",
198
198
  "schema": SCHEMA_VERSION,
199
- "flags": ["--root", "--format", "--open", "--config", "--entry", "--dart-platform", "--production", "--no-production", "--file", "--workspace", "--changed-workspaces", "--changed-since", "--compare", "--regression-baseline", "--save-regression-baseline", "--fail-on-regression", "--tolerance", "--baseline", "--save-baseline", "--max-cyclomatic", "--max-cognitive", "--complexity-breakdown", "--coverage", "--coverage-gaps", "--max-crap", "--runtime-coverage", "--min-invocations-hot", "--min-observation-volume", "--low-traffic-threshold", "--file-scores", "--hotspots", "--targets", "--ownership", "--min-score", "--top"]
199
+ "flags": ["--root", "--format", "--open", "--config", "--entry", "--dart-platform", "--production", "--no-production", "--file", "--workspace", "--changed-workspaces", "--changed-since", "--compare", "--regression-baseline", "--save-regression-baseline", "--fail-on-regression", "--tolerance", "--baseline", "--save-baseline", "--max-cyclomatic", "--max-cognitive", "--max-unit-size", "--complexity-breakdown", "--coverage", "--coverage-gaps", "--max-crap", "--runtime-coverage", "--min-invocations-hot", "--min-observation-volume", "--low-traffic-threshold", "--file-scores", "--hotspots", "--targets", "--ownership", "--min-score", "--top", "--flutter-style"]
200
200
  },
201
201
  {
202
202
  "name": "flags",
@@ -478,6 +478,7 @@ fn issue_types() -> Value {
478
478
  "part-of-violation",
479
479
  "unused-dependency",
480
480
  "unused-dev-dependency",
481
+ "dev-dependency-in-production",
481
482
  "test-only-dependency",
482
483
  "unused-dependency-override",
483
484
  "misconfigured-dependency-override",
@@ -491,6 +492,9 @@ fn issue_types() -> Value {
491
492
  "high-crap-score",
492
493
  "health-hotspot",
493
494
  "refactoring-target",
495
+ "raw-flutter-style-value",
496
+ "near-duplicate-theme-token",
497
+ "unused-theme-extension-token",
494
498
  "feature-flag",
495
499
  "security-candidate",
496
500
  "stale-suppression",
@@ -77,6 +77,7 @@ const fn finding_kind(issue: DependencyIssue) -> FindingKind {
77
77
  match issue {
78
78
  DependencyIssue::UnusedRuntimeDependency => FindingKind::UnusedDependency,
79
79
  DependencyIssue::UnusedDevDependency => FindingKind::UnusedDevDependency,
80
+ DependencyIssue::DevDependencyInProduction => FindingKind::DevDependencyInProduction,
80
81
  DependencyIssue::TestOnlyDependency => FindingKind::TestOnlyDependency,
81
82
  DependencyIssue::UnusedDependencyOverride => FindingKind::UnusedDependencyOverride,
82
83
  }
@@ -86,6 +87,7 @@ fn rule_id(issue: DependencyIssue) -> &'static str {
86
87
  match issue {
87
88
  DependencyIssue::UnusedRuntimeDependency => "dart-decimate/unused-dependency",
88
89
  DependencyIssue::UnusedDevDependency => "dart-decimate/unused-dev-dependency",
90
+ DependencyIssue::DevDependencyInProduction => "dart-decimate/dev-dependency-in-production",
89
91
  DependencyIssue::TestOnlyDependency => "dart-decimate/test-only-dependency",
90
92
  DependencyIssue::UnusedDependencyOverride => "dart-decimate/unused-dependency-override",
91
93
  }
@@ -93,7 +95,9 @@ fn rule_id(issue: DependencyIssue) -> &'static str {
93
95
 
94
96
  const fn severity(issue: DependencyIssue) -> Severity {
95
97
  match issue {
96
- DependencyIssue::UnusedDependencyOverride => Severity::Warning,
98
+ DependencyIssue::UnusedDependencyOverride | DependencyIssue::DevDependencyInProduction => {
99
+ Severity::Warning
100
+ }
97
101
  _ => Severity::Error,
98
102
  }
99
103
  }
@@ -108,6 +112,10 @@ fn message(dependency: &UnusedPackageDependency) -> String {
108
112
  "{} declares unused dev dependency {}",
109
113
  dependency.package, dependency.dependency
110
114
  ),
115
+ DependencyIssue::DevDependencyInProduction => format!(
116
+ "{} imports dev dependency {} from production code",
117
+ dependency.package, dependency.dependency
118
+ ),
111
119
  DependencyIssue::TestOnlyDependency => format!(
112
120
  "{} declares runtime dependency {} that is only imported from dev/test files",
113
121
  dependency.package, dependency.dependency
@@ -129,6 +137,7 @@ fn action(dependency: &UnusedPackageDependency) -> &'static str {
129
137
  DependencyIssue::UnusedRuntimeDependency | DependencyIssue::UnusedDevDependency => {
130
138
  "review-pubspec-dependency"
131
139
  }
140
+ DependencyIssue::DevDependencyInProduction => "move-pubspec-dependency-to-dependencies",
132
141
  DependencyIssue::TestOnlyDependency => "move-pubspec-dependency-to-dev-dependencies",
133
142
  DependencyIssue::UnusedDependencyOverride => "review-unused-dependency-override",
134
143
  }
@@ -144,6 +153,9 @@ fn action_description(dependency: &UnusedPackageDependency) -> &'static str {
144
153
  DependencyIssue::UnusedRuntimeDependency | DependencyIssue::UnusedDevDependency => {
145
154
  "Review non-Dart usage such as build tools before removing this pubspec dependency"
146
155
  }
156
+ DependencyIssue::DevDependencyInProduction => {
157
+ "Move the package from dev_dependencies to dependencies"
158
+ }
147
159
  DependencyIssue::TestOnlyDependency => {
148
160
  "Move the package from dependencies to dev_dependencies after checking runtime usage"
149
161
  }
@@ -249,6 +261,7 @@ const fn dependency_section_key(section: DependencySection) -> &'static str {
249
261
 
250
262
  const fn unused_action_config_key(dependency: &UnusedPackageDependency) -> &'static str {
251
263
  match dependency.issue {
264
+ DependencyIssue::DevDependencyInProduction => "dependencies",
252
265
  DependencyIssue::TestOnlyDependency => "dev_dependencies",
253
266
  _ => dependency_section_key(dependency.section),
254
267
  }
@@ -0,0 +1,189 @@
1
+ use std::path::Path;
2
+
3
+ use serde::{Deserialize, Serialize};
4
+
5
+ use super::format::display_path;
6
+ use super::{Finding, FindingAction, FindingKind, Severity};
7
+ use crate::{
8
+ FlutterStyleFinding, FlutterStyleFindingKind, FlutterStyleReport, FlutterStyleValueKind,
9
+ HealthReport, ThemeTokenEvidence,
10
+ };
11
+
12
+ /// Opt-in Flutter theme/style advisory serialized in JSON reports.
13
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14
+ pub struct JsonFlutterStyleFinding {
15
+ /// Stable advisory identifier.
16
+ pub rule_id: String,
17
+ /// Advisory category.
18
+ pub kind: String,
19
+ /// Candidate source file.
20
+ pub path: String,
21
+ /// 1-based line.
22
+ pub line: usize,
23
+ /// 0-based byte column.
24
+ pub column: usize,
25
+ /// Theme-able value category.
26
+ pub value_kind: String,
27
+ /// Normalized raw value when supported.
28
+ pub value: Option<String>,
29
+ /// Primary theme token for pair/unused rows.
30
+ pub token: Option<JsonThemeTokenEvidence>,
31
+ /// Deterministically selected nearest token.
32
+ pub nearest_token: Option<JsonThemeTokenEvidence>,
33
+ /// Deterministic ARGB distance formatted to two decimal places.
34
+ pub distance: Option<String>,
35
+ }
36
+
37
+ /// Root-relative theme token evidence.
38
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
39
+ pub struct JsonThemeTokenEvidence {
40
+ /// Stable theme role or custom extension field name.
41
+ pub name: String,
42
+ /// Token source file.
43
+ pub path: String,
44
+ /// 1-based line.
45
+ pub line: usize,
46
+ /// 0-based byte column.
47
+ pub column: usize,
48
+ /// Theme-able value category.
49
+ pub value_kind: String,
50
+ /// Normalized token value when supported.
51
+ pub value: Option<String>,
52
+ /// Whether this is a custom `ThemeExtension` field.
53
+ pub custom: bool,
54
+ }
55
+
56
+ pub(super) fn add_flutter_style_findings(
57
+ root: &Path,
58
+ report: &FlutterStyleReport,
59
+ findings: &mut Vec<Finding>,
60
+ ) {
61
+ findings.extend(
62
+ report
63
+ .findings
64
+ .iter()
65
+ .map(|finding| flutter_style_finding(root, finding)),
66
+ );
67
+ }
68
+
69
+ pub(super) fn json_flutter_style(
70
+ root: &Path,
71
+ report: &HealthReport,
72
+ ) -> Vec<JsonFlutterStyleFinding> {
73
+ report
74
+ .flutter_style
75
+ .as_ref()
76
+ .map_or_else(Vec::new, |style| {
77
+ style
78
+ .findings
79
+ .iter()
80
+ .map(|finding| JsonFlutterStyleFinding {
81
+ rule_id: finding.kind.rule_id().to_owned(),
82
+ kind: style_finding_kind(finding.kind).to_owned(),
83
+ path: display_path(root, &finding.path),
84
+ line: finding.location.line,
85
+ column: finding.location.column,
86
+ value_kind: style_value_kind(finding.value_kind).to_owned(),
87
+ value: finding.value.clone(),
88
+ token: finding
89
+ .token
90
+ .as_ref()
91
+ .map(|token| json_theme_token(root, token)),
92
+ nearest_token: finding
93
+ .nearest_token
94
+ .as_ref()
95
+ .map(|token| json_theme_token(root, token)),
96
+ distance: finding.distance.clone(),
97
+ })
98
+ .collect()
99
+ })
100
+ }
101
+
102
+ fn flutter_style_finding(root: &Path, finding: &FlutterStyleFinding) -> Finding {
103
+ let path = display_path(root, &finding.path);
104
+ let (message, action) = finding_text(finding.kind);
105
+ Finding {
106
+ rule_id: finding.kind.rule_id().to_owned(),
107
+ fingerprint: Some(format!(
108
+ "{}:{path}:{}:{}",
109
+ style_finding_kind(finding.kind),
110
+ finding.location.line,
111
+ finding.location.column
112
+ )),
113
+ kind: finding_kind(finding.kind),
114
+ severity: Severity::Warning,
115
+ message: message.to_owned(),
116
+ path: path.clone(),
117
+ line: finding.location.line,
118
+ column: finding.location.column,
119
+ safe_to_delete: false,
120
+ files: finding
121
+ .nearest_token
122
+ .iter()
123
+ .map(|token| display_path(root, &token.path))
124
+ .collect(),
125
+ edge: None,
126
+ actions: vec![
127
+ FindingAction::new("review-flutter-style", action, false)
128
+ .with_target_path(path)
129
+ .with_suppression_comment(format!(
130
+ "// dart-decimate-ignore-next-line {} -- <reason>",
131
+ style_finding_kind(finding.kind)
132
+ )),
133
+ ],
134
+ }
135
+ }
136
+
137
+ const fn finding_text(kind: FlutterStyleFindingKind) -> (&'static str, &'static str) {
138
+ match kind {
139
+ FlutterStyleFindingKind::RawFlutterStyleValue => (
140
+ "Raw Flutter style value duplicates a resolvable theme token",
141
+ "Replace the raw value with the reviewed theme token",
142
+ ),
143
+ FlutterStyleFindingKind::NearDuplicateThemeToken => (
144
+ "Custom theme color tokens are near duplicates",
145
+ "Review whether the token pair should share one semantic role",
146
+ ),
147
+ FlutterStyleFindingKind::UnusedThemeExtensionToken => (
148
+ "Custom ThemeExtension token has no observed member access",
149
+ "Verify dynamic/generated consumers before removing the token",
150
+ ),
151
+ }
152
+ }
153
+
154
+ const fn finding_kind(kind: FlutterStyleFindingKind) -> FindingKind {
155
+ match kind {
156
+ FlutterStyleFindingKind::RawFlutterStyleValue => FindingKind::RawFlutterStyleValue,
157
+ FlutterStyleFindingKind::NearDuplicateThemeToken => FindingKind::NearDuplicateThemeToken,
158
+ FlutterStyleFindingKind::UnusedThemeExtensionToken => {
159
+ FindingKind::UnusedThemeExtensionToken
160
+ }
161
+ }
162
+ }
163
+
164
+ const fn style_finding_kind(kind: FlutterStyleFindingKind) -> &'static str {
165
+ match kind {
166
+ FlutterStyleFindingKind::RawFlutterStyleValue => "raw-flutter-style-value",
167
+ FlutterStyleFindingKind::NearDuplicateThemeToken => "near-duplicate-theme-token",
168
+ FlutterStyleFindingKind::UnusedThemeExtensionToken => "unused-theme-extension-token",
169
+ }
170
+ }
171
+
172
+ const fn style_value_kind(kind: FlutterStyleValueKind) -> &'static str {
173
+ match kind {
174
+ FlutterStyleValueKind::Color => "color",
175
+ FlutterStyleValueKind::TextStyle => "text-style",
176
+ }
177
+ }
178
+
179
+ fn json_theme_token(root: &Path, token: &ThemeTokenEvidence) -> JsonThemeTokenEvidence {
180
+ JsonThemeTokenEvidence {
181
+ name: token.name.clone(),
182
+ path: display_path(root, &token.path),
183
+ line: token.location.line,
184
+ column: token.location.column,
185
+ value_kind: style_value_kind(token.value_kind).to_owned(),
186
+ value: token.value.clone(),
187
+ custom: token.custom,
188
+ }
189
+ }