dart-decimate 0.0.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.
- package/Cargo.lock +572 -0
- package/Cargo.toml +41 -0
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/bin/dart-decimate-mcp.js +48 -0
- package/npm/bin/dart-decimate.js +48 -0
- package/npm/scripts/postinstall.js +46 -0
- package/npm/scripts/test-npx-local.js +54 -0
- package/npm/scripts/test-npx-mcp-local.js +56 -0
- package/package.json +45 -0
- package/src/baseline.rs +643 -0
- package/src/bin/dart-decimate-mcp.rs +11 -0
- package/src/boundaries/tests.rs +60 -0
- package/src/boundaries.rs +317 -0
- package/src/changed_scope.rs +117 -0
- package/src/ci_template.rs +399 -0
- package/src/cli/analyze.rs +462 -0
- package/src/cli/analyzer_options.rs +82 -0
- package/src/cli/audit_run.rs +327 -0
- package/src/cli/boundary_args.rs +44 -0
- package/src/cli/ci_template_run.rs +196 -0
- package/src/cli/command_name.rs +20 -0
- package/src/cli/common_args.rs +167 -0
- package/src/cli/config_run.rs +78 -0
- package/src/cli/coverage_run.rs +393 -0
- package/src/cli/decision_surface_run.rs +99 -0
- package/src/cli/default_command.rs +69 -0
- package/src/cli/dupes_args.rs +150 -0
- package/src/cli/entry_points.rs +121 -0
- package/src/cli/error.rs +149 -0
- package/src/cli/error_output.rs +68 -0
- package/src/cli/explain_run.rs +72 -0
- package/src/cli/fix_run.rs +162 -0
- package/src/cli/flags_args.rs +23 -0
- package/src/cli/health_args.rs +200 -0
- package/src/cli/hooks_run.rs +191 -0
- package/src/cli/impact_run.rs +95 -0
- package/src/cli/init_run.rs +49 -0
- package/src/cli/inspect_args.rs +20 -0
- package/src/cli/inspect_run.rs +66 -0
- package/src/cli/issue_filter_args.rs +240 -0
- package/src/cli/list_run.rs +311 -0
- package/src/cli/mode_args.rs +72 -0
- package/src/cli/output_format.rs +62 -0
- package/src/cli/regression_args.rs +156 -0
- package/src/cli/request_args.rs +175 -0
- package/src/cli/schema_commands.rs +72 -0
- package/src/cli/scope_args.rs +174 -0
- package/src/cli/security_args.rs +175 -0
- package/src/cli/security_gate_run.rs +66 -0
- package/src/cli/security_summary_run.rs +43 -0
- package/src/cli/summary_args.rs +12 -0
- package/src/cli/tests.rs +516 -0
- package/src/cli/trace_args.rs +67 -0
- package/src/cli/trace_run.rs +131 -0
- package/src/cli/trace_tests.rs +235 -0
- package/src/cli/unsupported_run.rs +116 -0
- package/src/cli/watch_run.rs +153 -0
- package/src/cli.rs +603 -0
- package/src/config/boundary_config.rs +235 -0
- package/src/config/cache.rs +25 -0
- package/src/config/dependencies.rs +114 -0
- package/src/config/health.rs +237 -0
- package/src/config/jsonc.rs +66 -0
- package/src/config/policy.rs +91 -0
- package/src/config/rule_aliases.rs +487 -0
- package/src/config/rules.rs +339 -0
- package/src/config.rs +635 -0
- package/src/coverage.rs +469 -0
- package/src/dart_parser.rs +673 -0
- package/src/decision_surface.rs +405 -0
- package/src/dependencies/analyze.rs +218 -0
- package/src/dependencies/codegen.rs +118 -0
- package/src/dependencies/discovery.rs +60 -0
- package/src/dependencies/overrides.rs +76 -0
- package/src/dependencies/private_src_imports.rs +32 -0
- package/src/dependencies/pubspec_document.rs +86 -0
- package/src/dependencies/pubspec_entry.rs +96 -0
- package/src/dependencies/tests.rs +544 -0
- package/src/dependencies/usage.rs +33 -0
- package/src/dependencies.rs +553 -0
- package/src/dependency_scripts.rs +91 -0
- package/src/dupes/lex.rs +236 -0
- package/src/dupes/tests.rs +119 -0
- package/src/dupes.rs +625 -0
- package/src/explain.rs +692 -0
- package/src/extract/directives.rs +252 -0
- package/src/extract/error_tests.rs +25 -0
- package/src/extract/members.rs +210 -0
- package/src/extract/primary_constructors.rs +421 -0
- package/src/extract/references.rs +151 -0
- package/src/extract/routes.rs +691 -0
- package/src/extract/signatures.rs +266 -0
- package/src/extract/string_tests.rs +18 -0
- package/src/extract/strings.rs +107 -0
- package/src/extract/tests.rs +697 -0
- package/src/extract.rs +680 -0
- package/src/feature_flags/tests.rs +76 -0
- package/src/feature_flags.rs +453 -0
- package/src/finding_identity.rs +60 -0
- package/src/fix.rs +551 -0
- package/src/generated.rs +53 -0
- package/src/graph/augment_tests.rs +212 -0
- package/src/graph/conditionals.rs +74 -0
- package/src/graph/package_config_tests.rs +100 -0
- package/src/graph/parts.rs +248 -0
- package/src/graph/pubspec_tests.rs +119 -0
- package/src/graph/tests.rs +837 -0
- package/src/graph/uri_tests.rs +102 -0
- package/src/graph.rs +644 -0
- package/src/health/coverage.rs +309 -0
- package/src/health/ownership.rs +175 -0
- package/src/health/runtime_coverage.rs +616 -0
- package/src/health/runtime_intelligence.rs +511 -0
- package/src/health/scores.rs +296 -0
- package/src/health/tests.rs +240 -0
- package/src/health/threshold_types.rs +163 -0
- package/src/health/thresholds.rs +229 -0
- package/src/health/types.rs +636 -0
- package/src/health.rs +597 -0
- package/src/hooks/agent_settings.rs +175 -0
- package/src/hooks/templates.rs +51 -0
- package/src/hooks.rs +569 -0
- package/src/impact.rs +287 -0
- package/src/init.rs +237 -0
- package/src/inspect.rs +142 -0
- package/src/intelligence/tests.rs +232 -0
- package/src/intelligence.rs +305 -0
- package/src/lib.rs +198 -0
- package/src/main.rs +5 -0
- package/src/manifest/mcp.rs +565 -0
- package/src/manifest.rs +552 -0
- package/src/mcp/cli_args/value_args.rs +175 -0
- package/src/mcp/cli_args.rs +658 -0
- package/src/mcp/cli_args_tests.rs +522 -0
- package/src/mcp/code_execute.rs +671 -0
- package/src/mcp/tools.rs +660 -0
- package/src/mcp.rs +325 -0
- package/src/output/audit_risk.rs +135 -0
- package/src/output/dependency_findings.rs +327 -0
- package/src/output/duplication_findings.rs +114 -0
- package/src/output/feature_flag_findings.rs +122 -0
- package/src/output/format.rs +31 -0
- package/src/output/graph_findings.rs +461 -0
- package/src/output/health_findings.rs +612 -0
- package/src/output/human.rs +27 -0
- package/src/output/next_steps.rs +92 -0
- package/src/output/route_findings.rs +76 -0
- package/src/output/runtime_coverage.rs +515 -0
- package/src/output/scope.rs +183 -0
- package/src/output/security_findings.rs +390 -0
- package/src/output/security_sarif.rs +150 -0
- package/src/output/suppressions.rs +323 -0
- package/src/output/symbol_findings.rs +257 -0
- package/src/output/tests.rs +114 -0
- package/src/output/types.rs +604 -0
- package/src/output/widget_findings.rs +213 -0
- package/src/output.rs +682 -0
- package/src/package_map.rs +495 -0
- package/src/policy/packs.rs +232 -0
- package/src/policy/tests.rs +134 -0
- package/src/policy.rs +640 -0
- package/src/project_list.rs +376 -0
- package/src/report_schema/inventory.rs +418 -0
- package/src/report_schema.rs +488 -0
- package/src/routes.rs +354 -0
- package/src/scan/tests.rs +250 -0
- package/src/scan.rs +275 -0
- package/src/security/detect.rs +639 -0
- package/src/security/tests.rs +178 -0
- package/src/security.rs +373 -0
- package/src/security_gate.rs +555 -0
- package/src/symbols/path_filters.rs +27 -0
- package/src/symbols/private_type_leaks.rs +125 -0
- package/src/symbols/riverpod.rs +113 -0
- package/src/symbols/tests.rs +692 -0
- package/src/symbols.rs +693 -0
- package/src/trace/tests.rs +225 -0
- package/src/trace.rs +690 -0
- package/src/unsupported.rs +47 -0
- package/src/widgets/lifecycle.rs +484 -0
- package/src/widgets/params.rs +236 -0
- package/src/widgets/tests.rs +430 -0
- package/src/widgets/top_level.rs +110 -0
- package/src/widgets/unrendered.rs +374 -0
- package/src/widgets.rs +590 -0
- package/src/workspace_scope.rs +358 -0
|
@@ -0,0 +1,612 @@
|
|
|
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
|
+
ComplexityContribution, ComplexityFinding, ComplexityRule, CoverageGapFinding,
|
|
9
|
+
CoverageGapReason, CrapFinding, EffectiveThresholds, FileCoverageStatus, FileHealthScore,
|
|
10
|
+
HealthHotspot, HealthReport, HealthThresholdOverrideReport, HealthThresholdOverrideStatus,
|
|
11
|
+
RefactoringTarget, ThresholdSource,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/// Complexity finding serialized in JSON reports.
|
|
15
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
16
|
+
pub struct JsonComplexityFinding {
|
|
17
|
+
/// Rule identifier.
|
|
18
|
+
pub rule_id: String,
|
|
19
|
+
/// Dart file path, root-relative where possible.
|
|
20
|
+
pub path: String,
|
|
21
|
+
/// Function, method, getter, setter, constructor, or closure name.
|
|
22
|
+
pub symbol: String,
|
|
23
|
+
/// Function-like declaration kind.
|
|
24
|
+
pub kind: String,
|
|
25
|
+
/// 1-based start line.
|
|
26
|
+
pub line: usize,
|
|
27
|
+
/// 0-based byte column.
|
|
28
|
+
pub column: usize,
|
|
29
|
+
/// Cyclomatic complexity score.
|
|
30
|
+
pub cyclomatic_complexity: usize,
|
|
31
|
+
/// Cognitive complexity score.
|
|
32
|
+
pub cognitive_complexity: usize,
|
|
33
|
+
/// Rounded line coverage percentage when coverage data is available.
|
|
34
|
+
pub line_coverage_percent: Option<usize>,
|
|
35
|
+
/// Covered executable lines when coverage data is available.
|
|
36
|
+
pub covered_lines: Option<usize>,
|
|
37
|
+
/// Executable lines when coverage data is available.
|
|
38
|
+
pub executable_lines: Option<usize>,
|
|
39
|
+
/// CRAP score when coverage data is available.
|
|
40
|
+
pub crap_score: Option<usize>,
|
|
41
|
+
/// Coverage status for this health record.
|
|
42
|
+
pub coverage_status: Option<String>,
|
|
43
|
+
/// Effective thresholds used by a matching override.
|
|
44
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
45
|
+
pub effective_thresholds: Option<JsonEffectiveThresholds>,
|
|
46
|
+
/// Source of effective thresholds when not global defaults.
|
|
47
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
48
|
+
pub threshold_source: Option<String>,
|
|
49
|
+
/// Configured reason for the threshold override.
|
|
50
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
51
|
+
pub threshold_reason: Option<String>,
|
|
52
|
+
/// Decision-point breakdown when requested.
|
|
53
|
+
pub contributions: Vec<JsonComplexityContribution>,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Effective thresholds serialized in JSON reports.
|
|
57
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
58
|
+
pub struct JsonEffectiveThresholds {
|
|
59
|
+
/// Cyclomatic ceiling used for this function.
|
|
60
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
61
|
+
pub max_cyclomatic: Option<usize>,
|
|
62
|
+
/// Cognitive ceiling used for this function.
|
|
63
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
64
|
+
pub max_cognitive: Option<usize>,
|
|
65
|
+
/// CRAP ceiling used for this function.
|
|
66
|
+
#[serde(skip_serializing_if = "Option::is_none")]
|
|
67
|
+
pub max_crap: Option<usize>,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// Threshold override state serialized in JSON reports.
|
|
71
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
72
|
+
pub struct JsonThresholdOverride {
|
|
73
|
+
/// Zero-based index in `health.thresholdOverrides`.
|
|
74
|
+
pub index: usize,
|
|
75
|
+
/// File globs from config.
|
|
76
|
+
pub files: Vec<String>,
|
|
77
|
+
/// Exact function names from config.
|
|
78
|
+
pub functions: Vec<String>,
|
|
79
|
+
/// Local cyclomatic ceiling.
|
|
80
|
+
pub max_cyclomatic: Option<usize>,
|
|
81
|
+
/// Local cognitive ceiling.
|
|
82
|
+
pub max_cognitive: Option<usize>,
|
|
83
|
+
/// Local CRAP ceiling.
|
|
84
|
+
pub max_crap: Option<usize>,
|
|
85
|
+
/// Configured reason.
|
|
86
|
+
pub reason: Option<String>,
|
|
87
|
+
/// Whether this override currently changes or explains threshold output.
|
|
88
|
+
pub active: bool,
|
|
89
|
+
/// Whether this override matched code but is no longer needed.
|
|
90
|
+
pub stale: bool,
|
|
91
|
+
/// Whether this override matched no analyzed functions.
|
|
92
|
+
pub no_match: bool,
|
|
93
|
+
/// Matched root-relative `file:symbol` entries.
|
|
94
|
+
pub matched_functions: Vec<String>,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// One decision point serialized in JSON reports.
|
|
98
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
99
|
+
pub struct JsonComplexityContribution {
|
|
100
|
+
/// 1-based line.
|
|
101
|
+
pub line: usize,
|
|
102
|
+
/// 0-based byte column.
|
|
103
|
+
pub column: usize,
|
|
104
|
+
/// Decision-point kind.
|
|
105
|
+
pub kind: String,
|
|
106
|
+
/// Cyclomatic score added by this point.
|
|
107
|
+
pub cyclomatic: usize,
|
|
108
|
+
/// Cognitive score added by this point.
|
|
109
|
+
pub cognitive: usize,
|
|
110
|
+
/// Nesting depth at this point.
|
|
111
|
+
pub nesting: usize,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// File health score serialized in JSON reports.
|
|
115
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
116
|
+
pub struct JsonFileHealthScore {
|
|
117
|
+
/// Dart file path, root-relative where possible.
|
|
118
|
+
pub path: String,
|
|
119
|
+
/// 0-100 score; higher is healthier.
|
|
120
|
+
pub score: usize,
|
|
121
|
+
/// Function-like declarations in the file.
|
|
122
|
+
pub functions: usize,
|
|
123
|
+
/// Functions exceeding static complexity or CRAP thresholds.
|
|
124
|
+
pub complex_functions: usize,
|
|
125
|
+
/// Highest cyclomatic complexity in the file.
|
|
126
|
+
pub max_cyclomatic_complexity: usize,
|
|
127
|
+
/// Highest cognitive complexity in the file.
|
|
128
|
+
pub max_cognitive_complexity: usize,
|
|
129
|
+
/// Highest CRAP score in the file.
|
|
130
|
+
pub max_crap_score: usize,
|
|
131
|
+
/// Coverage status.
|
|
132
|
+
pub coverage_status: String,
|
|
133
|
+
/// Covered executable lines when coverage data is available.
|
|
134
|
+
pub covered_lines: Option<usize>,
|
|
135
|
+
/// Executable lines when coverage data is available.
|
|
136
|
+
pub executable_lines: Option<usize>,
|
|
137
|
+
/// Rounded line coverage percentage when coverage data is available.
|
|
138
|
+
pub line_coverage_percent: Option<usize>,
|
|
139
|
+
/// Agent-readable score reasons.
|
|
140
|
+
pub reasons: Vec<String>,
|
|
141
|
+
/// CODEOWNERS owners, when `--ownership` is enabled.
|
|
142
|
+
pub owners: Vec<String>,
|
|
143
|
+
/// CODEOWNERS file that produced the owner match.
|
|
144
|
+
pub owner_source: Option<String>,
|
|
145
|
+
/// GitLab CODEOWNERS section, when present.
|
|
146
|
+
pub owner_section: Option<String>,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// Health hotspot serialized in JSON reports.
|
|
150
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
151
|
+
pub struct JsonHealthHotspot {
|
|
152
|
+
/// Dart file path, root-relative where possible.
|
|
153
|
+
pub path: String,
|
|
154
|
+
/// 1-based line.
|
|
155
|
+
pub line: usize,
|
|
156
|
+
/// 0-based byte column.
|
|
157
|
+
pub column: usize,
|
|
158
|
+
/// 0-100 score; higher is healthier.
|
|
159
|
+
pub score: usize,
|
|
160
|
+
/// Agent-readable hotspot reasons.
|
|
161
|
+
pub reasons: Vec<String>,
|
|
162
|
+
/// CODEOWNERS owners, when `--ownership` is enabled.
|
|
163
|
+
pub owners: Vec<String>,
|
|
164
|
+
/// CODEOWNERS file that produced the owner match.
|
|
165
|
+
pub owner_source: Option<String>,
|
|
166
|
+
/// GitLab CODEOWNERS section, when present.
|
|
167
|
+
pub owner_section: Option<String>,
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/// Refactoring target serialized in JSON reports.
|
|
171
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
172
|
+
pub struct JsonRefactoringTarget {
|
|
173
|
+
/// Dart file path, root-relative where possible.
|
|
174
|
+
pub path: String,
|
|
175
|
+
/// 1-based line.
|
|
176
|
+
pub line: usize,
|
|
177
|
+
/// 0-based byte column.
|
|
178
|
+
pub column: usize,
|
|
179
|
+
/// 0-100 score; higher is healthier.
|
|
180
|
+
pub score: usize,
|
|
181
|
+
/// Priority score used for deterministic ordering.
|
|
182
|
+
pub priority: usize,
|
|
183
|
+
/// Agent-readable target reasons.
|
|
184
|
+
pub reasons: Vec<String>,
|
|
185
|
+
/// CODEOWNERS owners, when `--ownership` is enabled.
|
|
186
|
+
pub owners: Vec<String>,
|
|
187
|
+
/// CODEOWNERS file that produced the owner match.
|
|
188
|
+
pub owner_source: Option<String>,
|
|
189
|
+
/// GitLab CODEOWNERS section, when present.
|
|
190
|
+
pub owner_section: Option<String>,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
pub(super) fn add_health_findings(root: &Path, report: &HealthReport, findings: &mut Vec<Finding>) {
|
|
194
|
+
findings.extend(
|
|
195
|
+
report
|
|
196
|
+
.complexity
|
|
197
|
+
.iter()
|
|
198
|
+
.map(|finding| complexity_finding(root, finding)),
|
|
199
|
+
);
|
|
200
|
+
findings.extend(
|
|
201
|
+
report
|
|
202
|
+
.coverage_gaps
|
|
203
|
+
.iter()
|
|
204
|
+
.map(|finding| coverage_gap_finding(root, finding)),
|
|
205
|
+
);
|
|
206
|
+
findings.extend(
|
|
207
|
+
report
|
|
208
|
+
.crap
|
|
209
|
+
.iter()
|
|
210
|
+
.map(|finding| crap_finding(root, finding)),
|
|
211
|
+
);
|
|
212
|
+
findings.extend(
|
|
213
|
+
report
|
|
214
|
+
.hotspots
|
|
215
|
+
.iter()
|
|
216
|
+
.map(|finding| hotspot_finding(root, finding)),
|
|
217
|
+
);
|
|
218
|
+
findings.extend(
|
|
219
|
+
report
|
|
220
|
+
.refactoring_targets
|
|
221
|
+
.iter()
|
|
222
|
+
.map(|finding| refactoring_target_finding(root, finding)),
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
pub(super) fn json_complexity(root: &Path, report: &HealthReport) -> Vec<JsonComplexityFinding> {
|
|
227
|
+
let mut findings = report
|
|
228
|
+
.complexity
|
|
229
|
+
.iter()
|
|
230
|
+
.map(|finding| json_complexity_finding(root, finding))
|
|
231
|
+
.collect::<Vec<_>>();
|
|
232
|
+
findings.extend(
|
|
233
|
+
report
|
|
234
|
+
.crap
|
|
235
|
+
.iter()
|
|
236
|
+
.map(|finding| json_crap_finding(root, finding)),
|
|
237
|
+
);
|
|
238
|
+
findings
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
pub(super) fn json_file_scores(root: &Path, report: &HealthReport) -> Vec<JsonFileHealthScore> {
|
|
242
|
+
report
|
|
243
|
+
.file_scores
|
|
244
|
+
.iter()
|
|
245
|
+
.map(|score| json_file_score(root, score))
|
|
246
|
+
.collect()
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
pub(super) fn json_hotspots(root: &Path, report: &HealthReport) -> Vec<JsonHealthHotspot> {
|
|
250
|
+
report
|
|
251
|
+
.hotspots
|
|
252
|
+
.iter()
|
|
253
|
+
.map(|hotspot| JsonHealthHotspot {
|
|
254
|
+
path: display_path(root, &hotspot.path),
|
|
255
|
+
line: hotspot.location.line,
|
|
256
|
+
column: hotspot.location.column,
|
|
257
|
+
score: hotspot.score,
|
|
258
|
+
reasons: hotspot.reasons.clone(),
|
|
259
|
+
owners: hotspot.owners.clone(),
|
|
260
|
+
owner_source: hotspot.owner_source.clone(),
|
|
261
|
+
owner_section: hotspot.owner_section.clone(),
|
|
262
|
+
})
|
|
263
|
+
.collect()
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
pub(super) fn json_refactoring_targets(
|
|
267
|
+
root: &Path,
|
|
268
|
+
report: &HealthReport,
|
|
269
|
+
) -> Vec<JsonRefactoringTarget> {
|
|
270
|
+
report
|
|
271
|
+
.refactoring_targets
|
|
272
|
+
.iter()
|
|
273
|
+
.map(|target| JsonRefactoringTarget {
|
|
274
|
+
path: display_path(root, &target.path),
|
|
275
|
+
line: target.location.line,
|
|
276
|
+
column: target.location.column,
|
|
277
|
+
score: target.score,
|
|
278
|
+
priority: target.priority,
|
|
279
|
+
reasons: target.reasons.clone(),
|
|
280
|
+
owners: target.owners.clone(),
|
|
281
|
+
owner_source: target.owner_source.clone(),
|
|
282
|
+
owner_section: target.owner_section.clone(),
|
|
283
|
+
})
|
|
284
|
+
.collect()
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
pub(super) fn json_threshold_overrides(report: &HealthReport) -> Vec<JsonThresholdOverride> {
|
|
288
|
+
report
|
|
289
|
+
.threshold_overrides
|
|
290
|
+
.iter()
|
|
291
|
+
.map(json_threshold_override)
|
|
292
|
+
.collect()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
fn complexity_finding(root: &Path, finding: &ComplexityFinding) -> Finding {
|
|
296
|
+
let path = display_path(root, &finding.path);
|
|
297
|
+
Finding {
|
|
298
|
+
rule_id: finding.rule.rule_id().to_owned(),
|
|
299
|
+
fingerprint: None,
|
|
300
|
+
kind: finding_kind(finding.rule),
|
|
301
|
+
severity: Severity::Error,
|
|
302
|
+
message: format!(
|
|
303
|
+
"{} has cyclomatic complexity {} and cognitive complexity {}",
|
|
304
|
+
finding.symbol, finding.cyclomatic_complexity, finding.cognitive_complexity
|
|
305
|
+
),
|
|
306
|
+
path: path.clone(),
|
|
307
|
+
line: finding.location.line,
|
|
308
|
+
column: finding.location.column,
|
|
309
|
+
safe_to_delete: false,
|
|
310
|
+
files: Vec::new(),
|
|
311
|
+
edge: None,
|
|
312
|
+
actions: vec![
|
|
313
|
+
FindingAction::new(
|
|
314
|
+
"refactor-function",
|
|
315
|
+
"Split branches into smaller functions or move policy to the owning module",
|
|
316
|
+
false,
|
|
317
|
+
)
|
|
318
|
+
.with_target_path(path.clone())
|
|
319
|
+
.with_target_symbol(finding.symbol.clone())
|
|
320
|
+
.with_dart_decimate_args(["inspect", "--format", "json", "--file", path.as_str()])
|
|
321
|
+
.with_suppression_comment("// dart-decimate-ignore-next-line complexity"),
|
|
322
|
+
],
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
fn coverage_gap_finding(root: &Path, finding: &CoverageGapFinding) -> Finding {
|
|
327
|
+
let path = display_path(root, &finding.path);
|
|
328
|
+
Finding {
|
|
329
|
+
rule_id: "dart-decimate/coverage-gap".to_owned(),
|
|
330
|
+
fingerprint: Some(format!("coverage-gap:{path}")),
|
|
331
|
+
kind: FindingKind::CoverageGap,
|
|
332
|
+
severity: Severity::Error,
|
|
333
|
+
message: format!(
|
|
334
|
+
"{} has no covered executable lines ({})",
|
|
335
|
+
path,
|
|
336
|
+
coverage_gap_reason(finding.reason)
|
|
337
|
+
),
|
|
338
|
+
path: path.clone(),
|
|
339
|
+
line: finding.location.line,
|
|
340
|
+
column: finding.location.column,
|
|
341
|
+
safe_to_delete: false,
|
|
342
|
+
files: Vec::new(),
|
|
343
|
+
edge: None,
|
|
344
|
+
actions: vec![
|
|
345
|
+
FindingAction::new(
|
|
346
|
+
"add-test",
|
|
347
|
+
"Add or run tests that execute this Dart file, then refresh LCOV",
|
|
348
|
+
false,
|
|
349
|
+
)
|
|
350
|
+
.with_target_path(path.clone())
|
|
351
|
+
.with_dart_decimate_args([
|
|
352
|
+
"inspect",
|
|
353
|
+
"--format",
|
|
354
|
+
"json",
|
|
355
|
+
"--file",
|
|
356
|
+
path.as_str(),
|
|
357
|
+
]),
|
|
358
|
+
],
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
fn crap_finding(root: &Path, finding: &CrapFinding) -> Finding {
|
|
363
|
+
let path = display_path(root, &finding.path);
|
|
364
|
+
Finding {
|
|
365
|
+
rule_id: "dart-decimate/high-crap-score".to_owned(),
|
|
366
|
+
fingerprint: Some(format!(
|
|
367
|
+
"high-crap-score:{}:{}:{:?}",
|
|
368
|
+
path, finding.symbol, finding.kind
|
|
369
|
+
)),
|
|
370
|
+
kind: FindingKind::HighCrapScore,
|
|
371
|
+
severity: Severity::Error,
|
|
372
|
+
message: format!(
|
|
373
|
+
"{} has CRAP score {} with {}% line coverage",
|
|
374
|
+
finding.symbol, finding.crap_score, finding.line_coverage_percent
|
|
375
|
+
),
|
|
376
|
+
path: path.clone(),
|
|
377
|
+
line: finding.location.line,
|
|
378
|
+
column: finding.location.column,
|
|
379
|
+
safe_to_delete: false,
|
|
380
|
+
files: Vec::new(),
|
|
381
|
+
edge: None,
|
|
382
|
+
actions: vec![
|
|
383
|
+
FindingAction::new(
|
|
384
|
+
"refactor-or-test",
|
|
385
|
+
"Reduce branching or add targeted tests covering this function",
|
|
386
|
+
false,
|
|
387
|
+
)
|
|
388
|
+
.with_target_path(path.clone())
|
|
389
|
+
.with_target_symbol(finding.symbol.clone())
|
|
390
|
+
.with_dart_decimate_args(["inspect", "--format", "json", "--file", path.as_str()])
|
|
391
|
+
.with_suppression_comment("// dart-decimate-ignore-next-line complexity"),
|
|
392
|
+
],
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
fn hotspot_finding(root: &Path, finding: &HealthHotspot) -> Finding {
|
|
397
|
+
let path = display_path(root, &finding.path);
|
|
398
|
+
Finding {
|
|
399
|
+
rule_id: "dart-decimate/health-hotspot".to_owned(),
|
|
400
|
+
fingerprint: Some(format!("health-hotspot:{path}")),
|
|
401
|
+
kind: FindingKind::HealthHotspot,
|
|
402
|
+
severity: Severity::Error,
|
|
403
|
+
message: format!("{} has health score {}", path, finding.score),
|
|
404
|
+
path: path.clone(),
|
|
405
|
+
line: finding.location.line,
|
|
406
|
+
column: finding.location.column,
|
|
407
|
+
safe_to_delete: false,
|
|
408
|
+
files: Vec::new(),
|
|
409
|
+
edge: None,
|
|
410
|
+
actions: vec![
|
|
411
|
+
FindingAction::new(
|
|
412
|
+
"review-file-health",
|
|
413
|
+
"Review the file score reasons before refactoring",
|
|
414
|
+
false,
|
|
415
|
+
)
|
|
416
|
+
.with_target_path(path.clone())
|
|
417
|
+
.with_dart_decimate_args([
|
|
418
|
+
"inspect",
|
|
419
|
+
"--format",
|
|
420
|
+
"json",
|
|
421
|
+
"--file",
|
|
422
|
+
path.as_str(),
|
|
423
|
+
]),
|
|
424
|
+
],
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
fn refactoring_target_finding(root: &Path, finding: &RefactoringTarget) -> Finding {
|
|
429
|
+
let path = display_path(root, &finding.path);
|
|
430
|
+
Finding {
|
|
431
|
+
rule_id: "dart-decimate/refactoring-target".to_owned(),
|
|
432
|
+
fingerprint: Some(format!("refactoring-target:{path}")),
|
|
433
|
+
kind: FindingKind::RefactoringTarget,
|
|
434
|
+
severity: Severity::Error,
|
|
435
|
+
message: format!(
|
|
436
|
+
"{} is a refactoring target with priority {} and health score {}",
|
|
437
|
+
path, finding.priority, finding.score
|
|
438
|
+
),
|
|
439
|
+
path: path.clone(),
|
|
440
|
+
line: finding.location.line,
|
|
441
|
+
column: finding.location.column,
|
|
442
|
+
safe_to_delete: false,
|
|
443
|
+
files: Vec::new(),
|
|
444
|
+
edge: None,
|
|
445
|
+
actions: vec![
|
|
446
|
+
FindingAction::new(
|
|
447
|
+
"refactor-target",
|
|
448
|
+
"Split complex functions or isolate policy before editing",
|
|
449
|
+
false,
|
|
450
|
+
)
|
|
451
|
+
.with_target_path(path.clone())
|
|
452
|
+
.with_dart_decimate_args([
|
|
453
|
+
"inspect",
|
|
454
|
+
"--format",
|
|
455
|
+
"json",
|
|
456
|
+
"--file",
|
|
457
|
+
path.as_str(),
|
|
458
|
+
]),
|
|
459
|
+
],
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
fn finding_kind(rule: ComplexityRule) -> FindingKind {
|
|
464
|
+
match rule {
|
|
465
|
+
ComplexityRule::HighCyclomaticComplexity => FindingKind::HighCyclomaticComplexity,
|
|
466
|
+
ComplexityRule::HighCognitiveComplexity => FindingKind::HighCognitiveComplexity,
|
|
467
|
+
ComplexityRule::HighComplexity => FindingKind::HighComplexity,
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
fn json_complexity_finding(root: &Path, finding: &ComplexityFinding) -> JsonComplexityFinding {
|
|
472
|
+
JsonComplexityFinding {
|
|
473
|
+
rule_id: finding.rule.rule_id().to_owned(),
|
|
474
|
+
path: display_path(root, &finding.path),
|
|
475
|
+
symbol: finding.symbol.clone(),
|
|
476
|
+
kind: format!("{:?}", finding.kind)
|
|
477
|
+
.to_ascii_lowercase()
|
|
478
|
+
.replace('_', "-"),
|
|
479
|
+
line: finding.location.line,
|
|
480
|
+
column: finding.location.column,
|
|
481
|
+
cyclomatic_complexity: finding.cyclomatic_complexity,
|
|
482
|
+
cognitive_complexity: finding.cognitive_complexity,
|
|
483
|
+
line_coverage_percent: None,
|
|
484
|
+
covered_lines: None,
|
|
485
|
+
executable_lines: None,
|
|
486
|
+
crap_score: None,
|
|
487
|
+
coverage_status: None,
|
|
488
|
+
effective_thresholds: finding
|
|
489
|
+
.effective_thresholds
|
|
490
|
+
.as_ref()
|
|
491
|
+
.map(json_effective_thresholds),
|
|
492
|
+
threshold_source: finding
|
|
493
|
+
.threshold_source
|
|
494
|
+
.map(threshold_source)
|
|
495
|
+
.map(str::to_owned),
|
|
496
|
+
threshold_reason: finding.threshold_reason.clone(),
|
|
497
|
+
contributions: finding
|
|
498
|
+
.contributions
|
|
499
|
+
.iter()
|
|
500
|
+
.map(json_contribution)
|
|
501
|
+
.collect(),
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
fn json_crap_finding(root: &Path, finding: &CrapFinding) -> JsonComplexityFinding {
|
|
506
|
+
JsonComplexityFinding {
|
|
507
|
+
rule_id: "dart-decimate/high-crap-score".to_owned(),
|
|
508
|
+
path: display_path(root, &finding.path),
|
|
509
|
+
symbol: finding.symbol.clone(),
|
|
510
|
+
kind: format!("{:?}", finding.kind)
|
|
511
|
+
.to_ascii_lowercase()
|
|
512
|
+
.replace('_', "-"),
|
|
513
|
+
line: finding.location.line,
|
|
514
|
+
column: finding.location.column,
|
|
515
|
+
cyclomatic_complexity: finding.cyclomatic_complexity,
|
|
516
|
+
cognitive_complexity: finding.cognitive_complexity,
|
|
517
|
+
line_coverage_percent: Some(finding.line_coverage_percent),
|
|
518
|
+
covered_lines: Some(finding.covered_lines),
|
|
519
|
+
executable_lines: Some(finding.executable_lines),
|
|
520
|
+
crap_score: Some(finding.crap_score),
|
|
521
|
+
coverage_status: Some("covered".to_owned()),
|
|
522
|
+
effective_thresholds: finding
|
|
523
|
+
.effective_thresholds
|
|
524
|
+
.as_ref()
|
|
525
|
+
.map(json_effective_thresholds),
|
|
526
|
+
threshold_source: finding
|
|
527
|
+
.threshold_source
|
|
528
|
+
.map(threshold_source)
|
|
529
|
+
.map(str::to_owned),
|
|
530
|
+
threshold_reason: finding.threshold_reason.clone(),
|
|
531
|
+
contributions: Vec::new(),
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
fn json_effective_thresholds(thresholds: &EffectiveThresholds) -> JsonEffectiveThresholds {
|
|
536
|
+
JsonEffectiveThresholds {
|
|
537
|
+
max_cyclomatic: thresholds.max_cyclomatic,
|
|
538
|
+
max_cognitive: thresholds.max_cognitive,
|
|
539
|
+
max_crap: thresholds.max_crap,
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
fn json_threshold_override(report: &HealthThresholdOverrideReport) -> JsonThresholdOverride {
|
|
544
|
+
JsonThresholdOverride {
|
|
545
|
+
index: report.index,
|
|
546
|
+
files: report.files.clone(),
|
|
547
|
+
functions: report.functions.clone(),
|
|
548
|
+
max_cyclomatic: report.max_cyclomatic,
|
|
549
|
+
max_cognitive: report.max_cognitive,
|
|
550
|
+
max_crap: report.max_crap,
|
|
551
|
+
reason: report.reason.clone(),
|
|
552
|
+
active: report.status == HealthThresholdOverrideStatus::Active,
|
|
553
|
+
stale: report.status == HealthThresholdOverrideStatus::Stale,
|
|
554
|
+
no_match: report.status == HealthThresholdOverrideStatus::NoMatch,
|
|
555
|
+
matched_functions: report.matched_functions.clone(),
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const fn threshold_source(source: ThresholdSource) -> &'static str {
|
|
560
|
+
match source {
|
|
561
|
+
ThresholdSource::Override => "override",
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
fn json_file_score(root: &Path, score: &FileHealthScore) -> JsonFileHealthScore {
|
|
566
|
+
JsonFileHealthScore {
|
|
567
|
+
path: display_path(root, &score.path),
|
|
568
|
+
score: score.score,
|
|
569
|
+
functions: score.functions,
|
|
570
|
+
complex_functions: score.complex_functions,
|
|
571
|
+
max_cyclomatic_complexity: score.max_cyclomatic_complexity,
|
|
572
|
+
max_cognitive_complexity: score.max_cognitive_complexity,
|
|
573
|
+
max_crap_score: score.max_crap_score,
|
|
574
|
+
coverage_status: file_coverage_status(score.coverage_status).to_owned(),
|
|
575
|
+
covered_lines: score.covered_lines,
|
|
576
|
+
executable_lines: score.executable_lines,
|
|
577
|
+
line_coverage_percent: score.line_coverage_percent,
|
|
578
|
+
reasons: score.reasons.clone(),
|
|
579
|
+
owners: score.owners.clone(),
|
|
580
|
+
owner_source: score.owner_source.clone(),
|
|
581
|
+
owner_section: score.owner_section.clone(),
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
fn json_contribution(contribution: &ComplexityContribution) -> JsonComplexityContribution {
|
|
586
|
+
JsonComplexityContribution {
|
|
587
|
+
line: contribution.location.line,
|
|
588
|
+
column: contribution.location.column,
|
|
589
|
+
kind: contribution.kind.clone(),
|
|
590
|
+
cyclomatic: contribution.cyclomatic,
|
|
591
|
+
cognitive: contribution.cognitive,
|
|
592
|
+
nesting: contribution.nesting,
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
fn coverage_gap_reason(reason: CoverageGapReason) -> &'static str {
|
|
597
|
+
match reason {
|
|
598
|
+
CoverageGapReason::MissingFromCoverage => "missing from coverage",
|
|
599
|
+
CoverageGapReason::NoExecutableLines => "no executable lines in LCOV",
|
|
600
|
+
CoverageGapReason::ZeroCoveredLines => "zero covered lines",
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
fn file_coverage_status(status: FileCoverageStatus) -> &'static str {
|
|
605
|
+
match status {
|
|
606
|
+
FileCoverageStatus::NotRequested => "not-requested",
|
|
607
|
+
FileCoverageStatus::Missing => "missing",
|
|
608
|
+
FileCoverageStatus::NoExecutableLines => "no-executable-lines",
|
|
609
|
+
FileCoverageStatus::Uncovered => "uncovered",
|
|
610
|
+
FileCoverageStatus::Covered => "covered",
|
|
611
|
+
}
|
|
612
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
use std::fmt::Write as _;
|
|
2
|
+
|
|
3
|
+
use super::types::JsonReport;
|
|
4
|
+
|
|
5
|
+
/// Render a concise human report.
|
|
6
|
+
#[must_use]
|
|
7
|
+
pub fn render_human_report(report: &JsonReport) -> String {
|
|
8
|
+
let mut rendered = String::new();
|
|
9
|
+
let _ = writeln!(
|
|
10
|
+
rendered,
|
|
11
|
+
"{:?} {}: {} findings across {} files",
|
|
12
|
+
report.verdict,
|
|
13
|
+
report.command.as_str(),
|
|
14
|
+
report.summary.findings,
|
|
15
|
+
report.summary.files
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
for finding in &report.findings {
|
|
19
|
+
let _ = writeln!(
|
|
20
|
+
rendered,
|
|
21
|
+
"{}:{}:{} {} {}",
|
|
22
|
+
finding.path, finding.line, finding.column, finding.rule_id, finding.message
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
rendered
|
|
27
|
+
}
|