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

Update rubocop to latest with Ruby 2.2 support #233

Closed
wants to merge 9 commits into from

Conversation

cupakromer
Copy link
Member

This updates Rubocop from 0.23.0 to 0.32.1 (most recent).

Unfortunately, in order to support this new version, which includes several bug fixes and support for Ruby 2.2, we need to drop support on Ruby 1.9.2. In fact Rubocop dropped 1.9.2 support as of version 0.25.0.

Some additional new cops are now available:

  • Metrics/AbcSize (Assignment Branch Condition)
  • Metrics/PerceivedComplexity

There are three additional new cops but they have been disabled (these settings should be ported to rspec-dev as part of the project defaults):

  • Lint/NonLocalExitFromIterator

    This has been disabled due it's inability to distinguish between when / where return is sent from within a block. For example, a DSL block which has an explicit return in a method definition triggers this cop:

    some_method do
      def a_local_method
        return if true # triggers cop even though `return` will not exit from the block
      end
    end
  • Style/ParallelAssignment

    Rubocop suggested this because it believed that parallel assignment was slower than sequential assignment. Unfortunately the benchmark they reference is flawed due to how Ruby handles implicit returns. It turns out that parallel assignment is faster.

  • Style/StringLiteralsInInterpolation

    We previously disabled the related cop Style/StringLiterals. We simply don't care about single vs double qoutes.

See also: rspec/rspec-dev#134

@cupakromer
Copy link
Member Author

😦 way too many builds. A bit tired so was thrashing trying to get the travis config working. Now that things are green, I'm grabbing a few hours of sleep and will get this cleaned up in the AM.

Also, I'm temporarily dumping the parallel-vs-sequential assignment and symbol-to-proc-vs-block benchmarks to stdout in the script/run_build. You can see how all of the different Ruby versions shape up in the last travis build: https://travis-ci.org/rspec/rspec-support/builds/73746126

I skimmed the benchmarks and it looks like the general trends are:

  • sequential assignment & blocks are faster on 1.8.7, REE, JRubys
  • parallel assignment & symbol-to-proc are faster on 1.9.2 through 2.2

There were a lot of numbers to skim over tonight, but I think the benchmarks show that sequential vs parallel assignment really doesn't matter much for us. So we can disable that cop and use what seems best for the situation.

As for the block vs symbol-to-proc, we just need to decide if / when we are going to start following the optimizations for the newer Rubies. Thoughts?

/cc @rspec/rspec

This also updates the travis setup to use the latest bundler. Travis
currently defaults to Bundler version 1.7.4, however, this bundler
version does not support the `platform: :ruby_22` configuration setting.
So we need to tell travis to install a more recent bundler.

Also, `platform: :ruby_19` applies to **both** 1.9.2 and 1.9.3. But
Rubocop stopped supporting 1.9.2. Thus we need to check the
`RUBY_VERSION` in our `Gemfile` and not attempt to install Rubocop
specifically for 1.9.2.

Unfortunately, this bundler does not work with JRuby (2.0 mode), but
does work with JRuby 1.8 mode. So we need to update the config to ignore
JRuby 2.0. However, the current config incorrectly assumes we can do
that by checking the `JRUBY_OPTS` environment variable. Travis actually
sets this be default on _all_ systems:
http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables

However, we can check the Ruby version we pass into the travis matrix by
using the `TRAVIS_RUBY_VERSION` and seeing if it equals "jruby".
lib/rspec/support/ruby_features.rb:9:7: C: Outdent access modifiers like module_function.
      module_function
      ^^^^^^^^^^^^^^^
lib/rspec/support/ruby_features.rb:24:7: C: Outdent access modifiers like module_function.
      module_function
      ^^^^^^^^^^^^^^^
lib/rspec/support/ruby_features.rb:48:7: C: Outdent access modifiers like module_function.
      module_function
      ^^^^^^^^^^^^^^^
lib/rspec/support/spec/string_matcher.rb:7:1: C: Extra empty line detected at block body beginning.
The check name is a little misleading. The check really is more:
"`returned` called from inside a block". Given RSpec's DSL syntax and
our heavy block usage, from which calling `return` is valid, this is
being turned off.
lib/rspec/support/caller_filter.rb:72:23: C: Operator *= should be surrounded with a single space.
          increment   *= 2 # The choice of two here is arbitrary.
                      ^^
lib/rspec/support/method_signature_verifier.rb:98:48: C: Operator + should be surrounded with a single space.
          @max_non_kw_args = @min_non_kw_args  + optional_non_kw_args
                                                 ^
This raises the code metric thresholds for perceived complexity and
assignment branch conditionals. These are only meant to be temporary
settings to ignore the existing offenses. We fully intend to reduce
these over time.
We have not decided how we are going to handle the symbol to proc vs
block implementations. This is because the block is faster on Ruby
1.8.7, REE, and JRuby but slower on Ruby 1.9.2 through 2.2.2.
lib/rspec/support/version_checker.rb:8:9: C: Do not use parallel assignment.
        @library_name, @library_version = library_name, library_version
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@cupakromer
Copy link
Member Author

This is good to go.

# Note this doesn't work on JRUBY 2.0.0 mode so we don't do it
- if [ -z "$JRUBY_OPTS" ]; then gem install bundler -v=1.5.3 && alias bundle="bundle _1.5.3_"; fi
- if [ "jruby" != "$TRAVIS_RUBY_VERSION" ]; then gem install bundler; fi
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't do the same thing, can we now safely use the later version of bundler on JRuby?

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment above states that the older version of bundler is necessary due to an issue which is fixed. Though now I see that the default bundler on Travis, 1.7.4, doesn't contain the fix. So I can adjust this to support both.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I'm not sure there is anything to change. The comment was stating that we weren't running the custom lower bundler version on JRuby, so it was supposed to be using the Travis default of 1.7.4. Am I missing something here?

@JonRowe
Copy link
Member

JonRowe commented Aug 2, 2015

Good work on the benchmarks, but shouldn't we be doing the config via rspec-dev as its centralised? Also I disagree with one of the style changes but I'm willing to go with the majority obviously :)

@cupakromer
Copy link
Member Author

but shouldn't we be doing the config via rspec-dev as its centralised?

Bumping rubocop will cause all the builds to fail. We've opened up PRs on all repos that have these fixes as a stop-gap so the new cops can be configured and fixes made. I am going to have a PR open for rspec-mocks tonight, and a PR for rspec-dev with the "master" changes; which I plan to push out after the PRs get merged in so that the build stays happy.

@JonRowe
Copy link
Member

JonRowe commented Aug 3, 2015

Yeah but we can open the PRs from rspec-dev with the bump and then fix them in those PRS

@cupakromer cupakromer force-pushed the update-rubocop branch 3 times, most recently from bac55b1 to d26a58b Compare August 13, 2015 04:13
@benoittgt
Copy link
Member

@JonRowe do you think fix conflicts in a new PR (from this one) could be a good idea? I can work on it.

It seems lot's of things have change since. Maybe it can be close?

@JonRowe
Copy link
Member

JonRowe commented Mar 15, 2018

@benoittgt feel free to take a shot at rebasing this

@benoittgt
Copy link
Member

Closing for now. In favor of #350

@benoittgt benoittgt closed this Jun 12, 2019
@benoittgt benoittgt deleted the update-rubocop branch June 12, 2019 06:51
JonRowe pushed a commit that referenced this pull request Jun 10, 2020
Updated rubocop rules see: #350
JonRowe pushed a commit that referenced this pull request Jun 10, 2020
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
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

3 participants