Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions src/discover/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,16 @@ fn rewrite_segment_inner(
// Try each rewrite prefix (longest first) with word-boundary check
for &prefix in rule.rewrite_prefixes {
if let Some(rest) = strip_word_prefix(strip_target, prefix) {
let rewritten = if rest.is_empty() {
format!("{}{}", rule.rtk_cmd, redirect_suffix)
} else {
format!("{} {}{}", rule.rtk_cmd, rest, redirect_suffix)
let explicit_linter = explicit_linter_from_prefix(rule.rtk_cmd, prefix);
let rewritten = match (explicit_linter, rest.is_empty()) {
(Some(linter), true) => {
format!("{} {}{}", rule.rtk_cmd, linter, redirect_suffix)
}
(Some(linter), false) => {
format!("{} {} {}{}", rule.rtk_cmd, linter, rest, redirect_suffix)
}
(None, true) => format!("{}{}", rule.rtk_cmd, redirect_suffix),
(None, false) => format!("{} {}{}", rule.rtk_cmd, rest, redirect_suffix),
};
return Some(rewritten);
}
Expand All @@ -972,6 +978,17 @@ fn rewrite_segment_inner(
None
}

fn explicit_linter_from_prefix<'a>(rtk_cmd: &str, prefix: &'a str) -> Option<&'a str> {
if rtk_cmd != "rtk lint" {
return None;
}

match prefix.split_whitespace().last() {
Some(linter @ ("biome" | "eslint")) => Some(linter),
_ => None,
}
}

/// Strip a command prefix with word-boundary check.
/// Returns the remainder of the command after the prefix, or `None` if no match.
fn strip_word_prefix<'a>(cmd: &'a str, prefix: &str) -> Option<&'a str> {
Expand Down Expand Up @@ -2966,15 +2983,37 @@ mod tests {
"lint",
];
for command in commands {
let linter = command.split_whitespace().last().unwrap();
let expected = match linter {
"biome" | "eslint" => format!("rtk lint {linter}"),
"lint" => "rtk lint".to_string(),
_ => unreachable!(),
};
assert_eq!(
rewrite_command_no_prefixes(command, &[]),
Some("rtk lint".into()),
Some(expected),
"Failed for command: {}",
command
);
}
}

#[test]
fn test_rewrite_lint_preserves_explicit_linter_arguments() {
assert_eq!(
rewrite_command_no_prefixes("pnpm exec biome ci .", &[]),
Some("rtk lint biome ci .".into())
);
assert_eq!(
rewrite_command_no_prefixes("pnpm exec eslint --version", &[]),
Some("rtk lint eslint --version".into())
);
assert_eq!(
rewrite_command_no_prefixes("RAYON_NUM_THREADS=2 pnpm exec biome ci .", &[]),
Some("RAYON_NUM_THREADS=2 rtk lint biome ci .".into())
);
}

#[test]
fn test_classify_jest() {
let commands = vec![
Expand Down