Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions apps/oxlint/fixtures/fix_argument/fix.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script>debugger;</script>
<script>debugger;</script>
7 changes: 6 additions & 1 deletion apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,12 @@ mod test {

#[test]
fn test_fix() {
Tester::test_fix("fixtures/linter/fix.js", "debugger\n", "\n");
Tester::test_fix("fixtures/fix_argument/fix.js", "debugger\n", "\n");
Tester::test_fix(
"fixtures/fix_argument/fix.vue",
"<script>debugger;</script>\n<script>debugger;</script>\n",
"<script></script>\n<script></script>\n",
);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ arguments: -A all fixtures/linter
working directory:
----------
Found 0 warnings and 0 errors.
Finished in <variable>ms on 4 files with 0 rules using 1 threads.
Finished in <variable>ms on 3 files with 0 rules using 1 threads.
----------
CLI result: LintSucceeded
----------
11 changes: 2 additions & 9 deletions apps/oxlint/src/snapshots/_fixtures__linter@oxlint.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ working directory:
`----
help: Remove the debugger statement

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
,-[fixtures/linter/fix.js:1:1]
1 | debugger
: ^^^^^^^^
`----
help: Remove the debugger statement

! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
,-[fixtures/linter/js_as_jsx.js:1:1]
1 | debugger;
Expand All @@ -35,8 +28,8 @@ working directory:
`----
help: Use the isNaN function to compare with NaN.

Found 4 warnings and 0 errors.
Finished in <variable>ms on 4 files with 87 rules using 1 threads.
Found 3 warnings and 0 errors.
Finished in <variable>ms on 3 files with 87 rules using 1 threads.
----------
CLI result: LintSucceeded
----------
13 changes: 9 additions & 4 deletions crates/oxc_linter/src/fixer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,10 @@ impl<'a> Message<'a> {
Self { error, span: Span::new(start, end), fixes, fixed: false }
}

/// move the offset of all spans to the right
/// move the offset of all spans (except fixes) to the right
/// for moving fixes use [`Message::move_fix_offset`].
pub fn move_offset(&mut self, offset: u32) -> &mut Self {
if offset == 0 {
return self;
}
debug_assert!(offset != 0);

self.span = self.span.move_right(offset);

Expand All @@ -306,6 +305,12 @@ impl<'a> Message<'a> {
}
}

self
}

pub fn move_fix_offset(&mut self, offset: u32) -> &mut Self {
debug_assert!(offset != 0);

match &mut self.fixes {
PossibleFixes::None => {}
PossibleFixes::Single(fix) => {
Expand Down
12 changes: 8 additions & 4 deletions crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl Runtime {

// clippy: the source field is checked and assumed to be less than 4GB, and
// we assume that the fix offset will not exceed 2GB in either direction
#[expect(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)]
#[expect(clippy::cast_possible_truncation, clippy::cast_possible_wrap)]
pub(super) fn run(&mut self, tx_error: &DiagnosticSender) {
rayon::scope(|scope| {
self.resolve_modules(scope, true, tx_error, |me, mut module_to_lint| {
Expand Down Expand Up @@ -544,7 +544,8 @@ impl Runtime {
let fix_result = Fixer::new(source_text, messages).fix();
if fix_result.fixed {
// write to file, replacing only the changed part
let start = fix_offset as usize;
let start =
section.source.start.saturating_add_signed(fix_offset) as usize;
let end = start + source_text.len();
new_source_text
.to_mut()
Expand Down Expand Up @@ -646,7 +647,9 @@ impl Runtime {
// adjust offset for multiple source text in a single file
if section.source.start != 0 {
for message in &mut section_messages {
message.move_offset(section.source.start);
message
.move_offset(section.source.start)
.move_fix_offset(section.source.start);
}
}

Expand Down Expand Up @@ -773,7 +776,8 @@ impl Runtime {
.into_iter()
.map(|mut message| {
if section.source.start != 0 {
message.move_offset(section.source.start);
message.move_offset(section.source.start)
.move_fix_offset(section.source.start);
}
message.clone_in(allocator)
}),
Expand Down
Loading