summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-09-19 02:25:48 -0700
committerGitHub <noreply@github.com>2024-09-19 11:25:48 +0200
commitbb45446fa763b077f705971ca091008febab0794 (patch)
tree5f448cfe62b2656b4d575b7460b72b7064be5e7b
parent68065351dfeea5cb4c1ea630b02ae7455d416ed9 (diff)
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
-rw-r--r--cli/tools/fmt.rs6
-rw-r--r--cli/tools/lint/mod.rs6
-rw-r--r--tests/specs/fmt/default_ts/__test__.jsonc5
-rw-r--r--tests/specs/lint/default_ts/__test__.jsonc5
4 files changed, 14 insertions, 8 deletions
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 3f927545d..a51a2dfc6 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -221,10 +221,8 @@ fn collect_fmt_files(
files: FilePatterns,
) -> Result<Vec<PathBuf>, 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 a52d4e462..e096b486e 100644
--- a/cli/tools/lint/mod.rs
+++ b/cli/tools/lint/mod.rs
@@ -430,10 +430,8 @@ fn collect_lint_files(
files: FilePatterns,
) -> Result<Vec<PathBuf>, 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 24d77a79e..39772f5f8 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 ff0f342ab..d7c618a5a 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"
}
}