Mage: Add gofmt
to the Mage commands
Add two new mage commands: - `mage format`: run `gofmt` on all the Go sources. - `mage formatCheck`: run the formatter to check formatting issues. This will output the diff to make the code format-compliant. These commands are also available via `make format` resp. `make format-check`.
This commit is contained in:
parent
da4dd490d0
commit
f6d1d85722
8
Makefile
8
Makefile
@ -154,6 +154,12 @@ devserver-website:
|
||||
devserver-webapp: buildtool
|
||||
"${BUILDTOOL_PATH}" devServerWebapp
|
||||
|
||||
format: buildtool
|
||||
"${BUILDTOOL_PATH}" format
|
||||
|
||||
format-check: buildtool
|
||||
"${BUILDTOOL_PATH}" formatCheck
|
||||
|
||||
deploy-website:
|
||||
$(MAKE) -s check-environment
|
||||
rm -rf web/project-website/public/
|
||||
@ -311,4 +317,4 @@ publish-release-packages:
|
||||
${RELEASE_PACKAGE_LINUX} ${RELEASE_PACKAGE_DARWIN} ${RELEASE_PACKAGE_DARWIN_ARM64} ${RELEASE_PACKAGE_WINDOWS} ${RELEASE_PACKAGE_SHAFILE} \
|
||||
${WEBSERVER_SSH}:${WEBSERVER_ROOT}/downloads/
|
||||
|
||||
.PHONY: application version flamenco-manager flamenco-worker webapp webapp-static generate generate-go generate-py with-deps swagger-ui list-embedded test clean flamenco-manager-without-webapp
|
||||
.PHONY: application version flamenco-manager flamenco-worker webapp webapp-static generate generate-go generate-py with-deps swagger-ui list-embedded test clean flamenco-manager-without-webapp format format-check
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
|
||||
// Run unit tests, check for vulnerabilities, and run the linter
|
||||
func Check(ctx context.Context) {
|
||||
mg.CtxDeps(ctx, Test, Govulncheck, Staticcheck, Vet)
|
||||
mg.CtxDeps(ctx, Test, Govulncheck, Staticcheck, Vet, FormatCheck)
|
||||
}
|
||||
|
||||
// Run unit tests
|
||||
@ -59,3 +59,23 @@ func Staticcheck() error {
|
||||
func Vet() error {
|
||||
return sh.RunV(mg.GoCmd(), "vet", "./...")
|
||||
}
|
||||
|
||||
// Run `gofmt`, formatting all the source code.
|
||||
func Format() error {
|
||||
return sh.RunV("gofmt", "-s", "-w", ".")
|
||||
}
|
||||
|
||||
// Run `gofmt` on all the source code, reporting all differences.
|
||||
func FormatCheck(ctx context.Context) error {
|
||||
output, err := sh.Output("gofmt", "-d", ".")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if output == "" {
|
||||
// Format was OK.
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Formatting check failed:\n%s", output)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user