Using gometalinter with Danger
Run your gometalinter command in CI with the --json
command save output to a file e.g. lint.json
go list -f '{{.Dir}}' ./... | grep -v 'vendor' | xargs gometalinter --vendored-linters --json > lint.json
Add the following to Dangerfile
# Show lint errors
lint_file = "./lint.json" # file from previous step
slug = "myprojectname/" # slug used to find and remove fully qualified file path
if File.exist?(lint_file)
lint = File.read(lint_file)
lint_errors = JSON.parse(lint)
lint_errors.each do |lint_error|
linter = lint_error["linter"]
path = lint_error["path"]
# from /Users/curtis_allen/src/src/github.com/curtisallen/myprojectname/cmd/myprojectname/main.go
# to cmd/myprojectname/main.go
file = path[path.index(slug)+slug.length..-1]
line = lint_error["line"]
message = lint_error["message"]
fail("#{github.html_link("#{file}#L#{line}")} #{linter}: #{message}", file: file, line: line)
end
end