From bb45446fa763b077f705971ca091008febab0794 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Thu, 19 Sep 2024 02:25:48 -0700 Subject: [PATCH] fix: don't include extensionless files in file collection for lint & fmt by default (#25721) When using the `ext` flag, it will still attempt formatting them with the provided extension --- cli/tools/fmt.rs | 6 ++---- cli/tools/lint/mod.rs | 6 ++---- tests/specs/fmt/default_ts/__test__.jsonc | 5 +++++ tests/specs/lint/default_ts/__test__.jsonc | 5 +++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 3f927545d9..a51a2dfc62 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -221,10 +221,8 @@ fn collect_fmt_files( files: FilePatterns, ) -> Result, AnyError> { FileCollector::new(|e| { - cli_options.ext_flag().as_ref().is_some_and(|ext| { - is_supported_ext_fmt(Path::new(&format!("placeholder.{ext}"))) - }) || is_supported_ext_fmt(e.path) - || e.path.extension().is_none() + is_supported_ext_fmt(e.path) + || (e.path.extension().is_none() && cli_options.ext_flag().is_some()) }) .ignore_git_folder() .ignore_node_modules() diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index a52d4e4625..e096b486ef 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -430,10 +430,8 @@ fn collect_lint_files( files: FilePatterns, ) -> Result, AnyError> { FileCollector::new(|e| { - cli_options.ext_flag().as_ref().is_some_and(|ext| { - is_script_ext(Path::new(&format!("placeholder.{ext}"))) - }) || is_script_ext(e.path) - || e.path.extension().is_none() + is_script_ext(e.path) + || (e.path.extension().is_none() && cli_options.ext_flag().is_some()) }) .ignore_git_folder() .ignore_node_modules() diff --git a/tests/specs/fmt/default_ts/__test__.jsonc b/tests/specs/fmt/default_ts/__test__.jsonc index 24d77a79ef..39772f5f80 100644 --- a/tests/specs/fmt/default_ts/__test__.jsonc +++ b/tests/specs/fmt/default_ts/__test__.jsonc @@ -12,6 +12,11 @@ }, "extensionless": { "args": "fmt extensionless", + "output": "error: No target files found.\n", + "exitCode": 1 + }, + "extensionless_with_flag": { + "args": "fmt --ext=ts extensionless", "output": "Checked 1 file\n" } } diff --git a/tests/specs/lint/default_ts/__test__.jsonc b/tests/specs/lint/default_ts/__test__.jsonc index ff0f342ab8..d7c618a5a7 100644 --- a/tests/specs/lint/default_ts/__test__.jsonc +++ b/tests/specs/lint/default_ts/__test__.jsonc @@ -12,6 +12,11 @@ }, "extensionless": { "args": "lint extensionless", + "output": "error: No target files found.\n", + "exitCode": 1 + }, + "extensionless_with_flag": { + "args": "lint --ext=ts extensionless", "output": "Checked 1 file\n" } }