LoginSignup
6
2

More than 5 years have passed since last update.

CircleCI でRuboCopがError: Unsupported Ruby versionとかおっしゃる

Posted at

CircleCIでRuboCopが動かん

CircleCIでRuboCopを動かそうとすると下記エラーが出力されて動いてくれませんでした。
ローカルでRubocop走らせたら正常にチェックしてくれました。

#!/bin/bash -eo pipefail
bundle exec rubocop
Error: Unsupported Ruby version 2.1 found in `TargetRubyVersion` parameter (in vendor/bundle/ruby/2.5.0/gems/rainbow-3.0.0/.rubocop.yml). 2.1-compatible analysis was dropped after version 0.58.
Supported versions: 2.2, 2.3, 2.4, 2.5, 2.6
Exited with code 2

0.58以降のRuboCopはRubyのバージョン2.2, 2.3, 2.4, 2.5, 2.6しか対応してませんよ、ということらしいです。

バージョンちゃんと指定してんじゃん

とはいえ、CircleCIのコンフィグでちゃんとバージョンを2.5.1に設定しとるんですよ。

circleci/config.yml
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
       - image: circleci/ruby:2.5.1-node-browsers  # <-ほら

こうやったらええよ

結果としてRuboCopのコンフィグを編集することで解決できました。

rubocop.yml
AllCops:
  TargetRubyVersion: 2.5.1
  Exclude:
    - 'vendor/**/*'

なんでそうなるの

CircleCIの仕様上、gemたちはvendor/bundle配下にインストールされるそうです。
で、その中にRuboCopがつかっているrainbowとかいうGEMがあります。
rainbowは使うRubyのバージョンを独自で定義しているみたいで、そのバージョンがRubocopの対象外
ということみたいです。確かにエラーメッセージにもin vendor/bundle/ruby/2.5.0/gems/rainbow-3.0.0/.rubocop.ymlて書いてありますしね。
だから、と記載して、RubocopのTargetRubyVersion:でRubyのバージョンを指定し、- 'vendor/**/*'でvendorディレクトリ配下のチェックをスキップするようにしたら解決したのですね。めんどくさいですね。

しかしそれならrainbowがローカルでも悪さをしてRubocop失敗しないのかな。。という不思議。

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2