reviewdog / action-rubocop

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

rubocop_extensions installation version from Gemfile does not work with wrong definition order of gems #92

Closed SHinGo-Koba closed 8 months ago

SHinGo-Koba commented 1 year ago

Since rubocop-rspec requires rubocop-factory_bot and rubocop-capybara, rubocop-factory_bot and rubocop-capybara installation version from Gemfile does not work if you set rubocop-factory_bot:gemfile or rubocop-capybara:gemfile after rubocop-rspec in option rubocop_extensions.

# Gemfile.lock
rubocop-rspec (2.24.0)
  rubocop (~> 1.33)
  rubocop-capybara (~> 2.17)
  rubocop-factory_bot (~> 2.22)
...
rubocop-capybara (2.18.0)
...
rubocop-factory_bot (2.24.0)
  rubocop (~> 1.33)

# ci setting
- name: rubocop
  uses: reviewdog/action-rubocop@v2
  with:
    rubocop_version: gemfile
    rubocop_extensions: rubocop-rails:gemfile rubocop-rspec:gemfile rubocop-performance:gemfile rubocop-checkstyle_formatter:gemfile rubocop-select:gemfile rubocop-factory_bot:gemfile rubocop-capybara:gemfile

# logs
 Installing rubocop with extensions ... https://github.com/rubocop/rubocop
  Successfully installed unicode-display_width-2.4.2
  Successfully installed ruby-progressbar-1.13.0
  Successfully installed ast-2.4.2
  Successfully installed parser-3.2.2.3
  Successfully installed rubocop-ast-1.29.0
  Successfully installed regexp_parser-2.8.1
  Successfully installed rainbow-3.1.1
  Successfully installed parallel-1.23.0
  Successfully installed language_server-protocol-3.17.0.3
  Successfully installed rubocop-1.56.3
  10 gems installed
  Successfully installed rack-3.0.8
  Successfully installed concurrent-ruby-1.2.2
  Successfully installed tzinfo-2.0.6
  Successfully installed i18n-1.14.1
  Successfully installed activesupport-7.0.8
  Successfully installed rubocop-rails-2.21.1
  6 gems installed
  Successfully installed rubocop-factory_bot-2.24.0 # triggered by rubocop-rspec:gemfile
  Successfully installed rubocop-capybara-2.19.0 # triggered by rubocop-rspec:gemfile but rubocop-capybara installed with latest version due to rubocop-rspec requires rubocop-capybara(~> 2.17)
  Successfully installed rubocop-rspec-2.24.0
  3 gems installed
  Successfully installed rubocop-performance-1.19.1
  1 gem installed
  Successfully installed rubocop-checkstyle_formatter-0.6.0
  1 gem installed
  Successfully installed rubocop-select-2.0.0
  1 gem installed
  Successfully installed rubocop-factory_bot-2.24.0 # triggered by rubocop-factory_bot:gemfile
  1 gem installed
  Successfully installed rubocop-capybara-2.18.0 # triggered by rubocop-capybara:gemfile
  1 gem installed

This might cause unexpected rubocop violations due to new rules in latest gem version.

To avoid this at this point, we need to take the definition order of gems into account. But I think it would be better not to depend on definition order since we can not notice easily why ci fails suddenly.

# ci setting
- name: rubocop
  uses: reviewdog/action-rubocop@v2
  with:
    rubocop_version: gemfile
    rubocop_extensions: rubocop-factory_bot:gemfile rubocop-capybara:gemfile rubocop-rails:gemfile rubocop-rspec:gemfile rubocop-performance:gemfile rubocop-checkstyle_formatter:gemfile rubocop-select:gemfile

# logs
  Successfully installed unicode-display_width-2.4.2
  Successfully installed ruby-progressbar-1.13.0
  Successfully installed ast-2.4.2
  Successfully installed parser-3.2.2.3
  Successfully installed rubocop-ast-1.29.0
  Successfully installed regexp_parser-2.8.1
  Successfully installed rainbow-3.1.1
  Successfully installed parallel-1.23.0
  Successfully installed language_server-protocol-3.17.0.3
  Successfully installed rubocop-1.56.3
  10 gems installed
  Successfully installed rubocop-factory_bot-2.24.0 # expected version
  1 gem installed
  Successfully installed rubocop-capybara-2.18.0 # expected version
  1 gem installed
  Successfully installed rack-3.0.8
  Successfully installed concurrent-ruby-1.2.2
  Successfully installed tzinfo-2.0.6
  Successfully installed i18n-1.14.1
  Successfully installed activesupport-7.0.8
  Successfully installed rubocop-rails-2.21.1
  6 gems installed
  Successfully installed rubocop-rspec-2.24.0 # no more installation rubocop-factory_bot and rubocop-capybara because already exists
  1 gem installed
  Successfully installed rubocop-performance-1.19.1
  1 gem installed
  Successfully installed rubocop-checkstyle_formatter-0.6.0
  1 gem installed
  Successfully installed rubocop-select-2.0.0
  1 gem installed
javierjulio commented 9 months ago

@SHinGo-Koba my advice is that this should be avoided and to use bundler instead which will handle the ordering. With a rubocop gem group, and this workflow setup, should avoid that issue.

    env:
      BUNDLE_ONLY: rubocop
    steps:
      - uses: actions/checkout@v4
      - uses: ruby/setup-ruby@v1
        with:
          # ...
          bundler-cache: true
      - uses: reviewdog/action-rubocop@v2
        with:
          # ...
          skip_install: true
          use_bundler: true

If this works for you, I would welcome a PR to update the README with a detailed example and downgrade the existing example since this should be the preferred setup. Thank you.

SHinGo-Koba commented 9 months ago

@javierjulio Thank you for your reply!

I see. I didn't notice that option but I think it'll be good solution to deal with the issue. After checking it, I'll create a PR to update the example with mentioning this point.

javierjulio commented 9 months ago

@SHinGo-Koba you’re welcome. In this comment https://github.com/reviewdog/action-rubocop/issues/83#issuecomment-1942014445 I have an example of the gem group I referred too since I didn’t include it here.

SHinGo-Koba commented 9 months ago

@javierjulio I tried and confirmed it works well. Thank you so much again! Next, I'll create a PR and let you know if it is ready.

javierjulio commented 9 months ago

@SHinGo-Koba that's great news! You're very welcome. Ok sounds good, thank you.