-
Notifications
You must be signed in to change notification settings - Fork 885
Use --fix instead of -t applyFixes #1697
Conversation
1efd92d
to
c9511d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks pretty good. Can you also add a test for the CLI option?
@@ -47,5 +47,5 @@ export interface IFormatterMetadata { | |||
export type ConsumerType = "human" | "machine"; | |||
|
|||
export interface IFormatter { | |||
format(failures: RuleFailure[]): string; | |||
format(failures: RuleFailure[], fixes?: RuleFailure[]): string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the idea that fixes
are only supplied to this method if --fix
is enabled in the CLI? can you leave a comment explaining that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
@@ -50,6 +50,9 @@ let processed = optimist | |||
alias: "exclude", | |||
describe: "exclude globs from path expansion", | |||
}, | |||
fix: { | |||
describe: "Fixes some linting errors (may overwrite linted files)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"some" isn't great language -- can you just use the same description you have on L159
this.failures.push(ruleFailure); | ||
} | ||
// make a 2nd pass if there were any fixes because the positions may be off | ||
if (!this.options.fix || this.fixes.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first part of this conditional expression looks unintuitive to me -- don't you want to only continue if this.options.fix
is true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to run the linter at least once if fix
is false. Will try to clarify
@adidahiya made changes |
heads up @alexeagle |
PR checklist
--fix
instead of-t applyFixes
#1684What changes did you make?
When fixes are applied, they are applied first. If a rule triggers a fix, the AST is reloaded to prevent one fix from overwriting another fix. When all fixes are complete, the sourceFile is linted again if there were fixes. That way, we don't show errors that are already fixed and the positions will be correct.
here's what it looks like when using the prose formatter (the only formatter to output that there are fixes) when there is 1 issue fix and 1 remaining issue that can't be fixed: