From a38b4f8038d5096d9023c4af979515969e932583 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 11 Dec 2017 16:42:51 +0100 Subject: [PATCH] Pass svg_checks.sh via ShellCheck while read svgfile; do SC2162: read without -r will mangle backslashes. if [ $(wc -c < "$svgfile") -gt $(wc -c < "$outfile") ]; SC2046: quote to prevent word splitting found increment was done in a subshell and hence would not be properly incremented. Instead of: find | while Switch to: while < <( find ) Based on https://github.com/koalaman/shellcheck/wiki/SC2031 , this way $found is kept in the same context. Change-Id: Id8eb1027eed373161c8e7932b7745d4f53f2fc6c --- dev-scripts/svg_check.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dev-scripts/svg_check.sh b/dev-scripts/svg_check.sh index 963b7e575..220e43449 100755 --- a/dev-scripts/svg_check.sh +++ b/dev-scripts/svg_check.sh @@ -1,16 +1,15 @@ #!/usr/bin/env bash found=0 -find resources -type f -name '*.svg' | -while read svgfile; do +while read -r svgfile; do outfile="$svgfile.tmp" node_modules/.bin/svgo --config .svgo.yml -i "$svgfile" -o "$outfile" -q - if [ $(wc -c < "$svgfile") -gt $(wc -c < "$outfile") ]; then + if [ "$(wc -c < "$svgfile")" -gt "$(wc -c < "$outfile")" ]; then echo "File $svgfile is not compressed." found=$((found + 1)) fi rm "$outfile" -done +done < <(find resources -type f -name '*.svg') if [ $found -gt 0 ]; then echo "Found $found uncompressed SVG files. Please compress the files and re-submit the patch."