From 346d11f5e097ebc53f46ead937ba1278fe56092b Mon Sep 17 00:00:00 2001 From: H Paterson <26947190+patha454@users.noreply.github.com> Date: Sat, 21 Mar 2020 18:28:59 +1300 Subject: [PATCH] Exclude `.git` from search paths. Currently dscanner searches for files in the target directory ending in `.d` or `.di`. Git has some hidden files in `.git`, which log commits to files. These files share the same name as the tracked file: For example `.git/logs/refs/heads/somedfile.d` actually contains Git data, not D code. A naive call to dscanner using `dscanner --syntaxCheck` or `dscanner --styleCheck` (therefore also `dub lint...`) will attempt to check these Git files, resulting in spurious errors, such as: ```sh ./.git/logs/refs/heads/charstream.d(1:1)[error]: ./.git/logs/refs/heads/charstream.d(1:118)[warn]: Line is longer than 120 characters ``` I believe Git is a common enough tool that we're justified to handle this case inside D scanner, rather than asking the user to write configuration files with dodge the `.git` folder. --- src/dscanner/utils.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dscanner/utils.d b/src/dscanner/utils.d index 92d25e5..d5b1d29 100644 --- a/src/dscanner/utils.d +++ b/src/dscanner/utils.d @@ -84,7 +84,7 @@ string[] expandArgs(string[] args) { import std.file : isFile, FileException, dirEntries, SpanMode; import std.algorithm.iteration : map; - import std.algorithm.searching : endsWith; + import std.algorithm.searching : endsWith, find; // isFile can throw if it's a broken symlink. bool isFileSafe(T)(T a) @@ -105,7 +105,7 @@ string[] expandArgs(string[] args) else foreach (item; dirEntries(arg, SpanMode.breadth).map!(a => a.name)) { - if (isFileSafe(item) && (item.endsWith(`.d`) || item.endsWith(`.di`))) + if (isFileSafe(item) && (item.endsWith(`.d`) || item.endsWith(`.di`)) && !item.find('.git')) rVal ~= item; else continue;