Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support autocorrection for Lint/InterpolationCheck #8164

Merged

Conversation

koic
Copy link
Member

@koic koic commented Jun 18, 2020

This PR supports autocorrection for Lint/InterpolationCheck and marks it unsafe because autocorrected code is incompatible.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the support_autocorrect_for_lint_interpolation_check branch from ebfdf94 to 73dcb7f Compare June 18, 2020 23:33
def autocorrect(node)
lambda do |corrector|
corrector.replace(node.loc.begin, '"')
corrector.replace(node.loc.end, '"')
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this will fail when correcting a string like '"#{}"'. it may also change the output of a string like %{\{#{}} (where what once was a string that equaled "{" it's now equal to "\{". These are guesses without running it though

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I updated to use %{...} if a offending string contains double quoted strings.

@koic koic force-pushed the support_autocorrect_for_lint_interpolation_check branch from 73dcb7f to 6d988d7 Compare June 24, 2020 03:28
This PR supports autocorrection for `Lint/InterpolationCheck` and
marks it unsafe because autocorrected code is incompatible.
@koic koic force-pushed the support_autocorrect_for_lint_interpolation_check branch from 6d988d7 to fba655f Compare June 27, 2020 11:12
@bbatsov bbatsov merged commit 426b148 into rubocop:master Jun 27, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 27, 2020

Thanks!

@koic koic deleted the support_autocorrect_for_lint_interpolation_check branch June 27, 2020 13:34
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.

None yet

3 participants