Last active
August 29, 2015 14:23
-
-
Save KenshoFujisaki/9cefd372c9cec0814a08 to your computer and use it in GitHub Desktop.
技術的負債の定量化
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref: 第8回 Perlによる大規模システム開発・設計のツボ(3):Perl Hackers Hub|gihyo.jp … 技術評論社 | |
# http://gihyo.jp/dev/serial/01/perl-hackers-hub/000803 | |
# コンポーネントの単一責務性の違反指数(SRP) | |
# SRP=R+U+((L/100)-5) | |
# R:修正リビジョンのユニーク数 | |
# U:修正ユーザのユニーク数 | |
# L:モジュールのライン数 | |
function get_SRP() { | |
local target_filepath=$1 | |
echo $(( \ | |
$(git --no-pager blame --line-porcelain $target_filepath | sed -n 's/^summary //p' | sort | uniq -c | sort -rn | wc -l) + \ | |
$(git --no-pager blame --line-porcelain $target_filepath | sed -n 's/^author //p' | sort | uniq -c | sort -rn | wc -l) + \ | |
( $(cat $target_filepath | wc -l) / 100 - 5) \ | |
)) | |
} | |
# コンポーネントの循環的複雑度(CC) | |
# CC=循環的複雑度が20を超えるメソッド数 | |
function get_CC() { | |
local target_filepath=$1 | |
echo $( \ | |
rubocop --format simple --only Metrics/CyclomaticComplexity --config <(echo -e "CyclomaticComplexity:\n Max: 20") $target_filepath | grep 'Cyclomatic complexity' | wc -l \ | |
) | |
} | |
# コンポーネントの負債指数(P) | |
# P=SRP×CC+(SRP+CC) | |
function get_P() { | |
local srp=$1 | |
local cc=$2 | |
echo $(( $srp * $cc + ( $srp + $cc ) )) | |
} | |
# コンポーネント負債指数(P)が大きい順に "P SRP CC ファイル名" を標準出力 | |
for file in `git ls-files app lib | grep -E '\.rb$'`; do | |
local srp=$(get_SRP $file) | |
local cc=$(get_CC $file) | |
echo $( get_P $srp $cc ) $srp $cc $file | |
done | tee technical_dept_result.log | sort -k1,1 -nr | |
# 累積値 "ΣP ΣSRP ΣCC" を標準出力 | |
cat technical_dept_result.log | awk 'BEGIN{p=0;srp=0;cc=0}{p+=$1;srp+=$2;cc+=$3;}END{print p" "srp" "cc}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コミットごとに負債値を出力