(編集: 参照適切な使用法下部のセクション。)
主な質問
どうやって手に入れたのcloc
オプションを使用するにはどうすればいいです--exclude-list-file=<file>
か? 基本的には、ファイルを入力しようとしています.clocignore
。
予想される行動
cloc
ドキュメントには次のように記載されています:
--exclude-list-file=<file> Ignore files and/or directories whose names
appear in <file>. <file> should have one entry
per line. Relative path names will be resolved
starting from the directory where cloc is
invoked. See also --list-file.
試み
次のコマンドは期待どおりに動作します。
cloc --exclude-dir=node_modules .
しかし、このコマンドは何も除外しません:
cloc --exclude-list-file=myignorefile .
以下の内容ですmyignorefile
:
node_modules
node_modules/
node_modules/*
node_modules/**
./node_modules
./node_modules/
./node_modules/*
./node_modules/**
/full/path/to/current/directory/node_modules
/full/path/to/current/directory/node_modules/
/full/path/to/current/directory/node_modules/*
/full/path/to/current/directory/node_modules/**
cloc
するない存在しない場合はエラーがmyignorefile
発生するため、何を実行しているのかフィードバックがありません。
(私は OS X を実行しており、cloc
Homebrew 経由で v1.60 をインストールしました。)
適切な使用法
要約-- @Raman の回答で指定されている方法は、指定する必要のある項目が少なく.clocignore
、実行速度もかなり速くなります。
@Raman の回答に刺激されて、ソースコードを調査しました。cloc
する実際には尊重します--exclude-list-file
が、--exclude-dir
2 つの重要な方法でそれを異なる方法で処理します。
正確なファイル名と「パスの一部」
まず、 は--exclude-dir
パスに指定された文字列が含まれるファイルをすべて無視しますが、--exclude-list-file
は で指定されたファイルまたはディレクトリのみを除外します.clocignore
。
もしあなたがディレクトリ構造このような:
.clocignore
node_modules/foo/first.js
app/node_modules/bar/second.js
そしてその内容.clocignore
は
node_modules
すると、cloc --exclude-list-file=.clocignore .
は無視されますfirst.js
が、カウントされますsecond.js
。 一方、cloc --exclude-dir=node_modules .
は両方を無視します。
これに対処するには、.clocignore
次のものを含める必要があります。
node_modules
app/node_modules
パフォーマンス
第二に、のソースコードは、参照されるリストにcloc
指定されたディレクトリを追加するようです。--exlude-dir
前にファイルを数える。によって発見されたディレクトリのリストは--exclude-list-file
参照されるが、後ファイルを数えます。
つまり、 は、--exclude-list-file
最終レポートでその結果を無視する前に、遅い可能性があるファイルを処理します。これは実験によって実証されています。サンプル コードベースでは、 での実行に 0.5 秒かかりcloc
、--exclude-dir
同等の での実行には 11 秒かかりました--exclude-list-file
。
ベストアンサー1
私が見つけた最善の回避策は、 の内容.clocignore
を に直接渡すことです--exclude-dir
。たとえば、 を使用していてbash
、 がtr
使用可能な場合:
cloc --exclude-dir=$(tr '\n' ',' < .clocignore) .