Skip to content

Commit

Permalink
Add support for .lintignore.
Browse files Browse the repository at this point in the history
Lint-ing all of Weave Net is currently not desirable because:

* it would create conflicts on many branches,
* it would pollute the git history,
* etc.

and because `lint` currently lints all files except `./vendor`, this breaks Weave Net's build.
As a result, Weave Net is not using the latest commit in `build-tools`'s `master` branch, which is also source of problems:

* it limits standardisation of projects across Weaveworks,
* it limits the ability to use the latest features of `build-tools`,
* it complexifies merging changes in `build-tools` (e.g. #53 and weaveworks/weave#2694 for weaveworks/weave#2647),
* etc.

This change adds the ability to optionally process a `.lintignore` file, which can contain any number of `GLOB`s then used to filter out files one does not want to lint, a-la `.gitignore`.
This, coupled with a `.lintignore` file in Weave Net will then enable Weave Net to use the latest version of `build-tools`.
  • Loading branch information
marccarre committed Jan 24, 2017
1 parent 2b55c2d commit 315223a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lint
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ lint_files() {
exit $lint_result
}

filter_out() {
local globs="$1"
if [ -n "$globs" -a -r "$globs" ]; then
# Files to debug the regular expressions, as they get quite hairy:
local dir=${CIRCLE_ARTIFACTS:-/tmp}
local files_in=$(mktemp $dir/linted_files_in_XXX.txt)
local files_out=$(mktemp $dir/linted_files_out_XXX.txt)
# Globs blacklist found: filter out stdin before passing it to stdout:
while read -r filename; do
# Remove comments. Remove empty lines. Expand directories (e.g. "bin/" -> "bin/.*"). And then regexify globs.
# These regexes are then passed to grep to filter out matching elements from stdin:
echo "${filename}" | tee -a "$files_in" | grep -vEf <(sed '/^#.*$/d ; /^\s*$/d ; s/^\(.*\/\)$/\1*/g ; s/\([.|]\)/\\\1/g ; s/\?/./g ; s/\*/.*/g ; s/\(.*\)/\^\1\$/g' "$globs") | tee -a "$files_out"
done
else
# No globs blacklist was provided: simply propagate stdin to stdout:
while read -r filename; do echo "${filename}"; done
fi
}

list_files() {
if [ $# -gt 0 ]; then
git ls-files --exclude-standard | grep -vE '(^|/)vendor/'
Expand All @@ -179,4 +198,4 @@ list_files() {
fi
}

list_files "$@" | lint_files
list_files "$@" | filter_out .lintignore | lint_files

0 comments on commit 315223a

Please sign in to comment.