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

Add new Style/RedundantHeredocDelimiterQuotes cop #11528

Conversation

koic
Copy link
Member

@koic koic commented Feb 1, 2023

Follow up #11522 (comment).

This cop checks for redundant heredoc delimiter quotes.

# bad
do_something(<<~'EOS')
  no string interpolation style text
EOS

# good
do_something(<<~EOS)
  no string interpolation style text
EOS

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.

# no string interpolation style text
# EOS
#
# # good
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably you should also add a good example for 'EOS', so it's a bit clearer when it should be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Certainly! I added some examples for that.

Follow up rubocop#11522 (comment).

This cop checks for redundant heredoc delimiter quotes.

```ruby
# bad
do_something(<<~'EOS')
  no string interpolation style text
EOS

# good
do_something(<<~EOS)
  no string interpolation style text
EOS
```
@koic koic force-pushed the add_new_style_redundant_heredoc_delimiter_quotes_cop branch from 0e97dc5 to f3d4931 Compare February 1, 2023 08:15
@bbatsov bbatsov merged commit 1b6aa94 into rubocop:master Feb 1, 2023
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 1, 2023

Pretty useful cop! Thanks!

@koic koic deleted the add_new_style_redundant_heredoc_delimiter_quotes_cop branch February 1, 2023 09:07
koic added a commit to rubocop/rubocop-rails that referenced this pull request Feb 1, 2023
Follow up rubocop/rubocop#11528.

This commit suppresses the following new `Style/RedundantHeredocDelimiterQuotes` cop's offenses:

```console
% bundle exec rake
(snip)

Offenses:

spec/rubocop/cop/rails/helper_instance_variable_spec.rb:31:24:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    expect_no_offenses(<<~'RUBY')
                       ^^^^^^^^^
spec/rubocop/cop/rails/helper_instance_variable_spec.rb:39:24:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    expect_no_offenses(<<~'RUBY')
                       ^^^^^^^^^
spec/rubocop/cop/rails/helper_instance_variable_spec.rb:50:24:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    expect_no_offenses(<<~'RUBY')
                       ^^^^^^^^^
spec/rubocop/cop/rails/helper_instance_variable_spec.rb:61:20:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    expect_offense(<<~'RUBY')
                   ^^^^^^^^^
spec/rubocop/cop/rails/match_route_spec.rb:110:24:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    expect_no_offenses(<<~'RUBY')
                       ^^^^^^^^^
spec/rubocop/cop/rails/reflection_class_name_spec.rb:57:24:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    expect_no_offenses(<<~'RUBY')
                       ^^^^^^^^^
spec/rubocop/cop/rails/reflection_class_name_spec.rb:63:24:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    expect_no_offenses(<<~'RUBY')
                       ^^^^^^^^^
spec/rubocop/cop/rails/root_pathname_methods_spec.rb:123:22:
C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
      expect_offense(<<~'RUBY')
                     ^^^^^^^^^

279 files inspected, 8 offenses detected, 8 offenses autocorrectable
```
koic added a commit to rubocop/rubocop-minitest that referenced this pull request Feb 1, 2023
Follow up rubocop/rubocop#11528.

This commit suppresses the following new `Style/RedundantHeredocDelimiterQuotes` cop's offenses:

```console
% bundle exec rake
(snip)

Offenses:

test/rubocop/cop/minitest/assert_with_expected_argument_test.rb:82:24: C: [Correctable] Style/RedundantHeredocDelimiterQuotes: Remove the redundant heredoc delimiter quotes, use <<~RUBY instead.
    assert_no_offenses(<<~'RUBY')
                       ^^^^^^^^^

121 files inspected, 1 offense detected, 1 offense autocorrectable
RuboCop failed!
```
extend AutoCorrector

MSG = 'Remove the redundant heredoc delimiter quotes, use `%<replacement>s` instead.'
STRING_INTERPOLATION_OR_ESCAPED_CHARACTER_PATTERN = /#(\{|@|\$)|\\/.freeze
Copy link
Contributor

@splattael splattael Feb 6, 2023

Choose a reason for hiding this comment

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

@koic #11543 adds a missing spec to test escapes - the last \\ in the regexp.

kachick added a commit to kachick/ruby-ulid that referenced this pull request Feb 8, 2023
@javierjulio
Copy link

@koic thanks! Since we picked up this release through Dependabot, I check the docs to find more info but I didn't see the rule there. I realize now that 1.45 isn't published on docs.rubocop.org where this was included. Only 1.44 is available.

@koic
Copy link
Member Author

koic commented Feb 11, 2023

@javierjulio The 1.45 doc is published. Thank you!
https://docs.rubocop.org/rubocop/1.45/index.html

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 11, 2023

My bad. As the process is manual and I constantly switch between computers from time to time I forget to do it when I release from the "wrong" computer (the one where I haven't setup Antora locally yet).

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 11, 2023

On the bright side - this finally motivated me to setup Node.js and Antora on my laptop as well. 😄

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

4 participants