【codeclimate】デフォルトの設定。codeclimate入れたら注意されまくったよ
最近常駐先でコードのリファクタリングの風が吹いていて、テスト書こう、切り出そう、コードカバレッジをあげようの機運があります
それだけじゃ行動が起きないので、codeclimateが導入されました。
PRを送ると自分がどのくらい複雑なコードを書いているか、テストが網羅されているかが測られて嫌でも「あー。。。」ていう気になります。
プロジェクトによりますが、やはり太くなるファイルはあるので、
codeclimateのデフォルト値をいじることになるのですが、、、
注意されているところを直すための記事
codeclimate defaultのsettingはどんな感じでしょうか
https://docs.codeclimate.com/docs/default-analysis-configuration#section-maintainability-checks
Argument count
- Threshold: 4 引数は4つまで
Complex logic 理解しにくいbooleanのロジック
- Threshold: 4
File lines 1ファイルあたりの行数
- Threshold: 250
Method complexity 理解しにくい関数またはメソッド(認知の複雑さ)
- Threshold: 5
こういうのは理解しやすいがテストが大変になりやすく複雑とみなされる
switch ($meal) {
case "breakfast":
echo "Most important meal of the day! Enjoy.";
break;
case "lunch":
echo "A reasonably important meal of the day.";
break;
case "dinner":
echo "Alright, rounding out your day, very nice.";
break;
default:
echo "Snacking is important!";
https://docs.codeclimate.com/docs/cognitive-complexity
Method count 関数の数
- Threshold: 20
Method length 1つの関数またはメソッド内の過剰なコード行
- Threshold: 25
Nested control flow -ifやcaseのような深くネストされた制御構造
- Threshold: 4
Return statements 戻りステートメントの数が多い関数またはメソッド。returnは4つまで
- Threshold: 4
*Similar blocks of code 同一ではないが同じ構造を共有する重複コード **
- Threshold: language-specific defaults
Identical blocks of code
これらのファイルはcodeclimateではdefaultで無視する
defaultではymlファイルはこうなっているので
プロジェクトにあったsettingをしていく
version: "2" # required to adjust maintainability checks
checks:
argument-count:
config:
threshold: 4
complex-logic:
config:
threshold: 4
file-lines:
config:
threshold: 250
method-complexity:
config:
threshold: 5
method-count:
config:
threshold: 20
method-lines:
config:
threshold: 25
nested-control-flow:
config:
threshold: 4
return-statements:
config:
threshold: 4
similar-code:
config:
threshold: # language-specific defaults. an override will affect all languages.
identical-code:
config:
threshold: # language-specific defaults. an override will affect all languages.
defaultでignoreされるものはこれら
config/
db/
dist/
features/
**/node_modules/
script/
**/spec/
**/test/
**/tests/
Tests/
**/vendor/
**/*_test.go
**/*.d.ts
プロジェクトが機能満載になる前に早めの対応をしないとリファクタリング大変になりますね
ではー
「武骨日記の」プライバシーポリシーに関して
・プライバシーポリシー
・個人情報取り扱いに関して
・サイトTOP
・私は何者か
・29歳よしもと芸人がWebデザイナー未経験で学校に通い5年後フリーランスのフロントエンドエンジニアになるためにやった9つのこと
・フロント記事
・フロントエンドエンジニア
・フロントエンド記事(タグ)
・TypeScript
・TypeScript練習問題集
・【TypeScript】TypeSript中級者になる為に知っておくと良い108個のこと
・JavaScript練習問題
・styled-componentsの使い方
・SCSS問題集
・GraphQL「Apollo x Relay-Style-Cursor-Pagination(リレースタイルカーソルページネーション)」
・recomposeと仲良くなりたい
・機動戦士FlowType
・初めてReactNativeWebを触ってみて
・Ramda.jsシグネチャの読み方
・環境変数の話
・いちごタルトの作り方
・フロントエンドエンジニア豚汁の作り方
「武骨日記の」プライバシーポリシーに関して
プライバシーポリシー
株式会社TerraceTechについて
最近起業しました。
・株式会社TerraceTech
SNS
・しずかなインターネット kenjimorita
・インド旅 instagram
・適当な日常写真 instagram
・シュールさーん instagram
・シュールさーん LINEスタンプ
・もりたけんじTwitter
・ネタ帳Twitter
・note
※わたしが結成しているWebチームではWeb未経験者、フリーランスの方へのお仕事を紹介しています。
また個人レッスンしてほしい生徒も募集中です。
もしご興味ある方はチャットからご連絡ください。
※業務連絡やお久しぶり連絡もチャットからお願いします。