Debian Codegraph @

etc/check_fmt.sh

raw
1 #!/usr/bin/env bash
2 # check_fmt
3 # Runs go fmt on all packages in the repo and checks that *_example_test.go files have wrapped lines.
4
5 gofmt_out="$(go fmt ./...)"
6
7 if [[ $gofmt_out ]]; then
8 echo "go fmt check failed for:";
9 sed -e 's/^/ - /' <<< "$gofmt_out";
10 exit 1;
11 fi
12
13 # Use the "github.com/walle/lll" tool to check that all lines in *_example_test.go files are
14 # wrapped at 80 characters to keep them readable when rendered on https://pkg.go.dev.
15 # Ignore long lines that are comments containing URI-like strings and testable example output
16 # comments like "// Output: ...".
17 # E.g ignored lines:
18 # // "mongodb://ldap-user:ldap-pwd@localhost:27017/?authMechanism=PLAIN"
19 # // (https://www.mongodb.com/docs/manual/core/authentication-mechanisms-enterprise/#security-auth-ldap).
20 # // Output: {"myint": {"$numberLong":"1"},"int32": {"$numberLong":"1"},"int64": {"$numberLong":"1"}}
21 lll_out="$(find . -type f -name "*_examples_test.go" | lll -w 4 -l 80 -e '^\s*\/\/(.+:\/\/| Output:)' --files)"
22
23 if [[ $lll_out ]]; then
24 echo "lll check failed for:";
25 sed -e 's/^/ - /' <<< "$lll_out";
26 exit 1;
27 fi