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,150 @@
|
|
|
1
|
+
use std::collections::BTreeMap;
|
|
2
|
+
|
|
3
|
+
use serde_json::{Map, Value, json};
|
|
4
|
+
|
|
5
|
+
use super::{Finding, JsonReport, Severity};
|
|
6
|
+
|
|
7
|
+
const SARIF_VERSION: &str = "2.1.0";
|
|
8
|
+
const SARIF_SCHEMA: &str = "https://json.schemastore.org/sarif-2.1.0.json";
|
|
9
|
+
|
|
10
|
+
pub(crate) fn render_sarif_report(report: &JsonReport) -> Value {
|
|
11
|
+
let findings = report.findings.iter().collect::<Vec<_>>();
|
|
12
|
+
let reachability_by_fingerprint = security_reachability_by_fingerprint(report);
|
|
13
|
+
|
|
14
|
+
json!({
|
|
15
|
+
"version": SARIF_VERSION,
|
|
16
|
+
"$schema": SARIF_SCHEMA,
|
|
17
|
+
"runs": [
|
|
18
|
+
{
|
|
19
|
+
"tool": {
|
|
20
|
+
"driver": {
|
|
21
|
+
"name": "dart-decimate",
|
|
22
|
+
"rules": sarif_rules(&findings)
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"results": sarif_results_with_reachability(
|
|
26
|
+
&findings,
|
|
27
|
+
&reachability_by_fingerprint
|
|
28
|
+
),
|
|
29
|
+
"properties": {
|
|
30
|
+
"schemaVersion": &report.schema_version,
|
|
31
|
+
"command": &report.command,
|
|
32
|
+
"verdict": &report.verdict,
|
|
33
|
+
"findingCount": findings.len()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fn security_reachability_by_fingerprint(report: &JsonReport) -> BTreeMap<String, Value> {
|
|
41
|
+
report
|
|
42
|
+
.security_candidates
|
|
43
|
+
.iter()
|
|
44
|
+
.filter_map(|candidate| {
|
|
45
|
+
candidate
|
|
46
|
+
.reachability
|
|
47
|
+
.as_ref()
|
|
48
|
+
.map(|reachability| (candidate.fingerprint.clone(), json!(reachability)))
|
|
49
|
+
})
|
|
50
|
+
.collect()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
fn sarif_rules(findings: &[&Finding]) -> Vec<Value> {
|
|
54
|
+
let mut rules = BTreeMap::<&str, &Finding>::new();
|
|
55
|
+
for finding in findings {
|
|
56
|
+
rules.entry(finding.rule_id.as_str()).or_insert(*finding);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
rules
|
|
60
|
+
.into_values()
|
|
61
|
+
.map(|finding| {
|
|
62
|
+
json!({
|
|
63
|
+
"id": &finding.rule_id,
|
|
64
|
+
"name": &finding.rule_id,
|
|
65
|
+
"shortDescription": {
|
|
66
|
+
"text": "Dart Decimate codebase intelligence finding"
|
|
67
|
+
},
|
|
68
|
+
"fullDescription": {
|
|
69
|
+
"text": &finding.message
|
|
70
|
+
},
|
|
71
|
+
"help": {
|
|
72
|
+
"text": "Review the referenced Dart or Flutter code before editing."
|
|
73
|
+
},
|
|
74
|
+
"defaultConfiguration": {
|
|
75
|
+
"level": sarif_level(finding.severity)
|
|
76
|
+
},
|
|
77
|
+
"properties": {
|
|
78
|
+
"kind": finding.kind,
|
|
79
|
+
"tags": ["security", "dart", "flutter"]
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
.collect()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
fn sarif_results_with_reachability(
|
|
87
|
+
findings: &[&Finding],
|
|
88
|
+
reachability_by_fingerprint: &BTreeMap<String, Value>,
|
|
89
|
+
) -> Vec<Value> {
|
|
90
|
+
findings
|
|
91
|
+
.iter()
|
|
92
|
+
.map(|finding| {
|
|
93
|
+
let properties = result_properties(finding, reachability_by_fingerprint);
|
|
94
|
+
json!({
|
|
95
|
+
"ruleId": &finding.rule_id,
|
|
96
|
+
"level": sarif_level(finding.severity),
|
|
97
|
+
"message": {
|
|
98
|
+
"text": &finding.message
|
|
99
|
+
},
|
|
100
|
+
"locations": [
|
|
101
|
+
{
|
|
102
|
+
"physicalLocation": {
|
|
103
|
+
"artifactLocation": {
|
|
104
|
+
"uri": &finding.path
|
|
105
|
+
},
|
|
106
|
+
"region": {
|
|
107
|
+
"startLine": finding.line.max(1),
|
|
108
|
+
"startColumn": finding.column + 1
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"partialFingerprints": partial_fingerprints(finding),
|
|
114
|
+
"properties": properties
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
.collect()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
fn result_properties(
|
|
121
|
+
finding: &Finding,
|
|
122
|
+
reachability_by_fingerprint: &BTreeMap<String, Value>,
|
|
123
|
+
) -> Value {
|
|
124
|
+
let mut properties = Map::new();
|
|
125
|
+
properties.insert("kind".to_owned(), json!(finding.kind));
|
|
126
|
+
properties.insert("findingId".to_owned(), json!(&finding.fingerprint));
|
|
127
|
+
properties.insert("safeToDelete".to_owned(), json!(finding.safe_to_delete));
|
|
128
|
+
properties.insert("files".to_owned(), json!(&finding.files));
|
|
129
|
+
properties.insert("actions".to_owned(), json!(&finding.actions));
|
|
130
|
+
if let Some(fingerprint) = &finding.fingerprint
|
|
131
|
+
&& let Some(reachability) = reachability_by_fingerprint.get(fingerprint)
|
|
132
|
+
{
|
|
133
|
+
properties.insert("securityReachability".to_owned(), reachability.clone());
|
|
134
|
+
}
|
|
135
|
+
Value::Object(properties)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
fn partial_fingerprints(finding: &Finding) -> Value {
|
|
139
|
+
match finding.fingerprint.as_deref() {
|
|
140
|
+
Some(fingerprint) => json!({ "decimateFingerprint": fingerprint }),
|
|
141
|
+
None => json!({}),
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const fn sarif_level(severity: Severity) -> &'static str {
|
|
146
|
+
match severity {
|
|
147
|
+
Severity::Error => "error",
|
|
148
|
+
Severity::Warning => "warning",
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
+
use std::fs;
|
|
3
|
+
use std::path::{Path, PathBuf};
|
|
4
|
+
|
|
5
|
+
use super::format::display_path;
|
|
6
|
+
use super::{Finding, FindingAction, FindingKind, Severity};
|
|
7
|
+
use crate::DartFile;
|
|
8
|
+
|
|
9
|
+
pub(super) fn filter_suppressed_findings(
|
|
10
|
+
root: &Path,
|
|
11
|
+
files: &[DartFile],
|
|
12
|
+
findings: Vec<Finding>,
|
|
13
|
+
require_reasons: bool,
|
|
14
|
+
) -> Vec<Finding> {
|
|
15
|
+
let mut state = SuppressionState::new(root, files);
|
|
16
|
+
let mut filtered = findings
|
|
17
|
+
.into_iter()
|
|
18
|
+
.filter(|finding| !state.is_suppressed(finding))
|
|
19
|
+
.collect::<Vec<_>>();
|
|
20
|
+
filtered.extend(state.stale_findings());
|
|
21
|
+
if require_reasons {
|
|
22
|
+
filtered.extend(state.missing_reason_findings());
|
|
23
|
+
}
|
|
24
|
+
filtered
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#[derive(Debug)]
|
|
28
|
+
struct SuppressionState {
|
|
29
|
+
root: PathBuf,
|
|
30
|
+
cache: BTreeMap<PathBuf, Option<Vec<String>>>,
|
|
31
|
+
directives: BTreeMap<SuppressionKey, SuppressionDirective>,
|
|
32
|
+
used: BTreeSet<SuppressionKey>,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
36
|
+
struct SuppressionKey {
|
|
37
|
+
path: String,
|
|
38
|
+
line: usize,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#[derive(Debug)]
|
|
42
|
+
struct SuppressionDirective {
|
|
43
|
+
column: usize,
|
|
44
|
+
text: String,
|
|
45
|
+
has_reason: bool,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
impl SuppressionState {
|
|
49
|
+
fn new(root: &Path, files: &[DartFile]) -> Self {
|
|
50
|
+
let mut cache = BTreeMap::new();
|
|
51
|
+
let mut directives = BTreeMap::new();
|
|
52
|
+
for file in files {
|
|
53
|
+
let path = file.path.clone();
|
|
54
|
+
let lines = read_lines(&path);
|
|
55
|
+
if let Some(lines) = &lines {
|
|
56
|
+
collect_directives(root, &path, lines, &mut directives);
|
|
57
|
+
}
|
|
58
|
+
cache.insert(path, lines);
|
|
59
|
+
}
|
|
60
|
+
Self {
|
|
61
|
+
root: root.to_path_buf(),
|
|
62
|
+
cache,
|
|
63
|
+
directives,
|
|
64
|
+
used: BTreeSet::new(),
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fn is_suppressed(&mut self, finding: &Finding) -> bool {
|
|
69
|
+
let Some(previous_line) = finding.line.checked_sub(2) else {
|
|
70
|
+
return false;
|
|
71
|
+
};
|
|
72
|
+
let path = finding_path(&self.root, &finding.path);
|
|
73
|
+
let lines = self
|
|
74
|
+
.cache
|
|
75
|
+
.entry(path.clone())
|
|
76
|
+
.or_insert_with(|| read_lines(&path));
|
|
77
|
+
let Some(lines) = lines.as_ref() else {
|
|
78
|
+
return false;
|
|
79
|
+
};
|
|
80
|
+
let Some(line) = lines.get(previous_line) else {
|
|
81
|
+
return false;
|
|
82
|
+
};
|
|
83
|
+
if !suppression_matches(line, finding) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
self.used.insert(SuppressionKey {
|
|
87
|
+
path: display_path(&self.root, &path),
|
|
88
|
+
line: previous_line + 1,
|
|
89
|
+
});
|
|
90
|
+
true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fn stale_findings(&self) -> Vec<Finding> {
|
|
94
|
+
self.directives
|
|
95
|
+
.iter()
|
|
96
|
+
.filter(|(key, _)| !self.used.contains(key))
|
|
97
|
+
.map(|(key, directive)| stale_finding(key, directive))
|
|
98
|
+
.collect()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fn missing_reason_findings(&self) -> Vec<Finding> {
|
|
102
|
+
self.directives
|
|
103
|
+
.iter()
|
|
104
|
+
.filter(|(_, directive)| !directive.has_reason)
|
|
105
|
+
.map(|(key, directive)| missing_reason_finding(key, directive))
|
|
106
|
+
.collect()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
fn collect_directives(
|
|
111
|
+
root: &Path,
|
|
112
|
+
path: &Path,
|
|
113
|
+
lines: &[String],
|
|
114
|
+
directives: &mut BTreeMap<SuppressionKey, SuppressionDirective>,
|
|
115
|
+
) {
|
|
116
|
+
let display = display_path(root, path);
|
|
117
|
+
for (index, line) in lines.iter().enumerate() {
|
|
118
|
+
if let Some(suppression) = parse_suppression(line) {
|
|
119
|
+
directives.insert(
|
|
120
|
+
SuppressionKey {
|
|
121
|
+
path: display.clone(),
|
|
122
|
+
line: index + 1,
|
|
123
|
+
},
|
|
124
|
+
SuppressionDirective {
|
|
125
|
+
column: line.find("//").unwrap_or_default(),
|
|
126
|
+
text: line.trim().to_owned(),
|
|
127
|
+
has_reason: suppression.has_reason,
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
fn stale_finding(key: &SuppressionKey, directive: &SuppressionDirective) -> Finding {
|
|
135
|
+
Finding {
|
|
136
|
+
rule_id: "dart-decimate/stale-suppression".to_owned(),
|
|
137
|
+
fingerprint: Some(format!("stale-suppression:{}:{}", key.path, key.line)),
|
|
138
|
+
kind: FindingKind::StaleSuppression,
|
|
139
|
+
severity: Severity::Error,
|
|
140
|
+
message: format!(
|
|
141
|
+
"Suppression no longer matches a finding: {}",
|
|
142
|
+
directive.text
|
|
143
|
+
),
|
|
144
|
+
path: key.path.clone(),
|
|
145
|
+
line: key.line,
|
|
146
|
+
column: directive.column,
|
|
147
|
+
safe_to_delete: true,
|
|
148
|
+
files: Vec::new(),
|
|
149
|
+
edge: None,
|
|
150
|
+
actions: vec![
|
|
151
|
+
FindingAction::new(
|
|
152
|
+
"remove-suppression",
|
|
153
|
+
"Remove the unused suppression comment",
|
|
154
|
+
true,
|
|
155
|
+
)
|
|
156
|
+
.with_target_path(key.path.clone())
|
|
157
|
+
.with_suppression_comment(directive.text.clone()),
|
|
158
|
+
],
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fn missing_reason_finding(key: &SuppressionKey, directive: &SuppressionDirective) -> Finding {
|
|
163
|
+
Finding {
|
|
164
|
+
rule_id: "dart-decimate/missing-suppression-reason".to_owned(),
|
|
165
|
+
fingerprint: Some(format!(
|
|
166
|
+
"missing-suppression-reason:{}:{}",
|
|
167
|
+
key.path, key.line
|
|
168
|
+
)),
|
|
169
|
+
kind: FindingKind::MissingSuppressionReason,
|
|
170
|
+
severity: Severity::Error,
|
|
171
|
+
message: format!("Suppression must include a reason: {}", directive.text),
|
|
172
|
+
path: key.path.clone(),
|
|
173
|
+
line: key.line,
|
|
174
|
+
column: directive.column,
|
|
175
|
+
safe_to_delete: false,
|
|
176
|
+
files: Vec::new(),
|
|
177
|
+
edge: None,
|
|
178
|
+
actions: vec![
|
|
179
|
+
FindingAction::new(
|
|
180
|
+
"document-suppression",
|
|
181
|
+
"Add a short reason after the suppression comment",
|
|
182
|
+
false,
|
|
183
|
+
)
|
|
184
|
+
.with_target_path(key.path.clone())
|
|
185
|
+
.with_suppression_comment(format!(
|
|
186
|
+
"{} -- explain why this is intentional",
|
|
187
|
+
directive.text
|
|
188
|
+
)),
|
|
189
|
+
],
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
fn finding_path(root: &Path, path: &str) -> PathBuf {
|
|
194
|
+
let path = Path::new(path);
|
|
195
|
+
if path.is_absolute() {
|
|
196
|
+
path.to_path_buf()
|
|
197
|
+
} else {
|
|
198
|
+
root.join(path)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
fn read_lines(path: &Path) -> Option<Vec<String>> {
|
|
203
|
+
fs::read_to_string(path)
|
|
204
|
+
.ok()
|
|
205
|
+
.map(|source| source.lines().map(str::to_owned).collect())
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
fn suppression_matches(line: &str, finding: &Finding) -> bool {
|
|
209
|
+
let Some(suppression) = parse_suppression(line) else {
|
|
210
|
+
return false;
|
|
211
|
+
};
|
|
212
|
+
let rules = suppression.rules;
|
|
213
|
+
rules.is_empty() || rules.iter().any(|rule| rule_matches(rule, finding))
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
217
|
+
struct ParsedSuppression {
|
|
218
|
+
rules: Vec<String>,
|
|
219
|
+
has_reason: bool,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fn parse_suppression(line: &str) -> Option<ParsedSuppression> {
|
|
223
|
+
let comment = line.trim_start().strip_prefix("//")?.trim_start();
|
|
224
|
+
for directive in ["dart-decimate-ignore-next-line"] {
|
|
225
|
+
if let Some(rest) = comment.strip_prefix(directive)
|
|
226
|
+
&& rest.chars().next().is_none_or(char::is_whitespace)
|
|
227
|
+
{
|
|
228
|
+
let (rules, reason) = split_reason(rest.trim_start());
|
|
229
|
+
return Some(ParsedSuppression {
|
|
230
|
+
rules: rules
|
|
231
|
+
.split(|character: char| character == ',' || character.is_whitespace())
|
|
232
|
+
.filter(|rule| !rule.is_empty())
|
|
233
|
+
.map(str::to_owned)
|
|
234
|
+
.collect(),
|
|
235
|
+
has_reason: reason.is_some_and(|value| !value.trim().is_empty()),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
None
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
fn split_reason(rest: &str) -> (&str, Option<&str>) {
|
|
243
|
+
if let Some(index) = rest.find("--") {
|
|
244
|
+
return (&rest[..index], Some(&rest[index + 2..]));
|
|
245
|
+
}
|
|
246
|
+
if let Some(reason) = rest.strip_prefix("because ") {
|
|
247
|
+
return ("", Some(reason));
|
|
248
|
+
}
|
|
249
|
+
if let Some(index) = rest.find(" because ") {
|
|
250
|
+
return (&rest[..index], Some(&rest[index + " because ".len()..]));
|
|
251
|
+
}
|
|
252
|
+
if let Some(reason) = rest.strip_prefix("reason:") {
|
|
253
|
+
return ("", Some(reason));
|
|
254
|
+
}
|
|
255
|
+
if let Some(index) = rest.find(" reason:") {
|
|
256
|
+
return (&rest[..index], Some(&rest[index + " reason:".len()..]));
|
|
257
|
+
}
|
|
258
|
+
(rest, None)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
fn rule_matches(rule: &str, finding: &Finding) -> bool {
|
|
262
|
+
rule == "all"
|
|
263
|
+
|| rule == finding.rule_id
|
|
264
|
+
|| finding
|
|
265
|
+
.rule_id
|
|
266
|
+
.rsplit('/')
|
|
267
|
+
.next()
|
|
268
|
+
.is_some_and(|rule_id| rule == rule_id)
|
|
269
|
+
|| rule == kind_key(finding.kind)
|
|
270
|
+
|| security_rule_matches(rule, finding)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
fn security_rule_matches(rule: &str, finding: &Finding) -> bool {
|
|
274
|
+
finding.kind == FindingKind::SecurityCandidate
|
|
275
|
+
&& (rule == "security-sink"
|
|
276
|
+
|| (rule == "hardcoded-secret" && finding.rule_id.ends_with("hardcoded-secret")))
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const fn kind_key(kind: FindingKind) -> &'static str {
|
|
280
|
+
match kind {
|
|
281
|
+
FindingKind::DeadFile => "dead-file",
|
|
282
|
+
FindingKind::UnusedExport => "unused-export",
|
|
283
|
+
FindingKind::UnusedType => "unused-type",
|
|
284
|
+
FindingKind::PrivateTypeLeak => "private-type-leak",
|
|
285
|
+
FindingKind::UnusedEnumMember => "unused-enum-member",
|
|
286
|
+
FindingKind::UnusedClassMember => "unused-class-member",
|
|
287
|
+
FindingKind::DuplicateExport => "duplicate-export",
|
|
288
|
+
FindingKind::RouteCollision => "route-collision",
|
|
289
|
+
FindingKind::PrivateWidgetClass => "private-widget-class",
|
|
290
|
+
FindingKind::WidgetTopLevelFunctionBoundary => "widget-top-level-function-boundary",
|
|
291
|
+
FindingKind::UnusedWidgetParam => "unused-widget-param",
|
|
292
|
+
FindingKind::UnrenderedWidget => "unrendered-widget",
|
|
293
|
+
FindingKind::MissingContextMountedAfterAwait => "missing-context-mounted-after-await",
|
|
294
|
+
FindingKind::MissingEntryPoint => "missing-entry-point",
|
|
295
|
+
FindingKind::CircularDependency => "circular-dependency",
|
|
296
|
+
FindingKind::ReExportCycle => "re-export-cycle",
|
|
297
|
+
FindingKind::BoundaryViolation => "boundary-violation",
|
|
298
|
+
FindingKind::BoundaryCoverage => "boundary-coverage",
|
|
299
|
+
FindingKind::BoundaryCallViolation => "boundary-call-violation",
|
|
300
|
+
FindingKind::PolicyViolation => "policy-violation",
|
|
301
|
+
FindingKind::UnresolvedDependency => "unresolved-dependency",
|
|
302
|
+
FindingKind::PartOfViolation => "part-of-violation",
|
|
303
|
+
FindingKind::UnusedDependency => "unused-dependency",
|
|
304
|
+
FindingKind::UnusedDevDependency => "unused-dev-dependency",
|
|
305
|
+
FindingKind::TestOnlyDependency => "test-only-dependency",
|
|
306
|
+
FindingKind::UnusedDependencyOverride => "unused-dependency-override",
|
|
307
|
+
FindingKind::MisconfiguredDependencyOverride => "misconfigured-dependency-override",
|
|
308
|
+
FindingKind::UnlistedDependency => "unlisted-dependency",
|
|
309
|
+
FindingKind::PrivateSrcImport => "private-src-import",
|
|
310
|
+
FindingKind::CodeDuplication => "code-duplication",
|
|
311
|
+
FindingKind::HighCyclomaticComplexity => "high-cyclomatic-complexity",
|
|
312
|
+
FindingKind::HighCognitiveComplexity => "high-cognitive-complexity",
|
|
313
|
+
FindingKind::HighComplexity => "high-complexity",
|
|
314
|
+
FindingKind::CoverageGap => "coverage-gap",
|
|
315
|
+
FindingKind::HighCrapScore => "high-crap-score",
|
|
316
|
+
FindingKind::HealthHotspot => "health-hotspot",
|
|
317
|
+
FindingKind::RefactoringTarget => "refactoring-target",
|
|
318
|
+
FindingKind::FeatureFlag => "feature-flag",
|
|
319
|
+
FindingKind::SecurityCandidate => "security-candidate",
|
|
320
|
+
FindingKind::StaleSuppression => "stale-suppression",
|
|
321
|
+
FindingKind::MissingSuppressionReason => "missing-suppression-reason",
|
|
322
|
+
}
|
|
323
|
+
}
|