Skip to content
Merged
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
25 changes: 22 additions & 3 deletions crates/oxc_linter/src/rules/jest/valid_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ fn validate_title(
if !valid_title.ignore_space && trimmed_title != title {
let (error, help) = Message::AccidentalSpace.detail();
ctx.diagnostic_with_fix(valid_title_diagnostic(error, help, span), |fixer| {
fixer.replace(span.shrink(1), trimmed_title.to_string())
let inner_span = span.shrink(1);
let raw_text = fixer.source_range(inner_span);
let trimmed_raw = raw_text.trim().to_string();
fixer.replace(inner_span, trimmed_raw)
});
}

Expand All @@ -399,8 +402,14 @@ fn validate_title(
if first_word == un_prefixed_name {
let (error, help) = Message::DuplicatePrefix.detail();
ctx.diagnostic_with_fix(valid_title_diagnostic(error, help, span), |fixer| {
let replaced_title = title[first_word.len()..].trim().to_string();
fixer.replace(span.shrink(1), replaced_title)
// Use raw source text to preserve escape sequences
let inner_span = span.shrink(1);
let raw_text = fixer.source_range(inner_span);
// Find the first space in raw text to avoid byte offset issues
// if the prefix word ever contains escapable characters
let space_pos = raw_text.find(' ').unwrap_or(raw_text.len());
let replaced_raw = raw_text[space_pos..].trim().to_string();
fixer.replace(inner_span, replaced_raw)
});
return;
}
Expand Down Expand Up @@ -1136,6 +1145,16 @@ fn test() {
})
",
),
// AccidentalSpace: preserve escape sequences when trimming spaces
(
"test('issue #225513: Cmd-Click doesn\\'t work on JSDoc {@link URL|LinkText} format ', () => { assert(true); });",
"test('issue #225513: Cmd-Click doesn\\'t work on JSDoc {@link URL|LinkText} format', () => { assert(true); });",
),
// DuplicatePrefix: preserve escape sequences when removing prefix
(
"test('test that it doesn\\'t break', () => {});",
"test('that it doesn\\'t break', () => {});",
),
];

Tester::new(ValidTitle::NAME, ValidTitle::PLUGIN, pass, fail)
Expand Down
Loading