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
package/src/scan.rs
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
+
use std::fs;
|
|
3
|
+
use std::path::{Path, PathBuf};
|
|
4
|
+
|
|
5
|
+
use glob::Pattern;
|
|
6
|
+
use rayon::prelude::*;
|
|
7
|
+
use serde::{Deserialize, Serialize};
|
|
8
|
+
use thiserror::Error;
|
|
9
|
+
|
|
10
|
+
use crate::graph::normalize_path;
|
|
11
|
+
use crate::package_map::PackageMap;
|
|
12
|
+
use crate::{
|
|
13
|
+
DartFile, ExtractError, GraphError, GraphOptions, ModuleGraph, build_module_graph_with_options,
|
|
14
|
+
extract_dart_file,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/// Parsed Dart files plus their resolved module graph.
|
|
18
|
+
#[derive(Debug)]
|
|
19
|
+
pub struct ScannedProject {
|
|
20
|
+
/// Root directory used for discovery and dependency resolution.
|
|
21
|
+
pub root: PathBuf,
|
|
22
|
+
/// Extracted Dart files, sorted by path for deterministic output.
|
|
23
|
+
pub files: Vec<DartFile>,
|
|
24
|
+
/// Directed graph built from the extracted files.
|
|
25
|
+
pub graph: ModuleGraph,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Options controlling Dart file discovery.
|
|
29
|
+
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
30
|
+
pub struct ScanOptions {
|
|
31
|
+
/// Glob patterns excluded from Dart file discovery.
|
|
32
|
+
pub ignore_patterns: Vec<String>,
|
|
33
|
+
/// Dart conditional URI environment values. Empty means include every branch.
|
|
34
|
+
pub conditional_environment: BTreeMap<String, String>,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Errors returned while scanning a Dart or Flutter project.
|
|
38
|
+
#[derive(Debug, Error)]
|
|
39
|
+
pub enum ScanError {
|
|
40
|
+
/// The current working directory could not be read.
|
|
41
|
+
#[error("failed to read current directory: {source}")]
|
|
42
|
+
CurrentDir {
|
|
43
|
+
/// Underlying IO error.
|
|
44
|
+
source: std::io::Error,
|
|
45
|
+
},
|
|
46
|
+
/// A directory could not be read.
|
|
47
|
+
#[error("failed to read directory {path}: {source}")]
|
|
48
|
+
ReadDir {
|
|
49
|
+
/// Directory path.
|
|
50
|
+
path: PathBuf,
|
|
51
|
+
/// Underlying IO error.
|
|
52
|
+
source: std::io::Error,
|
|
53
|
+
},
|
|
54
|
+
/// A directory entry could not be read.
|
|
55
|
+
#[error("failed to read directory entry under {path}: {source}")]
|
|
56
|
+
ReadDirEntry {
|
|
57
|
+
/// Directory being scanned.
|
|
58
|
+
path: PathBuf,
|
|
59
|
+
/// Underlying IO error.
|
|
60
|
+
source: std::io::Error,
|
|
61
|
+
},
|
|
62
|
+
/// A file type could not be read.
|
|
63
|
+
#[error("failed to read file type for {path}: {source}")]
|
|
64
|
+
FileType {
|
|
65
|
+
/// Entry path.
|
|
66
|
+
path: PathBuf,
|
|
67
|
+
/// Underlying IO error.
|
|
68
|
+
source: std::io::Error,
|
|
69
|
+
},
|
|
70
|
+
/// A pubspec could not be read while expanding local packages.
|
|
71
|
+
#[error("failed to read pubspec {path}: {source}")]
|
|
72
|
+
ReadPubspec {
|
|
73
|
+
/// Pubspec path.
|
|
74
|
+
path: PathBuf,
|
|
75
|
+
/// Underlying IO error.
|
|
76
|
+
source: std::io::Error,
|
|
77
|
+
},
|
|
78
|
+
/// A pubspec could not be parsed while expanding local packages.
|
|
79
|
+
#[error("failed to parse pubspec {path}: {source}")]
|
|
80
|
+
ParsePubspec {
|
|
81
|
+
/// Pubspec path.
|
|
82
|
+
path: PathBuf,
|
|
83
|
+
/// Underlying YAML parse error.
|
|
84
|
+
source: serde_yaml_ng::Error,
|
|
85
|
+
},
|
|
86
|
+
/// A pub workspace glob pattern was invalid.
|
|
87
|
+
#[error("invalid pub workspace glob pattern {pattern}: {source}")]
|
|
88
|
+
WorkspacePattern {
|
|
89
|
+
/// Invalid pattern.
|
|
90
|
+
pattern: String,
|
|
91
|
+
/// Underlying glob pattern error.
|
|
92
|
+
source: glob::PatternError,
|
|
93
|
+
},
|
|
94
|
+
/// A configured ignore glob pattern was invalid.
|
|
95
|
+
#[error("invalid ignore pattern {pattern}: {source}")]
|
|
96
|
+
IgnorePattern {
|
|
97
|
+
/// Invalid ignore pattern.
|
|
98
|
+
pattern: String,
|
|
99
|
+
/// Underlying glob pattern error.
|
|
100
|
+
source: glob::PatternError,
|
|
101
|
+
},
|
|
102
|
+
/// A pub workspace glob expansion failed.
|
|
103
|
+
#[error("failed to expand pub workspace glob {pattern}: {source}")]
|
|
104
|
+
WorkspaceGlob {
|
|
105
|
+
/// Pattern being expanded.
|
|
106
|
+
pattern: String,
|
|
107
|
+
/// Underlying glob error.
|
|
108
|
+
source: glob::GlobError,
|
|
109
|
+
},
|
|
110
|
+
/// A Dart file could not be parsed.
|
|
111
|
+
#[error(transparent)]
|
|
112
|
+
Extract(#[from] ExtractError),
|
|
113
|
+
/// A module graph could not be built.
|
|
114
|
+
#[error(transparent)]
|
|
115
|
+
Graph(#[from] GraphError),
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Discover, parse, and graph all `.dart` files under `root`.
|
|
119
|
+
///
|
|
120
|
+
/// Parsing is parallelized with Rayon after a deterministic filesystem walk.
|
|
121
|
+
///
|
|
122
|
+
/// # Errors
|
|
123
|
+
///
|
|
124
|
+
/// Returns [`ScanError`] when discovery, parsing, or graph construction fails.
|
|
125
|
+
pub fn scan_project(root: impl AsRef<Path>) -> Result<ScannedProject, ScanError> {
|
|
126
|
+
scan_project_with_options(root, &ScanOptions::default())
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// Discover, parse, and graph all non-ignored `.dart` files under `root`.
|
|
130
|
+
///
|
|
131
|
+
/// Parsing is parallelized with Rayon after a deterministic filesystem walk.
|
|
132
|
+
///
|
|
133
|
+
/// # Errors
|
|
134
|
+
///
|
|
135
|
+
/// Returns [`ScanError`] when discovery, parsing, or graph construction fails.
|
|
136
|
+
pub fn scan_project_with_options(
|
|
137
|
+
root: impl AsRef<Path>,
|
|
138
|
+
options: &ScanOptions,
|
|
139
|
+
) -> Result<ScannedProject, ScanError> {
|
|
140
|
+
let root = normalize_scan_root(root.as_ref())?;
|
|
141
|
+
let ignore_matcher = IgnoreMatcher::new(&options.ignore_patterns)?;
|
|
142
|
+
let mut scan_roots = BTreeSet::new();
|
|
143
|
+
scan_roots.insert(root.clone());
|
|
144
|
+
scan_roots.extend(PackageMap::discover(&root)?.local_roots());
|
|
145
|
+
|
|
146
|
+
let mut paths = BTreeSet::new();
|
|
147
|
+
for scan_root in &scan_roots {
|
|
148
|
+
discover_dart_files(&root, scan_root, &ignore_matcher, &mut paths)?;
|
|
149
|
+
}
|
|
150
|
+
let paths = paths.into_iter().collect::<Vec<_>>();
|
|
151
|
+
|
|
152
|
+
let mut files = paths
|
|
153
|
+
.par_iter()
|
|
154
|
+
.map(extract_dart_file)
|
|
155
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
156
|
+
files.sort_by(|left, right| left.path.cmp(&right.path));
|
|
157
|
+
|
|
158
|
+
let graph = build_module_graph_with_options(
|
|
159
|
+
&root,
|
|
160
|
+
&files,
|
|
161
|
+
&GraphOptions {
|
|
162
|
+
conditional_environment: options.conditional_environment.clone(),
|
|
163
|
+
},
|
|
164
|
+
)?;
|
|
165
|
+
|
|
166
|
+
Ok(ScannedProject { root, files, graph })
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fn normalize_scan_root(root: &Path) -> Result<PathBuf, ScanError> {
|
|
170
|
+
if root.is_absolute() {
|
|
171
|
+
return Ok(normalize_path(root));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let current_dir = std::env::current_dir().map_err(|source| ScanError::CurrentDir { source })?;
|
|
175
|
+
Ok(normalize_path(¤t_dir.join(root)))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
fn discover_dart_files(
|
|
179
|
+
root: &Path,
|
|
180
|
+
dir: &Path,
|
|
181
|
+
ignore_matcher: &IgnoreMatcher,
|
|
182
|
+
paths: &mut BTreeSet<PathBuf>,
|
|
183
|
+
) -> Result<(), ScanError> {
|
|
184
|
+
let entries = fs::read_dir(dir).map_err(|source| ScanError::ReadDir {
|
|
185
|
+
path: dir.to_path_buf(),
|
|
186
|
+
source,
|
|
187
|
+
})?;
|
|
188
|
+
|
|
189
|
+
for entry in entries {
|
|
190
|
+
let entry = entry.map_err(|source| ScanError::ReadDirEntry {
|
|
191
|
+
path: dir.to_path_buf(),
|
|
192
|
+
source,
|
|
193
|
+
})?;
|
|
194
|
+
let path = entry.path();
|
|
195
|
+
let file_type = entry.file_type().map_err(|source| ScanError::FileType {
|
|
196
|
+
path: path.clone(),
|
|
197
|
+
source,
|
|
198
|
+
})?;
|
|
199
|
+
|
|
200
|
+
if file_type.is_dir() {
|
|
201
|
+
if should_skip_dir(&path) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if ignore_matcher.matches(root, &path) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
discover_dart_files(root, &path, ignore_matcher, paths)?;
|
|
208
|
+
} else if file_type.is_file()
|
|
209
|
+
&& path.extension().is_some_and(|ext| ext == "dart")
|
|
210
|
+
&& !ignore_matcher.matches(root, &path)
|
|
211
|
+
{
|
|
212
|
+
paths.insert(normalize_path(&path));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
Ok(())
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
fn should_skip_dir(path: &Path) -> bool {
|
|
220
|
+
matches!(
|
|
221
|
+
path.file_name().and_then(|name| name.to_str()),
|
|
222
|
+
Some(".dart_tool" | ".git" | ".idea" | ".pub-cache" | "build" | "target")
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
#[derive(Debug, Clone)]
|
|
227
|
+
struct IgnoreMatcher {
|
|
228
|
+
patterns: Vec<Pattern>,
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
impl IgnoreMatcher {
|
|
232
|
+
fn new(patterns: &[String]) -> Result<Self, ScanError> {
|
|
233
|
+
let patterns = patterns
|
|
234
|
+
.iter()
|
|
235
|
+
.map(|pattern| {
|
|
236
|
+
Pattern::new(pattern).map_err(|source| ScanError::IgnorePattern {
|
|
237
|
+
pattern: pattern.clone(),
|
|
238
|
+
source,
|
|
239
|
+
})
|
|
240
|
+
})
|
|
241
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
242
|
+
Ok(Self { patterns })
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
fn matches(&self, root: &Path, path: &Path) -> bool {
|
|
246
|
+
if self.patterns.is_empty() {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
let normalized = normalize_path(path);
|
|
251
|
+
let relative = normalized.strip_prefix(root).unwrap_or(&normalized);
|
|
252
|
+
let relative_display = slash_path(relative);
|
|
253
|
+
let absolute_display = slash_path(&normalized);
|
|
254
|
+
|
|
255
|
+
self.patterns.iter().any(|pattern| {
|
|
256
|
+
pattern.matches_path(relative)
|
|
257
|
+
|| pattern.matches(&relative_display)
|
|
258
|
+
|| pattern.matches(&absolute_display)
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
fn slash_path(path: &Path) -> String {
|
|
264
|
+
path.components()
|
|
265
|
+
.filter_map(|component| match component {
|
|
266
|
+
std::path::Component::Normal(value) => value.to_str(),
|
|
267
|
+
std::path::Component::RootDir => Some(""),
|
|
268
|
+
_ => None,
|
|
269
|
+
})
|
|
270
|
+
.collect::<Vec<_>>()
|
|
271
|
+
.join("/")
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
#[cfg(test)]
|
|
275
|
+
mod tests;
|