Skip to content

Instantly share code, notes, and snippets.

@curtisallen
Created May 1, 2017 19:22
Show Gist options
  • Save curtisallen/cc93939fffff14b9c9af668f82b04c5a to your computer and use it in GitHub Desktop.
Save curtisallen/cc93939fffff14b9c9af668f82b04c5a to your computer and use it in GitHub Desktop.
Danger with gometalinter

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment