You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rules that have fixers for some cases, but not others, all have some logic that looks like this:
fnrun<'a>(&self,ctx:&LintContext<'a>){// Check for a violationlet diagnostic = create_diagnostic_for_rule();let can_fix = check_if_fixable();// <-- this is problematicif can_fix {
ctx.diagnostic_with_fix(diagnostic, |fixer| do_fix(ctx, fixer, node));}else{
ctx.diagnostic(diagnostic);}}
This pushes a lot of fixing logic outside of the fixer. In cases where --fix is not used, these are all wasted cycles. If we move fixability checks to inside the fixer's closure, we can prevent rules from doing work that just gets thrown away.
fnrun<'a>(&self,ctx:&LintContext<'a>){// Check for a violationlet diagnostic = create_diagnostic_for_rule();
ctx.diagnostic_with_fix(diagnostic, |fixer| {if !check_if_fixable(ctx, fixer, node){returnNone;}returndo_fix(ctx, fixer, node);});}
The text was updated successfully, but these errors were encountered:
DonIsaac
changed the title
feat(linter): Let fixer functions decide whether to apply a fix or not
refactor(linter): Let fixer functions decide whether to apply a fix or not
Jul 11, 2024
Part of #4187.
Adds `CompositeFix::None`, which enables fixer functions to decide not to fix some code.
While I was in the area, I took the liberty of adding some doc comments.
Rules that have fixers for some cases, but not others, all have some logic that looks like this:
This pushes a lot of fixing logic outside of the fixer. In cases where
--fix
is not used, these are all wasted cycles. If we move fixability checks to inside the fixer's closure, we can prevent rules from doing work that just gets thrown away.The text was updated successfully, but these errors were encountered: