Merge pull request #14364 from owen-mc/go/improve-output-of-check-formatting-in-makefile

Go: improve output of check formatting in makefile
This commit is contained in:
Owen Mansel-Chan
2023-10-04 11:54:40 +01:00
committed by GitHub
5 changed files with 42 additions and 5 deletions

View File

@@ -32,7 +32,12 @@ autoformat:
find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -w
check-formatting:
test -z "$$(find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -l)"
@output=$$(find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -l 2>&1); \
if [ -n "$$output" ]; then \
echo "The following files need to be reformatted using gofmt or have compilation errors:"; \
echo "$$output"; \
fi; \
test -z "$$output"
ifeq ($(QHELP_OUT_DIR),)
# If not otherwise specified, compile qhelp to markdown in place

View File

@@ -1,4 +1,11 @@
func bad(w http.ResponseWriter, req *http.Request, []byte secret) (interface{}, error) {
package main
import (
"fmt"
"net/http"
)
func bad(w http.ResponseWriter, req *http.Request, secret []byte) (interface{}, error) {
secretHeader := "X-Secret"
@@ -8,4 +15,4 @@ func bad(w http.ResponseWriter, req *http.Request, []byte secret) (interface{},
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
}
return nil, nil
}
}

View File

@@ -1,4 +1,12 @@
func good(w http.ResponseWriter, req *http.Request, []byte secret) (interface{}, error) {
package main
import (
"crypto/subtle"
"fmt"
"net/http"
)
func good(w http.ResponseWriter, req *http.Request, secret []byte) (interface{}, error) {
secretHeader := "X-Secret"
@@ -7,4 +15,4 @@ func good(w http.ResponseWriter, req *http.Request, []byte secret) (interface{},
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
}
return nil, nil
}
}

View File

@@ -1,3 +1,10 @@
package main
import (
"database/sql"
"fmt"
"os"
)
func bad() interface{} {
name := os.Args[1:]

View File

@@ -1,3 +1,13 @@
package main
import (
"database/sql"
"errors"
"fmt"
"os"
"regexp"
)
func good() (interface{}, error) {
name := os.Args[1]
hasBadChar, _ := regexp.MatchString(".*[?].*", name)