diff options
| author | Mark Otto <[email protected]> | 2017-07-01 12:58:12 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2017-07-01 22:57:19 -0700 |
| commit | c90cef019ae3b2b4ccdb52997ee96189a5fd6da0 (patch) | |
| tree | ddf0c5e477a8cb7e19992d6950fde88f66bd9dd2 /build | |
| parent | 337ead4b27238b66a36f88e4beb4b8e7a55d3773 (diff) | |
| download | bootstrap-c90cef019ae3b2b4ccdb52997ee96189a5fd6da0.tar.xz bootstrap-c90cef019ae3b2b4ccdb52997ee96189a5fd6da0.zip | |
Add bash script to lint our variables
Diffstat (limited to 'build')
| -rwxr-xr-x | build/lint-vars.sh | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/build/lint-vars.sh b/build/lint-vars.sh new file mode 100755 index 000000000..ae7f716c1 --- /dev/null +++ b/build/lint-vars.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# +# Approach: +# 1. Find variable declaration in the form of "$my-var: anyvalue" +# 2. Loop through found variables and find occurrences of each variable in all sass files +# 3. Filter out vars that occurred only once +# +# Run from command line with `build/lint-vars.sh scss`. +# +# Source: https://gist.github.com/badsyntax/6193491 + +if [ -z "$1" ]; then + echo "Please specify a directory as the first argument." + exit 1 +fi +if [ ! -d "$1" ]; then + echo "Not a valid directory." + exit 1 +fi + +echo "Finding unused variables. This might take some time..." + +vars=$(find "$1" -type f -name "*.scss" -exec grep --color=never -h '^$[a-zA-Z0-9_-][^:]*' {} \; | sed 's/$\([a-zA-Z0-9_-][^:]*\).*/\1/') + +for var in $vars; do + echo -n "Occurrences of \"\$$var\":" + find "$1" -type f -name "*.scss" -exec grep --color=never -h "$var" "{}" \; | wc -l +done | grep ' 1$' |
