Skip to content

Automatically correct certain violations - #241

Merged
jpsim merged 20 commits into
masterfrom
jp-autocorrect
Dec 6, 2015
Merged

jpsim merged 20 commits into
masterfrom
jp-autocorrect

Conversation

@jpsim

@jpsim jpsim commented Nov 28, 2015

Copy link
Copy Markdown
Collaborator

This is a first stab at #5. Not super helpful at the moment because there's no reporting of what was corrected, which we'll want to add before merging this in edit: done.

Since this sets the direction for future autocorrect behavior, feedback is greatly appreciated!

Turns out this is kind of tricky to do in a robust way. Specifically: modifying files on disk can cause previous violation offsets to become invalid, or new violations to be created, or previous violations to vanish. For this reason, I've opted for --autocorrect to not lint in the normal sense, not reporting any violations.

Remaining:

  • Report corrections
  • Don't perform corrections if a rule is disabled globally via disabled_rules
  • Don't perform corrections if a rule is disabled locally via // swiftlint:disable
  • Decide if a dedicated autocorrect command is preferable to an --autocorrect flag on the lint command (requires moving a lot more of the logic currently in swiftlint.LintCommand into SwiftLintFramework.Linter, which is probably a good thing to do anyway)

@jpsim
jpsim force-pushed the jp-autocorrect branch 4 times, most recently from d743035 to da1ddbc Compare November 30, 2015 10:00
@jpsim

jpsim commented Dec 1, 2015

Copy link
Copy Markdown
Collaborator Author

@keith it'd be great to get your feedback on this one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of keeping a separate list we have to maintain we could flatMap enabled rules from the configuration as? CorrectableRule ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, I think that should work.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoa, much nicer.

@keith

keith commented Dec 1, 2015

Copy link
Copy Markdown
Contributor

I'm totally on board with this approach!

@keith

keith commented Dec 1, 2015

Copy link
Copy Markdown
Contributor

Re the last check mark, I think I'd prefer a separate autocorrect command. I feel like it's a big enough of a difference it's worth being separate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want this to be in the standard lib 😞

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file a 📡 !

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:trollface:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this method being used by the regex matchers. Since NSString is based around UTF-16 code units and not grapheme clusters, wouldn't this give wrong results for certain kinds of strings?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! 😱 I just fixed this. Nice catch!

@jpsim

jpsim commented Dec 6, 2015

Copy link
Copy Markdown
Collaborator Author

@keith when you get the chance, I'd love your input on #253 and this one, which has now been rebased on top of that visitor PR. Now autocorrect has a dedicated command. Damn that was a lot of work to do right.

@jpsim jpsim changed the title [WIP] Automatically correct certain violations Automatically correct certain violations Dec 6, 2015
@keith

keith commented Dec 6, 2015

Copy link
Copy Markdown
Contributor

:shipit:

@jpsim

jpsim commented Dec 6, 2015

Copy link
Copy Markdown
Collaborator Author

Thanks for reviewing, @keith!

jpsim added a commit that referenced this pull request Dec 6, 2015
Automatically correct certain violations
@jpsim
jpsim merged commit 9e1d981 into master Dec 6, 2015
@jpsim
jpsim deleted the jp-autocorrect branch December 6, 2015 21:31
@Gerst20051

Copy link
Copy Markdown

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants