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 RuboCop offences #1104

Merged
merged 64 commits into from Jun 9, 2019

Conversation

@pirj
Copy link
Contributor

commented Mar 8, 2019

I've kept the commits separate for easier review, with descriptive commit messages where I had to make a decision that needs explanation.

Tried to keep the changes minimal, picking the style matching the code the most (specifically with %-literals and spaces inside brackets).

RuboCop version update is better to be done simultaneously with the other rspec-* repositories since a number of rules are changed/renamed/removed, so I decided not to do that in the scope of this pull request.

@pirj pirj force-pushed the pirj:fix-rubocop-offences branch 4 times, most recently from 1498387 to f137a31 Mar 8, 2019

@JonRowe
Copy link
Member

left a comment

Went through this commit by commit, so feedback generally applies to the rules in the commit. (wow mega PR was mega!)

Show resolved Hide resolved lib/rspec/matchers.rb Outdated
Show resolved Hide resolved .rubocop.yml Outdated
Show resolved Hide resolved .rubocop.yml Outdated
Show resolved Hide resolved .rubocop.yml Outdated
Show resolved Hide resolved spec/rspec/matchers/built_in/change_spec.rb
Show resolved Hide resolved spec/rspec/matchers/built_in/include_spec.rb
Show resolved Hide resolved .rubocop.yml
Show resolved Hide resolved spec/rspec/matchers/built_in/raise_error_spec.rb Outdated
Show resolved Hide resolved spec/rspec/matchers/dsl_spec.rb
Show resolved Hide resolved spec/rspec/matchers/dsl_spec.rb
@pirj
Copy link
Contributor Author

left a comment

Will address the review shortly.
A couple of questions on how to proceed below.

Show resolved Hide resolved .rubocop.yml
Show resolved Hide resolved .rubocop.yml
Show resolved Hide resolved .rubocop.yml Outdated
Show resolved Hide resolved .rubocop.yml Outdated
Show resolved Hide resolved .rubocop.yml Outdated
Show resolved Hide resolved spec/rspec/matchers/built_in/change_spec.rb
Show resolved Hide resolved spec/rspec/matchers/built_in/include_spec.rb
Show resolved Hide resolved spec/rspec/matchers/dsl_spec.rb
Show resolved Hide resolved spec/rspec/matchers/dsl_spec.rb
Show resolved Hide resolved spec/rspec/matchers/dsl_spec.rb Outdated

@pirj pirj force-pushed the pirj:fix-rubocop-offences branch from c7c9f6c to ef35e56 Mar 10, 2019

@pirj
Copy link
Contributor Author

left a comment

Addressed the notes with no questions, squashed with the previous commits, changed commit messages where appropriate.

Please take a look at the remaining questions when you have a moment.

Show resolved Hide resolved .rubocop.yml
@benoittgt
Copy link
Member

left a comment

I am not sure various self removed are an issue if the test suite pass. This is not a blocker for me.

I would have added the link to the update/pr or specified version when disabling a Cop. For example here:

             self.a_method_not_in_the_example == "method defined in the example" # rubocop:disable Style/RedundantSelf RuboCop bug, should disappear on version update.

Like you did here

      # rubocop:disable Layout/EmptyLinesAroundArguments This is a RuboCop bug, and it's fixed in 0.65.0

But as the first point, this is not a blocker to accept this PR.

Lot's of work. 😅
Thanks for it

@pirj

This comment has been minimized.

Copy link
Contributor Author

commented Mar 14, 2019

@benoittgt Thanks for the review.
Unfortunately, Style/RedundantSelf is not fixed in latest RuboCop, I temporarily updated to 0.65, it still detects where it shouldn't, and doesn't detect where it should, so I hope to re-evaluate and remove local disabling when it's fixed in RuboCop.

@pirj pirj force-pushed the pirj:fix-rubocop-offences branch from 805b5b9 to 028deeb Mar 14, 2019

@pirj

This comment has been minimized.

Copy link
Contributor Author

commented Mar 14, 2019

@JonRowe Addressed a couple more remarks.

Appreciate if you check out a few of the remaining questions that I have: 1, 2, 3.

@pirj

This comment has been minimized.

Copy link
Contributor Author

commented Mar 29, 2019

@JonRowe I'm up for changing the code either way, please let me know what you think.

@JonRowe

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

@pirj Sorry I'm very busy at the moment, I promise this is high on my list to re-review I very much appreciate your time taken here!

@pirj

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2019

@JonRowe A friendly reminder. There are just three questions left (1, 2, 3), I'm up to change it the way you see fit.

My further plan is to:

  • perform fix the offences in the other RSpec repositories
  • update RuboCop version to the latest
  • extract common parts to rspec-dev's common .rubocop.yml

I'll stick to the practice I used here with the other repositories - reduce the code churn and disable the rules that would require massive codebase change.
This might take a while considering the effort to review those changes, I hope for your support in those changes.

@JonRowe

This comment has been minimized.

Copy link
Member

commented May 17, 2019

Just a fix required to your "1" and a green build and this can be merged. Thanks so much for your patience here @pirj

pirj added some commits Feb 25, 2019

Specify target Ruby version for RuboCop
Even though the aim is to provide 1.8+ support, RuboCop of the bundled
version only supports versions 2.1-2.5.

This reduces the severity of the following offence:

rspec-expectations.gemspec:30:29: C: Gemspec/RequiredRubyVersion: required_ruby_version (1.8, declared in rspec-expectations.gemspec) and TargetRubyVersion (2.5, declared in .rubocop.yml) should be equal.
  s.required_ruby_version = '>= 1.8.7'
                            ^^^^^^^^^^
Set FrozenStringLiteralComment style to never
`frozen_string_literal` is not used anywhere in the code, only adding
the noise (~200 offenses) in the RuboCop check.
Fix percent literal related offences
Specifically:
 - Style/PercentLiteralDelimiters
 - Style/UnneededPercentQ
 - Style/BarePercentLiterals

And find common ground for the usages to minimize the change.
Disable Gemfile cops
They doesn't seem to cut it in a Gemfile with conditionals
Fix Style/SpaceInsideBlockBraces offences
Use default styles for Style/SpaceInsideBlockBraces
Disable Style/BlockComments cop
There's a really long explanation in the benchmark code. The diff size
is intolerable.
Disable Layout/AlignParameters locally
Even though this cop is coming from rspec-dev's default RuboCop
settings, in this repository it's kind of cumbersome to enforce either
of the styles the cop can enforce.

pirj added some commits Mar 7, 2019

Explicitly denote that the code is unreachable
It's quite obvious anyway from looking at the code, though it is a
balancing example and deserves to remain as is. However, instead of
excluding this file in .rubocop.yml, it makes sense to additionally
denote that the code is unreachable in the code itself.
Fix Style/MethodCallWithoutArgsParentheses offences
Also, this changes reverts fdd9ef3, for which the warnings should not
appear anymore (see https://bugs.ruby-lang.org/issues/10661).
Exclude ignored paths from RuboCop checks
Aruba creates some tmp files that don't pass the checks. Also, git
ignored bin folder (of an unknown origin, probably part of how rspec-dev
checks out and initializes repositories) contains a number of offences.

    bin/bundle:34:25: C: Style/PerlBackrefs: Avoid the use of Perl-style backrefs.
                            ^^
    bin/bundle:89:187: C: Metrics/LineLength: Line is too long. [190/186]

    tmp/aruba/rspec_expectations_spec.rb:48:4: C: Layout/TrailingBlankLines: Final newline missing.

It doesn't make sense to fix them, since those files are not meant to be
committable.

@pirj pirj force-pushed the pirj:fix-rubocop-offences branch from 2b4e1ed to c304482 May 18, 2019

pirj added a commit to pirj/rspec-expectations that referenced this pull request May 21, 2019

Simplify regression test
The test was a bit confusing.
The point of it is that if a `matches?` is defined, and `===` is not
defined, it should not be used as an argument matcher.

rspec#1104 (comment)

pirj added some commits Mar 8, 2019

Tell RuboCop to check all files
Previously CI check was only checking `lib` directory
Locally disable Layout/EmptyLinesAroundArguments
It is a bug in RuboCop 0.52.1, fixed in 0.65.0
Adding a local disabling, since newer RuboCop will report an
unnecessary disabling, and it could be spotted and removed.
Simplify regression test
The test was a bit confusing.
The point of it is that if a `matches?` is defined, and `===` is not
defined, it should not be used as an argument matcher.

#1104 (comment)

@pirj pirj force-pushed the pirj:fix-rubocop-offences branch from eb1e325 to 8d877a8 May 21, 2019

@pirj

This comment has been minimized.

Copy link
Contributor Author

commented May 28, 2019

@JonRowe Addressed the remaining issue. Please take another look.

@benoittgt

This comment has been minimized.

Copy link
Member

commented May 29, 2019

I reviewed last commits. LGTM. Thanks for the hard work @pirj

@pirj

This comment has been minimized.

Copy link
Contributor Author

commented Jun 3, 2019

@JonRowe Please take another look.

@JonRowe

JonRowe approved these changes Jun 9, 2019

@JonRowe JonRowe merged commit 23c11fc into rspec:master Jun 9, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@JonRowe

This comment has been minimized.

Copy link
Member

commented Jun 9, 2019

Thanks @pirj !

@pirj pirj deleted the pirj:fix-rubocop-offences branch Jun 9, 2019

@pirj

This comment has been minimized.

Copy link
Contributor Author

commented Jun 9, 2019

Thanks for accepting @JonRowe !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.