fix(linter): only write fix results if source code has changed (#6096)

Closes #6061.

Read [this reply](https://github.com/oxc-project/oxc/issues/6061#issuecomment-2378226722) for context.
This commit is contained in:
DonIsaac 2024-09-27 02:14:27 +00:00
parent 418ae25f3d
commit 6c855affa3
2 changed files with 4 additions and 2 deletions

View file

@ -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 {

View file

@ -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;
}