dart-decimate 0.0.4 → 0.0.6
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 +1 -1
- package/Cargo.toml +2 -4
- package/README.md +33 -14
- package/package.json +1 -1
- package/src/cli/common_args.rs +13 -2
- package/src/cli/decision_surface_run.rs +149 -11
- package/src/cli/default_command.rs +304 -6
- package/src/cli/error.rs +3 -0
- package/src/cli/error_output.rs +10 -2
- package/src/cli/html_open.rs +240 -0
- package/src/cli/inspect_run.rs +3 -0
- package/src/cli/output_format.rs +3 -0
- package/src/cli/tests.rs +90 -0
- package/src/cli/trace_run.rs +12 -0
- package/src/cli.rs +72 -8
- package/src/manifest.rs +30 -9
- package/src/output/html.rs +691 -0
- package/src/output/human.rs +503 -10
- package/src/output/human_details.rs +449 -0
- package/src/output.rs +3 -0
package/Cargo.lock
CHANGED
package/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "dart-decimate"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.6"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.85"
|
|
6
6
|
description = "Rust-native codebase intelligence for Dart and Flutter module graphs."
|
|
@@ -21,14 +21,12 @@ rayon = "1"
|
|
|
21
21
|
serde = { version = "1", features = ["derive"] }
|
|
22
22
|
serde_json = "1"
|
|
23
23
|
serde_yaml_ng = "0.10"
|
|
24
|
+
tempfile = "3"
|
|
24
25
|
thiserror = "2"
|
|
25
26
|
toml = "1.1"
|
|
26
27
|
tree-sitter = "0.26"
|
|
27
28
|
tree-sitter-dart = "0.2"
|
|
28
29
|
|
|
29
|
-
[dev-dependencies]
|
|
30
|
-
tempfile = "3"
|
|
31
|
-
|
|
32
30
|
[lints.rust]
|
|
33
31
|
unsafe_code = "forbid"
|
|
34
32
|
|
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ It answers practical questions:
|
|
|
36
36
|
Inside any Dart or Flutter project, run this:
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
npx --yes dart-decimate
|
|
39
|
+
npx --yes dart-decimate human .
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
That is the easiest command. It checks the whole repo for dead code, circular
|
|
@@ -44,14 +44,14 @@ dependencies, duplicated code, complex functions, dependency hygiene,
|
|
|
44
44
|
architecture drift, Flutter graph issues, security candidates, and PR-risk
|
|
45
45
|
signals.
|
|
46
46
|
|
|
47
|
-
For
|
|
47
|
+
For JSON output that agents and CI can parse:
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
|
-
npx --yes dart-decimate
|
|
50
|
+
npx --yes dart-decimate json .
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
If the report says `"verdict": "fail"`, Dart Decimate
|
|
54
|
-
error-level issues. It does not mean the tool crashed.
|
|
53
|
+
If the human report says `FAIL`, or JSON says `"verdict": "fail"`, Dart Decimate
|
|
54
|
+
worked. It means it found error-level issues. It does not mean the tool crashed.
|
|
55
55
|
|
|
56
56
|
Exit codes:
|
|
57
57
|
|
|
@@ -65,7 +65,7 @@ Exit codes:
|
|
|
65
65
|
You do not need to install anything permanently. Use `npx`:
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
npx --yes dart-decimate
|
|
68
|
+
npx --yes dart-decimate human .
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Add this to `package.json` if you want a short project command:
|
|
@@ -73,10 +73,10 @@ Add this to `package.json` if you want a short project command:
|
|
|
73
73
|
```json
|
|
74
74
|
{
|
|
75
75
|
"scripts": {
|
|
76
|
-
"dart-decimate": "dart-decimate
|
|
76
|
+
"dart-decimate": "dart-decimate json ."
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"dart-decimate": "^0.0.
|
|
79
|
+
"dart-decimate": "^0.0.6"
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
```
|
|
@@ -130,13 +130,32 @@ install.
|
|
|
130
130
|
Check everything:
|
|
131
131
|
|
|
132
132
|
```bash
|
|
133
|
-
npx --yes dart-decimate
|
|
133
|
+
npx --yes dart-decimate human .
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
Machine-readable JSON:
|
|
137
137
|
|
|
138
138
|
```bash
|
|
139
|
-
npx --yes dart-decimate
|
|
139
|
+
npx --yes dart-decimate json .
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Open the HTML report in your browser:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
npx --yes dart-decimate html .
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The `html` shortcut opens the report by default. On report commands, use
|
|
149
|
+
`--format html` to print static HTML or `--open` to write a private temporary
|
|
150
|
+
file and open it in the default browser.
|
|
151
|
+
|
|
152
|
+
Human terminal reports strip control characters from user-derived paths and
|
|
153
|
+
messages; HTML reports escape user-derived content.
|
|
154
|
+
|
|
155
|
+
Print the HTML report instead:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx --yes dart-decimate html . --stdout > dart-decimate-report.html
|
|
140
159
|
```
|
|
141
160
|
|
|
142
161
|
To run the GitHub version directly:
|
|
@@ -575,7 +594,7 @@ Add Dart Decimate to CI so every PR gets the same repo health check:
|
|
|
575
594
|
|
|
576
595
|
```yaml
|
|
577
596
|
- name: Dart Decimate
|
|
578
|
-
run: npx --yes dart-decimate
|
|
597
|
+
run: npx --yes dart-decimate json .
|
|
579
598
|
```
|
|
580
599
|
|
|
581
600
|
That is the easiest CI command. It checks everything Dart Decimate knows how to
|
|
@@ -593,7 +612,7 @@ You can also put the full check in a git hook:
|
|
|
593
612
|
mkdir -p .git/hooks
|
|
594
613
|
cat > .git/hooks/pre-commit <<'SH'
|
|
595
614
|
#!/usr/bin/env sh
|
|
596
|
-
npx --yes dart-decimate
|
|
615
|
+
npx --yes dart-decimate json .
|
|
597
616
|
SH
|
|
598
617
|
chmod +x .git/hooks/pre-commit
|
|
599
618
|
```
|
|
@@ -656,7 +675,7 @@ This repository forbids `unsafe_code`.
|
|
|
656
675
|
|
|
657
676
|
## Release Flow
|
|
658
677
|
|
|
659
|
-
Current version: `0.0.
|
|
678
|
+
Current version: `0.0.6`.
|
|
660
679
|
|
|
661
680
|
After the first public release, changes should go through pull requests.
|
|
662
681
|
|
package/package.json
CHANGED
package/src/cli/common_args.rs
CHANGED
|
@@ -5,6 +5,9 @@ use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
|
|
|
5
5
|
|
|
6
6
|
use super::regression_args::regression_command;
|
|
7
7
|
|
|
8
|
+
pub(super) const FORMAT_VALUES: [&str; 2] = ["human", "json"];
|
|
9
|
+
pub(super) const REPORT_FORMAT_VALUES: [&str; 4] = ["human", "html", "json", "sarif"];
|
|
10
|
+
|
|
8
11
|
pub(super) fn scan_command(command: Command) -> Command {
|
|
9
12
|
scan_command_with_format(command, format_arg())
|
|
10
13
|
}
|
|
@@ -13,6 +16,7 @@ pub(super) fn report_command(command: Command) -> Command {
|
|
|
13
16
|
super::scope_args::report_command(super::summary_args::summary_command(
|
|
14
17
|
scan_command_with_format(command, report_format_arg()),
|
|
15
18
|
))
|
|
19
|
+
.arg(open_arg())
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
fn scan_command_with_format(command: Command, format: Arg) -> Command {
|
|
@@ -70,11 +74,18 @@ pub(super) fn format_arg() -> Arg {
|
|
|
70
74
|
.value_name("FORMAT")
|
|
71
75
|
.help("Output format")
|
|
72
76
|
.default_value("human")
|
|
73
|
-
.value_parser(
|
|
77
|
+
.value_parser(FORMAT_VALUES)
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
fn report_format_arg() -> Arg {
|
|
77
|
-
format_arg().value_parser(
|
|
81
|
+
format_arg().value_parser(REPORT_FORMAT_VALUES)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn open_arg() -> Arg {
|
|
85
|
+
Arg::new("open")
|
|
86
|
+
.long("open")
|
|
87
|
+
.help("Write an HTML report to a temporary file and open its file:// URL in the default browser")
|
|
88
|
+
.action(ArgAction::SetTrue)
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
pub(super) fn config_arg() -> Arg {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
use std::io::Write;
|
|
2
2
|
|
|
3
|
-
use clap::{Arg, ArgMatches, Command, value_parser};
|
|
3
|
+
use clap::{Arg, ArgMatches, Command, parser::ValueSource, value_parser};
|
|
4
4
|
|
|
5
5
|
use crate::changed_scope::changed_files;
|
|
6
6
|
use crate::decision_surface::{
|
|
7
7
|
decision_surface_report_for_command, render_decision_surface_report,
|
|
8
8
|
};
|
|
9
|
+
use crate::output::render_decision_surface_html_report;
|
|
9
10
|
use crate::scan::{ScanOptions, scan_project_with_options};
|
|
10
11
|
|
|
11
12
|
use super::common_args::{config_arg, format_arg, root_arg, root_flag_arg, root_path};
|
|
12
|
-
use super::{CliError,
|
|
13
|
+
use super::{CliError, ReportOutputFormat, html_open};
|
|
13
14
|
|
|
14
15
|
pub(super) fn decision_surface_command() -> Command {
|
|
15
16
|
decision_surface_command_named(
|
|
@@ -54,8 +55,21 @@ fn decision_surface_command_named(name: &'static str, about: &'static str) -> Co
|
|
|
54
55
|
pub(super) fn run_decision_surface<W: Write>(
|
|
55
56
|
subcommand: &ArgMatches,
|
|
56
57
|
mut writer: W,
|
|
57
|
-
command: &str,
|
|
58
|
+
command: &'static str,
|
|
58
59
|
) -> Result<i32, CliError> {
|
|
60
|
+
run_decision_surface_with_opener(subcommand, &mut writer, command, html_open::open_url)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn run_decision_surface_with_opener<W, F>(
|
|
64
|
+
subcommand: &ArgMatches,
|
|
65
|
+
writer: &mut W,
|
|
66
|
+
command: &'static str,
|
|
67
|
+
opener: F,
|
|
68
|
+
) -> Result<i32, CliError>
|
|
69
|
+
where
|
|
70
|
+
W: Write,
|
|
71
|
+
F: FnOnce(&str) -> std::io::Result<()>,
|
|
72
|
+
{
|
|
59
73
|
let root = root_path(subcommand);
|
|
60
74
|
let config = super::load_config(&root, subcommand)?;
|
|
61
75
|
let project = scan_project_with_options(
|
|
@@ -76,24 +90,148 @@ pub(super) fn run_decision_surface<W: Write>(
|
|
|
76
90
|
let report =
|
|
77
91
|
decision_surface_report_for_command(&project, base, &changed, max_decisions, command);
|
|
78
92
|
|
|
79
|
-
match
|
|
80
|
-
|
|
93
|
+
match decision_surface_output_format(subcommand, command)? {
|
|
94
|
+
ReportOutputFormat::Human => {
|
|
81
95
|
writer.write_all(render_decision_surface_report(&report).as_bytes())?;
|
|
82
96
|
}
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
ReportOutputFormat::HtmlOpen => {
|
|
98
|
+
html_open::write_and_open_html_document_with(
|
|
99
|
+
&report.command,
|
|
100
|
+
&render_decision_surface_html_report(&report),
|
|
101
|
+
writer,
|
|
102
|
+
opener,
|
|
103
|
+
)?;
|
|
104
|
+
}
|
|
105
|
+
ReportOutputFormat::Html => {
|
|
106
|
+
writer.write_all(render_decision_surface_html_report(&report).as_bytes())?;
|
|
107
|
+
}
|
|
108
|
+
ReportOutputFormat::Json => {
|
|
109
|
+
serde_json::to_writer_pretty(&mut *writer, &report)?;
|
|
85
110
|
writeln!(writer)?;
|
|
86
111
|
}
|
|
112
|
+
ReportOutputFormat::Sarif => return Err(CliError::UnsupportedSarifFormat { command }),
|
|
87
113
|
}
|
|
88
114
|
Ok(0)
|
|
89
115
|
}
|
|
90
116
|
|
|
91
|
-
fn
|
|
92
|
-
|
|
117
|
+
fn decision_surface_output_format(
|
|
118
|
+
subcommand: &ArgMatches,
|
|
119
|
+
command: &'static str,
|
|
120
|
+
) -> Result<ReportOutputFormat, CliError> {
|
|
121
|
+
let format = match subcommand
|
|
93
122
|
.get_one::<String>("format")
|
|
94
123
|
.map_or("human", String::as_str)
|
|
95
124
|
{
|
|
96
|
-
"
|
|
97
|
-
|
|
125
|
+
"html" => ReportOutputFormat::Html,
|
|
126
|
+
"json" => ReportOutputFormat::Json,
|
|
127
|
+
"sarif" => ReportOutputFormat::Sarif,
|
|
128
|
+
_ => ReportOutputFormat::Human,
|
|
129
|
+
};
|
|
130
|
+
let open_html = subcommand
|
|
131
|
+
.try_get_one::<bool>("open")
|
|
132
|
+
.ok()
|
|
133
|
+
.flatten()
|
|
134
|
+
.copied()
|
|
135
|
+
.unwrap_or_default();
|
|
136
|
+
if !open_html {
|
|
137
|
+
return Ok(format);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let explicit_format = subcommand.value_source("format") == Some(ValueSource::CommandLine);
|
|
141
|
+
if explicit_format && format != ReportOutputFormat::Html {
|
|
142
|
+
return Err(CliError::HtmlOpenRequiresHtml);
|
|
143
|
+
}
|
|
144
|
+
if format == ReportOutputFormat::Sarif {
|
|
145
|
+
return Err(CliError::UnsupportedSarifFormat { command });
|
|
146
|
+
}
|
|
147
|
+
Ok(ReportOutputFormat::HtmlOpen)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#[cfg(test)]
|
|
151
|
+
mod tests {
|
|
152
|
+
use std::cell::RefCell;
|
|
153
|
+
use std::fs;
|
|
154
|
+
use std::process::Command;
|
|
155
|
+
|
|
156
|
+
use tempfile::TempDir;
|
|
157
|
+
|
|
158
|
+
use super::*;
|
|
159
|
+
|
|
160
|
+
#[test]
|
|
161
|
+
fn audit_brief_open_writes_html_and_opens_file_url() -> Result<(), Box<dyn std::error::Error>> {
|
|
162
|
+
let fixture = changed_dependency_fixture()?;
|
|
163
|
+
let matches = super::super::command().try_get_matches_from([
|
|
164
|
+
"dart-decimate",
|
|
165
|
+
"audit",
|
|
166
|
+
fixture.path().to_str().unwrap_or("."),
|
|
167
|
+
"--base",
|
|
168
|
+
"HEAD",
|
|
169
|
+
"--brief",
|
|
170
|
+
"--open",
|
|
171
|
+
])?;
|
|
172
|
+
let Some(("audit", subcommand)) = matches.subcommand() else {
|
|
173
|
+
panic!("audit subcommand");
|
|
174
|
+
};
|
|
175
|
+
let opened = RefCell::new(String::new());
|
|
176
|
+
let mut output = Vec::new();
|
|
177
|
+
|
|
178
|
+
let code =
|
|
179
|
+
run_decision_surface_with_opener(subcommand, &mut output, "audit --brief", |url| {
|
|
180
|
+
opened.replace(url.to_owned());
|
|
181
|
+
Ok(())
|
|
182
|
+
})?;
|
|
183
|
+
|
|
184
|
+
let opened = opened.into_inner();
|
|
185
|
+
let path = opened.strip_prefix("file://").unwrap_or(&opened);
|
|
186
|
+
let html = fs::read_to_string(path)?;
|
|
187
|
+
let message = String::from_utf8(output)?;
|
|
188
|
+
assert_eq!(code, 0);
|
|
189
|
+
assert!(opened.starts_with("file:///"));
|
|
190
|
+
assert!(message.contains("Opened HTML report: file:///"));
|
|
191
|
+
assert!(html.contains("<h1>audit --brief decision surface</h1>"));
|
|
192
|
+
assert!(html.contains("pubspec.yaml"));
|
|
193
|
+
Ok(())
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
fn changed_dependency_fixture() -> Result<TempDir, Box<dyn std::error::Error>> {
|
|
197
|
+
let fixture = tempfile::tempdir()?;
|
|
198
|
+
git(&fixture, ["init", "-q"])?;
|
|
199
|
+
git(
|
|
200
|
+
&fixture,
|
|
201
|
+
["config", "user.email", "dart-decimate@example.com"],
|
|
202
|
+
)?;
|
|
203
|
+
git(&fixture, ["config", "user.name", "Dart Decimate Tests"])?;
|
|
204
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
205
|
+
write(&fixture, "lib/main.dart", "void main() {}\n")?;
|
|
206
|
+
git(&fixture, ["add", "."])?;
|
|
207
|
+
git(&fixture, ["commit", "-m", "baseline", "-q"])?;
|
|
208
|
+
write(
|
|
209
|
+
&fixture,
|
|
210
|
+
"pubspec.yaml",
|
|
211
|
+
"name: app\ndependencies:\n http: ^1.0.0\n",
|
|
212
|
+
)?;
|
|
213
|
+
Ok(fixture)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
fn git<const N: usize>(
|
|
217
|
+
fixture: &TempDir,
|
|
218
|
+
args: [&str; N],
|
|
219
|
+
) -> Result<(), Box<dyn std::error::Error>> {
|
|
220
|
+
let output = Command::new("git")
|
|
221
|
+
.args(args)
|
|
222
|
+
.current_dir(fixture.path())
|
|
223
|
+
.output()?;
|
|
224
|
+
if output.status.success() {
|
|
225
|
+
return Ok(());
|
|
226
|
+
}
|
|
227
|
+
Err(String::from_utf8_lossy(&output.stderr).to_string().into())
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
|
|
231
|
+
let path = fixture.path().join(path);
|
|
232
|
+
if let Some(parent) = path.parent() {
|
|
233
|
+
fs::create_dir_all(parent)?;
|
|
234
|
+
}
|
|
235
|
+
fs::write(path, source)
|
|
98
236
|
}
|
|
99
237
|
}
|