mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
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:
parent
418ae25f3d
commit
6c855affa3
2 changed files with 4 additions and 2 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue