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 #11122] Add new Style/RedundantLineContinuation cop #11694

Merged
merged 1 commit into from
Mar 31, 2023

Conversation

ydah
Copy link
Member

@ydah ydah commented Mar 13, 2023

Fix: #11122


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.

@koic
Copy link
Member

koic commented Mar 13, 2023

This cop should be able to detect various redundat \ cases such as:

def foo \
end

class Foo \
end

foo do \
end

and many cases.

@ydah ydah force-pushed the fix/11122 branch 2 times, most recently from f0f0605 to 3bbc00f Compare March 20, 2023 15:49
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 23, 2023

@ydah I see a lot of CI failures.

@ydah ydah changed the title [Fix #11122] Add new Style/RedundantLineContinuations cop [Fix #11122] Add new Style/RedundantLineContinuation cop Mar 23, 2023
@ydah ydah force-pushed the fix/11122 branch 3 times, most recently from 1231ba4 to 7e8b251 Compare March 23, 2023 16:51
@ydah
Copy link
Member Author

ydah commented Mar 23, 2023

Thank you so much for feedback. I updated this PR. on_new_investigation and added test cases and comments accordingly.

@ydah ydah force-pushed the fix/11122 branch 2 times, most recently from 32acd25 to bdebfef Compare March 24, 2023 06:19
@ydah
Copy link
Member Author

ydah commented Mar 25, 2023

Thank you for lots. I updated this PR.

ydah added a commit to ydah/rubocop that referenced this pull request Mar 25, 2023
@bbatsov bbatsov merged commit a677975 into rubocop:master Mar 31, 2023
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 31, 2023

Seems we're good to go here. Thanks!

@nobuyo
Copy link
Contributor

nobuyo commented Apr 3, 2023

In looking at the release notes for v1.49, I noticed that the changelog entry on this was missing 👀

@ydah ydah deleted the fix/11122 branch April 3, 2023 07:32
@ydah
Copy link
Member Author

ydah commented Apr 3, 2023

I also noticed that just now and opened the following PR.

@gsamokovarov
Copy link
Contributor

Here is an example of a false-positive case:

merged_document.public_url.should eq \
  "#{Settings.server.base_uri}/file_download?filename=graphql_receipts_merge%2Ftest1234"

Gets autocorrect to:

merged_document.public_url.should eq
"#{Settings.server.base_uri}/file_download?filename=graphql_receipts_merge%2Ftest1234"

This is interpreted as eq() by Ruby itself and fails my test.

merged_document.public_url.should eq()
"#{Settings.server.base_uri}/file_download?filename=graphql_receipts_merge%2Ftest1234"

I have to put parentheses to preserve the correct behaviour now, but I actually preferred omitting them in that case.

@koic
Copy link
Member

koic commented Apr 3, 2023

@gsamokovarov Thanks! I've opened #11752 to fix the false positive.

@frodsan
Copy link

frodsan commented Apr 3, 2023

I think there is a false positive:

def ==(other)
        foo == other.foo \
          && bar == other.bar \
          &&  baz == other.baz
end

I get the following after autocorrect:

F: Lint/Syntax: unexpected token tAMPER
(Using Ruby 3.2 parser; configure using TargetRubyVersion parameter, under AllCops)
        && bar == other.bar
def ==(other)
        foo == other.foo \
          && bar == other.bar
          &&  baz == other.baz
end

ydah added a commit to ydah/rubocop that referenced this pull request Apr 3, 2023
This PR is a follow-up of rubocop#11694.
Wrong method name was used in the cop.
@ydah
Copy link
Member Author

ydah commented Apr 3, 2023

@frodsan Thank you so much. I've opened #11754 to fix the false positive.

ydah added a commit to ydah/rubocop that referenced this pull request Apr 3, 2023
… `&&` and `||` with a multiline condition.

Follow up:  rubocop#11694 (comment)
This PR fixes a false positive for `Style/RedundantLineContinuation` when using `&&` and `||` with a multiline condition.
koic added a commit to koic/rubocop that referenced this pull request Apr 3, 2023
Follow up rubocop#11694 (comment)

This PR fixes a false positive for `Style/RedundantLineContinuation`
when using line concatenation and calling a method without parentheses.
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.

Cop idea: Check for unnecessary line continuations
6 participants