1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

duplicationエンジンを特定のパスで無効にする

Last updated at Posted at 2016-02-17

CodeClimateを使うと自動的にコードの品質を採点してくれる。潜在的なリファクタリング可能ポイントを可視化してくれるので大変便利なのだが、特にduplicationエンジンはお節介が過ぎて邪魔になることがある。

特に顕著なのはテストを書いているときだと思う。テストだとどうしても同じようなコードが出現してしまう。下手に共通化してもむしろ見通しが悪くなったりすることもある、そもそも対応するのが面倒なことも多い。

こういう場合は、engine設定にexclude_pathsを追加することで、テストコードに対してduplicationエンジンをオフにすることができる。例えばRubyのリポジトリで、specディレクトリ以下はduplicationエンジンを切る場合はこんな感じで書く:

.codeclimate.yml
---
engines:
  duplication:
    enabled: true
    exclude_paths:
    - spec
    config:
      languages:
      - ruby
  rubocop:
    enabled: true

当然ながらrubocopエンジンはspec以下も対象になる。

実はこれまでexclude_pathsはトップレベルにしか置けなかった。つまりこういうこと:

.codeclimate.yml
---
engines:
  duplication:
    enabled: true
    config:
      languages:
      - ruby
  rubocop:
    enabled: true
exclude_paths:
- spec

この場合spec以下はrubocopも走らなくなってしまう。小さな改善だが嬉しい :relaxed:

参考

  • codelimate/codeclimate#308
    • この機能が追加されたPull Request。中身はごちゃごちゃ色々入っているが、その中に今回のengine単位のexclude_pathsも含まれている。
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?