mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 15:19:40 -05:00
refactor(cli): simplify lint/format resolver logic (#12898)
This commit is contained in:
parent
4a13c320d7
commit
bd989143e1
2 changed files with 39 additions and 42 deletions
|
@ -87,35 +87,34 @@ pub async fn format(
|
||||||
let resolver = |changed: Option<Vec<PathBuf>>| {
|
let resolver = |changed: Option<Vec<PathBuf>>| {
|
||||||
let files_changed = changed.is_some();
|
let files_changed = changed.is_some();
|
||||||
|
|
||||||
let collect_files =
|
let result =
|
||||||
collect_files(&include_files, &exclude_files, is_supported_ext_fmt);
|
collect_files(&include_files, &exclude_files, is_supported_ext_fmt).map(
|
||||||
|
|files| {
|
||||||
let (result, should_refmt) = match collect_files {
|
let refmt_files = if let Some(paths) = changed {
|
||||||
Ok(value) => {
|
if check {
|
||||||
if let Some(paths) = changed {
|
files
|
||||||
let refmt_files = value
|
.iter()
|
||||||
.clone()
|
.any(|path| paths.contains(path))
|
||||||
.into_iter()
|
.then(|| files)
|
||||||
.filter(|path| paths.contains(path))
|
.unwrap_or_else(|| [].to_vec())
|
||||||
.collect::<Vec<_>>();
|
} else {
|
||||||
|
files
|
||||||
let should_refmt = !refmt_files.is_empty();
|
.into_iter()
|
||||||
|
.filter(|path| paths.contains(path))
|
||||||
if check {
|
.collect::<Vec<_>>()
|
||||||
(Ok((value, fmt_options.clone())), Some(should_refmt))
|
}
|
||||||
} else {
|
} else {
|
||||||
(Ok((refmt_files, fmt_options.clone())), Some(should_refmt))
|
files
|
||||||
}
|
};
|
||||||
} else {
|
(refmt_files, fmt_options.clone())
|
||||||
(Ok((value, fmt_options.clone())), None)
|
},
|
||||||
}
|
);
|
||||||
}
|
|
||||||
Err(e) => (Err(e), None),
|
|
||||||
};
|
|
||||||
|
|
||||||
let paths_to_watch = include_files.clone();
|
let paths_to_watch = include_files.clone();
|
||||||
async move {
|
async move {
|
||||||
if files_changed && matches!(should_refmt, Some(false)) {
|
if files_changed
|
||||||
|
&& matches!(result, Ok((ref files, _)) if files.is_empty())
|
||||||
|
{
|
||||||
ResolutionResult::Ignore
|
ResolutionResult::Ignore
|
||||||
} else {
|
} else {
|
||||||
ResolutionResult::Restart {
|
ResolutionResult::Restart {
|
||||||
|
|
|
@ -112,27 +112,25 @@ pub async fn lint(
|
||||||
|
|
||||||
let resolver = |changed: Option<Vec<PathBuf>>| {
|
let resolver = |changed: Option<Vec<PathBuf>>| {
|
||||||
let files_changed = changed.is_some();
|
let files_changed = changed.is_some();
|
||||||
let collect_files =
|
let result =
|
||||||
collect_files(&include_files, &exclude_files, is_supported_ext);
|
collect_files(&include_files, &exclude_files, is_supported_ext).map(
|
||||||
|
|files| {
|
||||||
|
if let Some(paths) = changed {
|
||||||
|
files
|
||||||
|
.iter()
|
||||||
|
.any(|path| paths.contains(path))
|
||||||
|
.then(|| files)
|
||||||
|
.unwrap_or_else(|| [].to_vec())
|
||||||
|
} else {
|
||||||
|
files
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let paths_to_watch = include_files.clone();
|
let paths_to_watch = include_files.clone();
|
||||||
|
|
||||||
let (result, should_relint) = match collect_files {
|
|
||||||
Ok(value) => {
|
|
||||||
if let Some(paths) = changed {
|
|
||||||
(
|
|
||||||
Ok(value.clone()),
|
|
||||||
Some(value.iter().any(|path| paths.contains(path))),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(Ok(value), None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => (Err(e), None),
|
|
||||||
};
|
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
if files_changed && matches!(should_relint, Some(false)) {
|
if files_changed && matches!(result, Ok(ref files) if files.is_empty()) {
|
||||||
ResolutionResult::Ignore
|
ResolutionResult::Ignore
|
||||||
} else {
|
} else {
|
||||||
ResolutionResult::Restart {
|
ResolutionResult::Restart {
|
||||||
|
|
Loading…
Reference in a new issue