diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 47acdc9ee0..72746f4233 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -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] diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index d4002984a1..6afcb90af2 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -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| { let config = get_typescript_config(); diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs index 165f32233a..2f31c88d60 100644 --- a/cli/tools/lint.rs +++ b/cli/tools/lint.rs @@ -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();