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

[Fix #6822] Fix Lint/LiteralInInterpolation autocorrection for single quotes #6979

Merged

Conversation

hoshinotsuyoshi
Copy link
Contributor

@hoshinotsuyoshi hoshinotsuyoshi commented Apr 26, 2019

Fixes #6822

Current behavior:

Doing $ rubocop --only Lint/LiteralInInterpolation;

source:

x = "ABC".gsub(/(A)(B)(C)/, "D#{'\2'}F")
"foo#{'\n'}bar"
"this is #{'"'} silly"

corrected to:

x = "ABC".gsub(/(A)(B)(C)/, "D\2F")
"foo\nbar"
"this is " silly"

New behavior:

corrected to:

x = "ABC".gsub(/(A)(B)(C)/, "D\\2F")
"foo\\nbar"
"this is \" silly"

  • 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.

… single quotes

  ## Current behavior:

  Doing `$ rubocop --only Lint/LiteralInInterpolation`;

  source:

  ```ruby
  x = "ABC".gsub(/(A)(B)(C)/, "D#{'\2'}F")
  "foo#{'\n'}bar"
  "this is #{'"'} silly"
  ```

  corrected to:

  ```ruby
  x = "ABC".gsub(/(A)(B)(C)/, "D\2F")
  "foo\nbar"
  "this is " silly"
  ```

  ## New behavior:

  corrected to:

  ```ruby
  x = "ABC".gsub(/(A)(B)(C)/, "D\\2F")
  "foo\\nbar"
  "this is \" silly"
  ```
@hoshinotsuyoshi hoshinotsuyoshi force-pushed the literal_in_interpolation_one_backslash branch from 69151d4 to 5849678 Compare April 27, 2019 00:07
@hoshinotsuyoshi
Copy link
Contributor Author

hoshinotsuyoshi commented Apr 27, 2019

force-pushed 69151d4 (using String#gsub) to 5849678 (using String#inspect) 🙏


I want to fix another pattern bug,

"this is #{'"'} silly"

corrected to (at latest rubocop);

"this is " silly"

new behavior, 5849678 correctly works;

"this is \" silly"

@hoshinotsuyoshi hoshinotsuyoshi changed the title [Fix #6822] Fix Lint/LiteralInInterpolation autocorrection for backslash in single quotes [Fix #6822] Fix Lint/LiteralInInterpolation autocorrection for single quotes Apr 27, 2019
@bbatsov bbatsov merged commit 557ad20 into rubocop:master Apr 29, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 29, 2019

Thanks!

@hoshinotsuyoshi hoshinotsuyoshi deleted the literal_in_interpolation_one_backslash branch April 30, 2019 14:06
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.

Autocorrection of Lint/LiteralInInterpolation changes code behaviour in regexes
2 participants