SourceMonitorでASP.NETのVB部分の複雑度を図る

経緯

  • SourceMonitorを導入してみた
  • 解析がうまくいかないファイルがあった
  • 仕方ないので細かくファイルを分けて計測したところ、どうやら日本語部分が悪いっぽい
    • コメント' comment
    • ドキュメントコメント'''<summary>doc comment</summary>
    • 文字列中 Dim hoge = "漢字が入るとあやしい"
  • 複雑度とかネストには関係ないので計測前に全部処理すればよいのでは?
    • char型に注意
    • ''''の2種類に注意
      • SourceMonitorの機能でコメント率があるのでそれには影響してしまう

処理してみた

powershellで作ってみた

function grepVBFiles([string] $path) {
    return Get-ChildItem -Path $path -Recurse -Filter "*.vb"
}
 
function grepReplaceVB([string] $path, [string] $regex, [string] $replacer) {
     grepVBFiles $path | ?{
        Select-String -InputObject $_ -Pattern $regex
    } | %{
        $file = $_
        $content = Get-Content -LiteralPath $file
        Set-Content $_.FullName ($content -replace $regex, $replacer)
    }
}
# change this variable
$path = "C:\tmp"
cd $path
grepReplaceVB $path '\"[^"]*\"' '""'
grepReplaceVB $path "'[^']'" "__char__"
grepReplaceVB $path "'.*$" "'"
grepReplaceVB $path "__char__" "'a'"

課題

  • commentとdoc commentを区別していない
  • 4回別々に実行して書き込んでいるのでヤバそう
  • __char__に置換しているので万が一同じ箇所があるとバグる
  • どう書けばキレイに使いやすいのかがわからない……

首尾

明日試す