reviewdog / action-rubocop

Run rubocop with reviewdog 🐶
MIT License
115 stars 75 forks source link

undefined method `begin' for nil:NilClass #68

Closed sinshutu closed 2 years ago

sinshutu commented 2 years ago

I'm getting an error during execution. Can provide more details if needed.

I feel that Metrics / AbcSize is the cause.

rubocop offensens

Offenses:

app/controllers/users_controller.rb:13:3: C: Metrics/AbcSize: Assignment Branch Condition size for create is too high. [<4, 28, 6> 28.91/25]
  def create ...
  ^^^^^^^^^^

error

  undefined method `begin' for nil:NilClass
  /home/runner/work/_actions/reviewdog/action-rubocop/v2.1/rdjson_formatter/rdjson_formatter.rb:73:in `build_suggestions'
  /home/runner/work/_actions/reviewdog/action-rubocop/v2.1/rdjson_formatter/rdjson_formatter.rb:59:in `build_diagnostic'
  /home/runner/work/_actions/reviewdog/action-rubocop/v2.1/rdjson_formatter/rdjson_formatter.rb:21:in `block in file_finished'
  /home/runner/work/_actions/reviewdog/action-rubocop/v2.1/rdjson_formatter/rdjson_formatter.rb:18:in `each'
  /home/runner/work/_actions/reviewdog/action-rubocop/v2.1/rdjson_formatter/rdjson_formatter.rb:18:in `file_finished'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/formatter/formatter_set.rb:49:in `block in file_finished'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/formatter/formatter_set.rb:49:in `each'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/formatter/formatter_set.rb:49:in `file_finished'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:218:in `file_finished'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:127:in `process_file'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:100:in `each'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:100:in `reduce'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:86:in `inspect_files'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/runner.rb:47:in `run'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/cli/command.rb:11:in `run'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/cli/environment.rb:18:in `run'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/cli.rb:65:in `run_command'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/cli.rb:72:in `execute_runners'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/lib/rubocop/cli.rb:41:in `run'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/exe/rubocop:13:in `block in <top (required)>'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/lib/ruby/gems/2.6.0/gems/rubocop-0.92.0/exe/rubocop:12:in `<top (required)>'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/bin/rubocop:23:in `load'
  /opt/hostedtoolcache/Ruby/2.6.5/x64/bin/rubocop:23:in `<main>'

workflow

  rubocop:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.6.5
          bundler-cache: true
      - name: rubocop
        uses: reviewdog/action-rubocop@v2.1
        with:
          rubocop_version: gemfile
          rubocop_extensions: rubocop-rspec:gemfile
          reporter: github-pr-review

Installing rubocop

Installing rubocop with extensions ... https://github.com/rubocop/rubocop
  Successfully installed unicode-display_width-1.8.0
  Successfully installed ruby-progressbar-1.11.0
  Successfully installed ast-2.4.2
  Successfully installed parser-3.1.1.0
  Successfully installed rubocop-ast-1.16.0
  Successfully installed regexp_parser-2.2.1
  Successfully installed rainbow-3.1.1
  Successfully installed parallel-1.22.1
  Successfully installed rubocop-0.92.0
  9 gems installed
  Successfully installed rubocop-rspec-1.[43](https://github.com/slogan-tech/fastgrow/runs/5765065621?check_suite_focus=true#step:4:43).2
ohbarye commented 2 years ago

Could you provide a concrete example to reproduce? I tried to reproduce the error with an example file including an offence of Metrics/AbcSize, but wasn't able to do.

📝 In my understanding,

sinshutu commented 2 years ago

Then, build_suggestions is not called in case of Metrics/AbcSize.

So that's it. Reproduced with rubocop 0.92.0.

I reproduced it with a simple program like the following.

# frozen_string_literal: true

def create
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
  user = User.new(params)
end