Skip to content

Commit 3703c56

Browse files
authored
Merge pull request #14364 from owen-mc/go/improve-output-of-check-formatting-in-makefile
Go: improve output of check formatting in makefile
2 parents 9c02b4f + bd2c49f commit 3703c56

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

go/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ autoformat:
3232
find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -w
3333

3434
check-formatting:
35-
test -z "$$(find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -l)"
35+
@output=$$(find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -l 2>&1); \
36+
if [ -n "$$output" ]; then \
37+
echo "The following files need to be reformatted using gofmt or have compilation errors:"; \
38+
echo "$$output"; \
39+
fi; \
40+
test -z "$$output"
3641

3742
ifeq ($(QHELP_OUT_DIR),)
3843
# If not otherwise specified, compile qhelp to markdown in place
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
func bad(w http.ResponseWriter, req *http.Request, []byte secret) (interface{}, error) {
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
func bad(w http.ResponseWriter, req *http.Request, secret []byte) (interface{}, error) {
29

310
secretHeader := "X-Secret"
411

@@ -8,4 +15,4 @@ func bad(w http.ResponseWriter, req *http.Request, []byte secret) (interface{},
815
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
916
}
1017
return nil, nil
11-
}
18+
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
func good(w http.ResponseWriter, req *http.Request, []byte secret) (interface{}, error) {
1+
package main
2+
3+
import (
4+
"crypto/subtle"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
func good(w http.ResponseWriter, req *http.Request, secret []byte) (interface{}, error) {
210

311
secretHeader := "X-Secret"
412

@@ -7,4 +15,4 @@ func good(w http.ResponseWriter, req *http.Request, []byte secret) (interface{},
715
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
816
}
917
return nil, nil
10-
}
18+
}

go/ql/src/experimental/CWE-74/DsnBad.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"fmt"
6+
"os"
7+
)
18

29
func bad() interface{} {
310
name := os.Args[1:]

go/ql/src/experimental/CWE-74/DsnGood.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"errors"
6+
"fmt"
7+
"os"
8+
"regexp"
9+
)
10+
111
func good() (interface{}, error) {
212
name := os.Args[1]
313
hasBadChar, _ := regexp.MatchString(".*[?].*", name)

0 commit comments

Comments
 (0)