CLOC 無視/除外リストファイル (.clocignore) 質問する

CLOC 無視/除外リストファイル (.clocignore) 質問する

編集: 参照適切な使用法下部のセクション。

主な質問

どうやって手に入れたの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 を実行しており、clocHomebrew 経由で v1.60 をインストールしました。)



適切な使用法

要約-- @Raman の回答で指定されている方法は、指定する必要のある項目が少なく.clocignore、実行速度もかなり速くなります。


@Raman の回答に刺激されて、ソースコードを調査しました。cloc する実際には尊重します--exclude-list-fileが、--exclude-dir2 つの重要な方法でそれを異なる方法で処理します。

正確なファイル名と「パスの一部」

まず、 は--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) .

おすすめ記事