mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix: lint and fmt error if no target files are found (#9527)
This commit is contained in:
parent
555595e6d0
commit
91881b7cd3
3 changed files with 31 additions and 7 deletions
|
@ -537,7 +537,9 @@ mod integration {
|
||||||
.expect("Failed to spawn script")
|
.expect("Failed to spawn script")
|
||||||
.wait()
|
.wait()
|
||||||
.expect("Failed to wait for child process");
|
.expect("Failed to wait for child process");
|
||||||
assert!(status.success());
|
// No target files found
|
||||||
|
assert!(!status.success());
|
||||||
|
|
||||||
// Check without ignore.
|
// Check without ignore.
|
||||||
let status = util::deno_cmd()
|
let status = util::deno_cmd()
|
||||||
.current_dir(util::root_path())
|
.current_dir(util::root_path())
|
||||||
|
@ -551,6 +553,7 @@ mod integration {
|
||||||
.wait()
|
.wait()
|
||||||
.expect("Failed to wait for child process");
|
.expect("Failed to wait for child process");
|
||||||
assert!(!status.success());
|
assert!(!status.success());
|
||||||
|
|
||||||
// Format the source file.
|
// Format the source file.
|
||||||
let status = util::deno_cmd()
|
let status = util::deno_cmd()
|
||||||
.current_dir(util::root_path())
|
.current_dir(util::root_path())
|
||||||
|
@ -4986,6 +4989,7 @@ console.log("finish");
|
||||||
fn lint_ignore_unexplicit_files() {
|
fn lint_ignore_unexplicit_files() {
|
||||||
let output = util::deno_cmd()
|
let output = util::deno_cmd()
|
||||||
.current_dir(util::root_path())
|
.current_dir(util::root_path())
|
||||||
|
.env("NO_COLOR", "1")
|
||||||
.arg("lint")
|
.arg("lint")
|
||||||
.arg("--unstable")
|
.arg("--unstable")
|
||||||
.arg("--ignore=./")
|
.arg("--ignore=./")
|
||||||
|
@ -4994,14 +4998,18 @@ console.log("finish");
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(output.status.success());
|
assert!(!output.status.success());
|
||||||
assert_eq!(output.stderr, b"Checked 0 file\n");
|
assert_eq!(
|
||||||
|
String::from_utf8_lossy(&output.stderr),
|
||||||
|
"error: No target files found.\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fmt_ignore_unexplicit_files() {
|
fn fmt_ignore_unexplicit_files() {
|
||||||
let output = util::deno_cmd()
|
let output = util::deno_cmd()
|
||||||
.current_dir(util::root_path())
|
.current_dir(util::root_path())
|
||||||
|
.env("NO_COLOR", "1")
|
||||||
.arg("fmt")
|
.arg("fmt")
|
||||||
.arg("--check")
|
.arg("--check")
|
||||||
.arg("--ignore=./")
|
.arg("--ignore=./")
|
||||||
|
@ -5010,8 +5018,11 @@ console.log("finish");
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(output.status.success());
|
assert!(!output.status.success());
|
||||||
assert_eq!(output.stderr, b"Checked 0 file\n");
|
assert_eq!(
|
||||||
|
String::from_utf8_lossy(&output.stderr),
|
||||||
|
"error: No target files found.\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -37,7 +37,13 @@ pub async fn format(
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let target_file_resolver = || {
|
let target_file_resolver = || {
|
||||||
// collect the files that are to be formatted
|
// collect the files that are to be formatted
|
||||||
collect_files(&args, &ignore, is_supported_ext_fmt)
|
collect_files(&args, &ignore, is_supported_ext_fmt).and_then(|files| {
|
||||||
|
if files.is_empty() {
|
||||||
|
Err(generic_error("No target files found."))
|
||||||
|
} else {
|
||||||
|
Ok(files)
|
||||||
|
}
|
||||||
|
})
|
||||||
};
|
};
|
||||||
let operation = |paths: Vec<PathBuf>| {
|
let operation = |paths: Vec<PathBuf>| {
|
||||||
let config = get_typescript_config();
|
let config = get_typescript_config();
|
||||||
|
|
|
@ -47,7 +47,14 @@ pub async fn lint_files(
|
||||||
if args.len() == 1 && args[0].to_string_lossy() == "-" {
|
if args.len() == 1 && args[0].to_string_lossy() == "-" {
|
||||||
return lint_stdin(json);
|
return lint_stdin(json);
|
||||||
}
|
}
|
||||||
let target_files = collect_files(&args, &ignore, is_supported_ext)?;
|
let target_files =
|
||||||
|
collect_files(&args, &ignore, is_supported_ext).and_then(|files| {
|
||||||
|
if files.is_empty() {
|
||||||
|
Err(generic_error("No target files found."))
|
||||||
|
} else {
|
||||||
|
Ok(files)
|
||||||
|
}
|
||||||
|
})?;
|
||||||
debug!("Found {} files", target_files.len());
|
debug!("Found {} files", target_files.len());
|
||||||
let target_files_len = target_files.len();
|
let target_files_len = target_files.len();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue