1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix: lint and fmt error if no target files are found (#9527)

This commit is contained in:
Yusuke Tanaka 2021-02-19 21:18:16 +09:00 committed by GitHub
parent 555595e6d0
commit 91881b7cd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 7 deletions

View file

@ -537,7 +537,9 @@ mod integration {
.expect("Failed to spawn script")
.wait()
.expect("Failed to wait for child process");
assert!(status.success());
// No target files found
assert!(!status.success());
// Check without ignore.
let status = util::deno_cmd()
.current_dir(util::root_path())
@ -551,6 +553,7 @@ mod integration {
.wait()
.expect("Failed to wait for child process");
assert!(!status.success());
// Format the source file.
let status = util::deno_cmd()
.current_dir(util::root_path())
@ -4986,6 +4989,7 @@ console.log("finish");
fn lint_ignore_unexplicit_files() {
let output = util::deno_cmd()
.current_dir(util::root_path())
.env("NO_COLOR", "1")
.arg("lint")
.arg("--unstable")
.arg("--ignore=./")
@ -4994,14 +4998,18 @@ console.log("finish");
.unwrap()
.wait_with_output()
.unwrap();
assert!(output.status.success());
assert_eq!(output.stderr, b"Checked 0 file\n");
assert!(!output.status.success());
assert_eq!(
String::from_utf8_lossy(&output.stderr),
"error: No target files found.\n"
);
}
#[test]
fn fmt_ignore_unexplicit_files() {
let output = util::deno_cmd()
.current_dir(util::root_path())
.env("NO_COLOR", "1")
.arg("fmt")
.arg("--check")
.arg("--ignore=./")
@ -5010,8 +5018,11 @@ console.log("finish");
.unwrap()
.wait_with_output()
.unwrap();
assert!(output.status.success());
assert_eq!(output.stderr, b"Checked 0 file\n");
assert!(!output.status.success());
assert_eq!(
String::from_utf8_lossy(&output.stderr),
"error: No target files found.\n"
);
}
#[test]

View file

@ -37,7 +37,13 @@ pub async fn format(
) -> Result<(), AnyError> {
let target_file_resolver = || {
// 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 config = get_typescript_config();

View file

@ -47,7 +47,14 @@ pub async fn lint_files(
if args.len() == 1 && args[0].to_string_lossy() == "-" {
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());
let target_files_len = target_files.len();