title: CLOC ignore/exclude list file (.clocignore)
body: <p>(<em>Edit: see <strong>Proper Usage</strong> section on the bottom.</em>)</p>
  
  <p><strong>Main Question</strong></p>
  
  <p>How do you get <a href="http://cloc.sourceforge.net/"><code>cloc</code></a> to use its <code>--exclude-list-file=&lt;file&gt;</code> option?  Essentially, I'm trying to feed it a <code>.clocignore</code> file.</p>
  
  <p><strong>Expected Behavior</strong></p>
  
  <p><code>cloc</code> documentation says the following:</p>
  
  <pre><code>--exclude-list-file=&lt;file&gt;  Ignore files and/or directories whose names
                            appear in &lt;file&gt;.  &lt;file&gt; should have one entry
                            per line.  Relative path names will be resolved
                            starting from the directory where cloc is
                            invoked.  See also --list-file.
  </code></pre>
  
  <p><strong>Attempts</strong></p>
  
  <p>The following command works as expected:</p>
  
  <pre><code>cloc --exclude-dir=node_modules .
  </code></pre>
  
  <p>But this command doesn't exclude anything:</p>
  
  <pre><code>cloc --exclude-list-file=myignorefile .
  </code></pre>
  
  <p>This is the contents of <code>myignorefile</code>:</p>
  
  <pre><code>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/**
  </code></pre>
  
  <p><code>cloc</code> does <em>not</em> error if <code>myignorefile</code> doesn't exist, so I have no feedback on what it's doing.</p>
  
  <p>(I'm running OS X and installed <code>cloc</code> v1.60 via Homebrew.)</p>
  
  <hr>
  
  <hr>
  
  <h2>Proper Usage</h2>
  
  <p><em>tl;dr</em> -- The method specified in @Raman's answer both requires less to be specified in <code>.clocignore</code> and runs considerably faster.</p>
  
  <hr>
  
  <p>Spurred on by @Raman's answer, I investigated the source code: <code>cloc</code> <em>does</em> in fact respect <code>--exclude-list-file</code> but processes it differently than <code>--exclude-dir</code> in two important ways.</p>
  
  <h3>Exact filename versus 'part of the path'</h3>
  
  <p>First, while <code>--exclude-dir</code> will ignore any files whose paths contain the specified strings, <code>--exclude-list-file</code> will only exclude the exact files or directories specified in <code>.clocignore</code>.</p>
  
  <p>If you have a <strong>directory structure</strong> like this:</p>
  
  <pre><code>.clocignore
  node_modules/foo/first.js
  app/node_modules/bar/second.js
  </code></pre>
  
  <p>And the contents of <code>.clocignore</code> is just</p>
  
  <pre><code>node_modules
  </code></pre>
  
  <p>Then <code>cloc --exclude-list-file=.clocignore .</code> will successfully ignore <code>first.js</code> but count <code>second.js</code>.  Whereas <code>cloc --exclude-dir=node_modules .</code> will ignore both.</p>
  
  <p>To deal with this, <code>.clocignore</code> needs to contain this:</p>
  
  <pre><code>node_modules
  app/node_modules
  </code></pre>
  
  <h3>Performance</h3>
  
  <p>Second, the source code for <code>cloc</code> appears to add the directories specified in <code>--exlude-dir</code> to a list which is consulted <em>before</em> counting the files.  Whereas the list of directories discovered by <code>--exclude-list-file</code> is consulted <em>after</em> counting the files.</p>
  
  <p>Meaning, <code>--exclude-list-file</code> still processes the files, which can be slow, before ignoring their results in the final report.  This is borne out by experiment: in an example codebase, it took half a second to run <code>cloc</code> with <code>--exclude-dir</code>, and 11 seconds to run with an equivalent <code>--exclude-list-file</code>.</p>