Skip to content

Commit

Permalink
fix(linter): only write fix results if source code has changed (#6096)
Browse files Browse the repository at this point in the history
Closes #6061.

Read [this reply](#6061 (comment)) for context.
  • Loading branch information
DonIsaac committed Sep 27, 2024
1 parent 418ae25 commit 6c855af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<'a> LintContext<'a> {
(Some(message), None) => diagnostic.with_help(message.to_owned()),
_ => diagnostic,
};
if self.parent.fix.can_apply(rule_fix.kind()) {
if self.parent.fix.can_apply(rule_fix.kind()) && !rule_fix.is_empty() {
let fix = rule_fix.into_fix(self.source_text());
self.add_diagnostic(Message::new(diagnostic, Some(fix)));
} else {
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ impl Runtime {
// TODO: Span is wrong, ban this feature for file process by `PartialLoader`.
if !is_processed_by_partial_loader && self.linter.options().fix.is_some() {
let fix_result = Fixer::new(source_text, messages).fix();
fs::write(path, fix_result.fixed_code.as_bytes()).unwrap();
if fix_result.fixed {
fs::write(path, fix_result.fixed_code.as_bytes()).unwrap();
}
messages = fix_result.messages;
}

Expand Down

0 comments on commit 6c855af

Please sign in to comment.