1

I am attempting to enable code quality reports for merge requests for a Ruby on Rails application managed in GitLab.

In my .gitlab-ci.yml file I have added the code quality template.

.gitlab-ci.yml:

include:
  - template: Jobs/SAST.gitlab-ci.yml
  - template: Jobs/Secret-Detection.gitlab-ci.yml
  - template: Code-Quality.gitlab-ci.yml

My .rubocop.yml file, stored in the root of the project has lots of configuration.

require:
  - rubocop-rspec
  - rubocop-rails
  - rubocop-performance
Style/HashEachMethods:
  Enabled: true
Style/HashTransformKeys:
  Enabled: true
Metrics/AbcSize:
  Enabled: false
…

And I have configured a .codeclimate.yml file as such.

version: "2"
plugins:
  rubocop:
    enabled: true
    channel: rubocop-1-48-1
    config:
      file: .rubocop.yml

If I run rubocop locally I get a clean bill of health. When GitLab runs it as part of a merge request pipeline, it has over 100 failures.

Major - Method get_state has 32 lines of code (exceeds 25 allowed). Consider refactoring.

in app/services/order/order_service.rb:62

I am basing my config on GitLab's Documentation and Code Climate's documentation.

Edit: Here is what I get when I run codeclimate locally, with the specific details of the failing code obfuscated.

✗ docker run \
  --interactive --tty --rm \
  --env CODECLIMATE_CODE="$PWD" \
  --volume "$PWD":/code \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /tmp/cc:/tmp/cc \
  codeclimate/codeclimate analyze
Starting analysis
Running structure: Done!
Running duplication: Done!
Running rubocop: Done!

== app/controllers/foobar_controller.rb (1 issue) ==
18-29: Method `barbaz` has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. [structure]

…
David Baucum
  • 2,162
  • 24
  • 25

1 Answers1

0

I see in "Using rubocop's newer versions"

Using newer versions of RuboCop vs the Rubocop Plugin default

You might encounter errors if you rely on Code Climate to infer a RuboCop configuration file for you.

To avoid that, be sure to have a version-specific .rubocop.yml in your repo.

So start explicitly setting the RuboCop version in your .codeclimate.yml file (latest one is 1-50-2):

version: "2"
plugins:
  rubocop:
    enabled: true
    channel: rubocop-1-48-1
    config:
      file: .rubocop.yml
    checks:
      rubocop:
        enabled: true
        config: .rubocop.yml
  structure:
    enabled: true
    checks:
      cognitive-complexity:
        config:
          threshold: 10

Then try again, both locally and on GitLab.
But make sure your .rubocop.yml, .gitlab-ci.yml, and .codeclimate.yml files are committed and pushed to the GitLab repository. Code Climate will only use configuration files present in the repository when the pipeline is triggered.

Just in case, check locally if one of those file is ignored:

cd /path/to/repository
git check-ignore -v -- .rubocop.yml
git check-ignore -v -- .gitlab-ci.yml
git check-ignore -v -- .codeclimate.yml
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I updated my `.codeclimate.yml` file to be identical to yours and re-pushed. I have validated none of those files are ignored, and they all show up in GitLab when I look at the repo. The eslint errors still persist. I tried running codeclimate locally, the description above has those updates. – David Baucum May 12 '23 at 20:32
  • Also, it looks like Codeclimate is not currently picking up the latest channel yet. `Skipped rubocop: Channel rubocop-1-50-2 not found for rubocop, available channels: ["stable", "beta", "cache-support", "rubocop-0-42", "rubocop-0-46", "rubocop-0-48", "rubocop-0-49", "rubocop-0-50", "rubocop-0-51", "rubocop-0-52", "rubocop-0-54", "rubocop-0-55", "rubocop-0-56", "rubocop-0-57", "rubocop-0-58", "rubocop-0-59", "rubocop-0-60", "rubocop-0-61", "rubocop-0-62", "rubocop-0-63", "rubocop-0-64", "rubocop-0-65", "rubocop-0-66", "rubocop-0-67", "rubocop-0-68", "rubocop-0-69", "rubocop-0-70", "ruboco…` – David Baucum May 12 '23 at 20:36
  • It's showing `rubocop-1-48-1` at the latest in the above array. The reply cutoff wouldn't allow me to post the entire output. – David Baucum May 12 '23 at 20:38
  • @DavidBaucum OK, can you try with an older version? 1-48-1 for instance? – VonC May 12 '23 at 21:38
  • I did. I get the same result. – David Baucum May 15 '23 at 14:39