Skip to content

Commit bb45446

Browse files
authored
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
1 parent 6806535 commit bb45446

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

cli/tools/fmt.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,8 @@ fn collect_fmt_files(
221221
files: FilePatterns,
222222
) -> Result<Vec<PathBuf>, AnyError> {
223223
FileCollector::new(|e| {
224-
cli_options.ext_flag().as_ref().is_some_and(|ext| {
225-
is_supported_ext_fmt(Path::new(&format!("placeholder.{ext}")))
226-
}) || is_supported_ext_fmt(e.path)
227-
|| e.path.extension().is_none()
224+
is_supported_ext_fmt(e.path)
225+
|| (e.path.extension().is_none() && cli_options.ext_flag().is_some())
228226
})
229227
.ignore_git_folder()
230228
.ignore_node_modules()

cli/tools/lint/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,8 @@ fn collect_lint_files(
430430
files: FilePatterns,
431431
) -> Result<Vec<PathBuf>, AnyError> {
432432
FileCollector::new(|e| {
433-
cli_options.ext_flag().as_ref().is_some_and(|ext| {
434-
is_script_ext(Path::new(&format!("placeholder.{ext}")))
435-
}) || is_script_ext(e.path)
436-
|| e.path.extension().is_none()
433+
is_script_ext(e.path)
434+
|| (e.path.extension().is_none() && cli_options.ext_flag().is_some())
437435
})
438436
.ignore_git_folder()
439437
.ignore_node_modules()

tests/specs/fmt/default_ts/__test__.jsonc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
},
1313
"extensionless": {
1414
"args": "fmt extensionless",
15+
"output": "error: No target files found.\n",
16+
"exitCode": 1
17+
},
18+
"extensionless_with_flag": {
19+
"args": "fmt --ext=ts extensionless",
1520
"output": "Checked 1 file\n"
1621
}
1722
}

tests/specs/lint/default_ts/__test__.jsonc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
},
1313
"extensionless": {
1414
"args": "lint extensionless",
15+
"output": "error: No target files found.\n",
16+
"exitCode": 1
17+
},
18+
"extensionless_with_flag": {
19+
"args": "lint --ext=ts extensionless",
1520
"output": "Checked 1 file\n"
1621
}
1722
}

0 commit comments

Comments
 (0)