Skip to content

Commit

Permalink
fix: lint and fmt error if no target files are found (denoland#9527)
Browse files Browse the repository at this point in the history
  • Loading branch information
magurotuna committed Feb 19, 2021
1 parent 555595e commit 91881b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
21 changes: 16 additions & 5 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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=./")
Expand All @@ -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=./")
Expand All @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion cli/tools/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 91881b7

Please sign in to comment.