Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Fix #233 conflicts -> Update rubocop #350

Merged
merged 14 commits into from
Jun 10, 2020
Merged

Conversation

benoittgt
Copy link
Member

I'm trying to reduce the number of open PR on this repo.

This PR is a merge conflict free of #233.

@benoittgt
Copy link
Member Author

We have 3 rubocop offences

lib/rspec/support/comparable_version.rb:13:7: C: Metrics/AbcSize: Assignment Branch Condition size for <=> is too high. [23.62/22]
      def <=>(other) ...
      ^^^^^^^^^^^^^^
lib/rspec/support/spec/in_sub_process.rb:11:9: C: Metrics/AbcSize: Assignment Branch Condition size for in_sub_process is too high. [27.46/22]
        def in_sub_process(prevent_warnings=true) ...
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rspec/support/method_signature_verifier.rb:283:7: C: Metrics/PerceivedComplexity: Perceived complexity for with_expectation is too high. [10/9]
      def with_expectation(expectation) # rubocop:disable MethodLength ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31 files inspected, 3 offenses detected

Do we want to change Rubocop Metrics/AbcSize to 28 and Metrics/PerceivedComplexityto 10 or do we want to fix those issues?

I'm trying to fix them at the moment.

@benoittgt
Copy link
Member Author

Little bump. I can work on any changes if needed.

@JonRowe
Copy link
Member

JonRowe commented May 24, 2018

Some refactoring of those methods would be good but happy for the rules to be disabled for those methods temporarily, isn't the rubocop.yml file controlled from the rspec-dev repo though?

@benoittgt
Copy link
Member Author

You are correct for the rubocop.yml. I will remove the change on it, to stay sync with rspec-dev and see which change needs to be made.

@JonRowe
Copy link
Member

JonRowe commented May 25, 2018

@benoittgt I'm quite happy for you to update rubocop.yml over in rspec-dev if required :) Thank you for tackling this!

@benoittgt
Copy link
Member Author

I don't know if we still need to keep benchmarks #233 (comment)

@benoittgt
Copy link
Member Author

I started fixing offenses. But I still have 171 ! rubocop auto-correct break few test.
I will work on fixing those issues. I probably disable few cops on file when it require too much work.

@benoittgt
Copy link
Member Author

I will probably import only benchmarks and speed changes on a new PR. I tried to rebase but it was very painful.

@pirj
Copy link
Member

pirj commented Jun 12, 2019

No worries about RuboCop part @benoittgt, I'm planning to address them in rspec-support as well.

@benoittgt
Copy link
Member Author

Do we still want this?

@JonRowe
Copy link
Member

JonRowe commented May 17, 2020

I think so if you want to spend the time updating it, a bunch of the old ruby stuff is now irrelevant, and some of the rules will have been improved anyway?

@benoittgt benoittgt self-assigned this May 18, 2020
cupakromer and others added 11 commits June 8, 2020 15:06
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
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@benoittgt
Copy link
Member Author

We should be good now.

@benoittgt benoittgt requested review from JonRowe and pirj June 8, 2020 13:38
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

I don't know if we still need to keep benchmarks

As long as we use them to justify our styling choices - probably yes.

We can give in and use what rubocop-performance tells us to, however some express concerns regarding its defaults.

@JonRowe
Copy link
Member

JonRowe commented Jun 8, 2020

The changes to the code look fine, but what relevance do the benchmarks have?

@benoittgt
Copy link
Member Author

The changes to the code look fine, but what relevance do the benchmarks have?

Good question. I just looked at commit body benoittgt@6b27ac2

lib/rspec/support/version_checker.rb:8:9: C: Do not use parallel assignment.
        @library_name, @library_version = library_name, library_version
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

But I should have look deeper. The file no longer exist and also we do not check this rule

Enabled: false

So I am in favor of removing this benchmark first.

For the second benchmark. This is related to a rule we didn't choose yet. benoittgt@6c8f550

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.

@pirj
Copy link
Member

pirj commented Jun 8, 2020

I guess we can put

Style/SymbolProc:
  Enabled: false

to .rubocop_todo.yml just like we do in rspec-rails. There should be a reference to it from .rubocop.yml.

Symbol to proc makes sense, we can decide/enforce later when we drop Ruby < 2.3.

@JonRowe
Copy link
Member

JonRowe commented Jun 9, 2020

I'm happy to keep either benchmark, but a comment at the top explaining that they are there for checking the performance of rubocop/rbhint recommendations

@pirj
Copy link
Member

pirj commented Jun 9, 2020

rbhint

😱 🏃 🙈

script/run_build Outdated
@@ -20,6 +20,9 @@ fi

fold "cukes" run_cukes

# To remove after benchmark measurement
ruby benchmarks/symbol_to_proc_vs_block.rb

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't add this to the build personally, whats your thoughts here

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it take some times to gather benchmark result on each Ruby build. You not get easily info that the new Ruby version is for example slower that the previous one on one benchmark. This is more something that should be inserted in https://rubybench.org/ruby/ruby/releases

Also it will add some time to the build itself. I think we should try to have always a fast CI.

I am not convinced about adding it. 😊

I would prefer a benchmark for each gem (except rspec-rails) that assert rspec gem benchmarking performance using a tool like https://github.com/marketplace/actions/continuous-benchmark (it needs Ruby support).

Copy link
Member

Choose a reason for hiding this comment

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

It might be an idea to run once, but not for every build.

Copy link
Member Author

@benoittgt benoittgt Jun 9, 2020

Choose a reason for hiding this comment

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

I tried two things:

require 'benchmark_driver'

Benchmark.driver do |x|
  x.prelude <<~RUBY
    RANGE = (1..100)

    def sym_to_proc_with_map
      RANGE.map(&:to_s)
    end

    def sym_to_proc_with_each
      RANGE.each(&:to_s)
    end

    def block_with_map
      RANGE.map { |i| i.to_s }
    end

    def block_with_each
      RANGE.each { |i| i.to_s }
    end
  RUBY

  size = 10_000
  range = (1..size)

  x.report 'Block map', %{ block_with_map }
  x.report 'Symbol#to_proc map', %{ sym_to_proc_with_map }
  x.report 'Block each', %{ block_with_each }
  x.report 'Symbol#to_proc each', %{ sym_to_proc_with_each }
end

But the gem looks pretty buggy at the moment. I was not able to have the output for all ruby with with this command. Also results are not properly compared at the end you have to do it by hand. Plus, it is working only after Ruby 2.2.

Here is a cleaned output https://gist.github.com/benoittgt/3464d476060dbbe1dce5e7c649a3587a

BTW I noticed that the part with benchmark-ips was not written in the initial benchmark by Aaron. So I rewrote it.

I think both benchmark should be removed. I already removed one. If we want to have benchmarks like this one (basic Ruby across Ruby version), we should rely on rubybench.


puts "\nUsing Array#map size #{size}:"
Benchmark.ips do |x|
x.report('Block ') { range.map { |i| i.to_s } }
Copy link
Member Author

Choose a reason for hiding this comment

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

Benchmark is incorrect. It should be:

Suggested change
x.report('Block ') { range.map { |i| i.to_s } }
x.report('Block ') { block_with_map }

This is the same for all the others.

1. The benchmark-ips part is incorrect
2. This benchmark is meant to be tested across different Ruby versions
   but for that we use the CI. The CI is not isolated enough to be used
   to run benchmark.
3. Results are difficult to gather

The solution is to rely on rubybench.org
@JonRowe JonRowe merged commit c221faa into rspec:master Jun 10, 2020
@benoittgt benoittgt deleted the update-rubocop branch June 10, 2020 14:52
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants