Skip to content

Commit

Permalink
fix: don't include extensionless files in file collection for lint & …
Browse files Browse the repository at this point in the history
…fmt by default (#25721)

When using the `ext` flag, it will still attempt formatting them with
the provided extension
  • Loading branch information
crowlKats authored Sep 19, 2024
1 parent 6806535 commit bb45446
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 2 additions & 4 deletions cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions cli/tools/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/fmt/default_ts/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/lint/default_ts/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down

0 comments on commit bb45446

Please sign in to comment.