rlaures
rlaures

Reputation: 335

GitLab Auto Dev Ops and rubocop plugins extension incompatibility

Introduction

Working for some time on Ruby on Rails applications, I was looking for some time now, with minimum changes to GitLab's AutoDevOps configuration, to be able to both:

The problem

Since those extensions are not by default included in the Code Climate image of GitLab (while writing this post, the last available is 0.96.0), it ends with the Pipeline Job failing with some message like this:

error: (CC::CLI::Analyze::EngineFailure) engine rubocop failed with status 1 and stderr 
/usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:117:in `require': cannot load such file -- rubocop-haml (LoadError)

This means that you either need to renounce using those extensions, or make a new image for yourself. The latter is not good from my standpoint because you'll have a new thing to maintain.

A “kind of” solution

What I found as a solution for now is to differentiate between the .rubocop.yml file used on Code Climate and the one used for my tests.

The simplest configuration is set in the file .rubocop.yml:

---
require:
# requires here only installed rubocop extensions.
- rubocop-rails # rubocop included in CodeClimate image for some time now

# Activate all new Cops
AllCops:
NewCops: enable

# Any other rules that you want to differentiate from the default rubocop configuration go here.
# It must exclude all the configuration for in this file declared extensions.

It will be used by default by everyone. We'll see the implication later.

Then you create another one like this (I called it .rubocop.local.yml):

---
# get your default configuration
inherit_from: .rubocop.yml

# add plugins rejected by CodeClimate
require:
- rubocop-capybara
- rubocop-haml
- rubocop-rspec

# Any other rules that you want to differentiate from the default rubocop configuration go here.

Finally, to easily use this configuration, create a script in the bin/ directory of your project containing this:

#!/usr/bin/env sh

exec bundle exec rubocop -c .rubocop.local.yml "$@"

Don't forget to make it executable: chmod +x bin/rubocop.

Pros

This allows you to locally run ./bin/rubocop and get all your lint information, as well as get your Code Climate running.

Cons

  1. The Code Climate will not show all the necessary lint errors.
  2. You need to manually run ./bin/rubocop in a terminal to see the errors
  3. You need to configure your IDE to use it, or change the YAML file directly.

Best alternatives

If you have better ideas to improve my solution, please go on. This issue is regularly brought to the attention of GitLab (mainly for Ruby version support). And I suppose I'm not the only one wasting time thinking about it. ;)

Upvotes: 0

Views: 28

Answers (0)

Related Questions