Skip to content

Commit 3240075

Browse files
kylehgcclaude
andcommitted
fix(lint): guard known linter names from the on-disk path check, bound failure passthrough
Two amendments from the reviewer pass on the adopted upstream rtk-ai#3567: - detect_linter: the exists() check no longer overrides a name the dispatch table special-cases, so a vendored `biome` directory cannot silently reroute `rtk lint biome check` through ESLint. - filter_generic_lint: the failed-run passthrough is bounded at passthrough_max_chars like the sibling fallbacks; tee keeps the full raw on disk. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent cae0f21 commit 3240075

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

‎src/cmds/js/lint_cmd.rs‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ fn detect_linter(args: &[String]) -> (&str, bool) {
8888
|| args[0].contains('/')
8989
|| args[0].contains('.');
9090

91-
if is_path_or_flag || std::path::Path::new(&args[0]).exists() {
91+
// A name the dispatch table special-cases keeps its linter meaning even
92+
// when a file or directory of the same name exists in cwd — otherwise a
93+
// vendored `biome` directory would silently reroute `rtk lint biome
94+
// check` through ESLint.
95+
let known_linter =
96+
!args.is_empty() && (is_python_linter(&args[0]) || matches!(args[0].as_str(), "eslint" | "biome"));
97+
98+
if is_path_or_flag || (!known_linter && std::path::Path::new(&args[0]).exists()) {
9299
("eslint", false)
93100
} else {
94101
(&args[0], true)
@@ -477,7 +484,9 @@ fn filter_generic_lint(output: &str, succeeded: bool) -> String {
477484

478485
if errors == 0 && warnings == 0 {
479486
if !succeeded {
480-
return output.trim().to_string();
487+
// Bound the shown copy like the sibling fallbacks; tee keeps the
488+
// full raw on disk.
489+
return truncate(output.trim(), config::limits().passthrough_max_chars);
481490
}
482491
return "Lint: No issues found".to_string();
483492
}
@@ -738,6 +747,28 @@ mod tests {
738747
assert!(explicit);
739748
}
740749

750+
/// Amendment: a vendored file or directory named after a known linter
751+
/// must not reroute an explicit invocation through ESLint.
752+
#[test]
753+
fn detect_linter_keeps_known_linter_name_even_when_it_exists_on_disk() {
754+
let dir = std::path::Path::new("biome");
755+
let created = !dir.exists();
756+
if created {
757+
std::fs::create_dir(dir).expect("create biome dir");
758+
}
759+
760+
let args: Vec<String> = vec!["biome".into(), "check".into()];
761+
let (linter, explicit) = detect_linter(&args);
762+
let result = (linter.to_string(), explicit);
763+
764+
if created {
765+
std::fs::remove_dir(dir).expect("remove biome dir");
766+
}
767+
768+
assert_eq!(result.0, "biome");
769+
assert!(result.1);
770+
}
771+
741772
/// Regression: pnpm reports a missing command without the word "error",
742773
/// and in the user's locale. Both counters stayed at zero and the run was
743774
/// summarized as clean although the linter never started.

0 commit comments

Comments
 (0)