-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added format script to simplify avoiding .semgrep directory (#2946)
- Loading branch information
1 parent
831dd71
commit 8a96e3d
Showing
4 changed files
with
49 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
die() { echo -e "$@" 1>&2 ; exit 1; } | ||
|
||
AUTOFMT=true | ||
while getopts 'f:' OPTION; do | ||
case "$OPTION" in | ||
f) | ||
AUTOFMT="$OPTARG" | ||
;; | ||
esac | ||
done | ||
|
||
# Build a list of all the top-level directories in the project. | ||
for DIRECTORY in */ ; do | ||
GOGLOB="$GOGLOB ${DIRECTORY%/}" | ||
done | ||
GOGLOB="${GOGLOB/ docs/}" | ||
GOGLOB="${GOGLOB/ vendor/}" | ||
|
||
# Check that there are no formatting issues | ||
GOFMT_LINES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | wc -l | xargs` | ||
if $AUTOFMT; then | ||
# if there are files with formatting issues, they will be automatically corrected using the gofmt -w <file> command | ||
if [[ $GOFMT_LINES -ne 0 ]]; then | ||
FMT_FILES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | xargs` | ||
for FILE in $FMT_FILES; do | ||
echo "Running: gofmt -s -w $FILE" | ||
`gofmt -s -w $FILE` | ||
done | ||
fi | ||
else | ||
test $GOFMT_LINES -eq 0 || die "gofmt needs to be run, ${GOFMT_LINES} files have issues. Below is a list of files to review:\n`gofmt -s -l $GOGLOB`" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters