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 #11123 ] Fix auto correction bug for Style/StringLiterals #11144

Merged

Conversation

si-lens
Copy link
Contributor

@si-lens si-lens commented Nov 2, 2022

Fix: #11123

Before:

a = {
  b: "{\"[\\\"*\\\"]\""
}

was corrected to:

a = {
  b: '{"["*"]"'
}

These two strings are not the same.
After my changes it should result in correct string:

a = {
  b: '{"[\"*\"]"'
}

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@si-lens si-lens marked this pull request as ready for review November 2, 2022 09:16
@@ -93,7 +93,7 @@ def correct_quotes(str)
end

# The conversion process doubles escaped slashes, so they have to be reverted
correction.gsub('\\\\', '\\')
correction.gsub('\\\\', '\\').gsub('\"', '"')
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That change was made to keep this test passing. It was the only one to fail after the change was made in lib/rubocop/cop/util.rb

@koic
Copy link
Member

koic commented Nov 5, 2022

This looks good to me. Can you add a changelog entry? Please see the end of the PR check items for details.

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 11, 2022

@si-lens ping :-)

@si-lens si-lens force-pushed the fix_auto_correction_bug_for_Style/StringLiterals branch from 94b5862 to 7facde9 Compare November 12, 2022 13:02
@si-lens
Copy link
Contributor Author

si-lens commented Nov 12, 2022

This looks good to me. Can you add a changelog entry? Please see the end of the PR check items for details.

Oh right, forgot about it!
There you go 😄

@@ -0,0 +1 @@
* [#11123](https://github.com/rubocop/rubocop/issues/11123): Fix autocorrection bug for `Style/StringLiterals` when using multiple escape characters. ([@si-lens][])
Copy link
Member

Choose a reason for hiding this comment

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

CI is failing. Can you insert the newline to make the test below pass?

% bundle exec rspec spec/project_spec.rb
(snip)

Failures:

  1) RuboCop Project Changelog future entries For /home/circleci/project/spec/../changelog/fix_auto_correction_bug_for_string_literals.md has newline at end of file
     Failure/Error: expect(changelog.end_with?("\n")).to be true

@si-lens si-lens force-pushed the fix_auto_correction_bug_for_Style/StringLiterals branch from 7facde9 to 45da59a Compare November 12, 2022 16:15
@koic koic merged commit 57e7c45 into rubocop:master Nov 12, 2022
@koic
Copy link
Member

koic commented Nov 12, 2022

Thanks!

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.

Incorrect auto-correction for Style/StringLiterals cop
3 participants