Commit 189f7737 authored by Hayley Swimelar's avatar Hayley Swimelar Committed by Nick Thomas

Suggest golangci-lint for go project CI

[golangci-lint](https://github.com/golangci/golangci-lint) is a
configurable and fast metalinter and is the suggested alternative
to the now-deprecated
[gometalinter](https://github.com/alecthomas/gometalinter)

This job will generate a code coverage report that will be
picked up by the GitLab Merge Request UI.
parent 27d5228a
......@@ -78,13 +78,27 @@ projects:
All Go projects should include these GitLab CI/CD jobs:
```yaml
go lint:
image: golang:1.11
lint:
image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine
stage: test
script:
- go get -u golang.org/x/lint/golint
- golint -set_exit_status $(go list ./... | grep -v "vendor/")
# Use default .golangci.yml file from the image if one is not present in the project root.
- '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .'
# Write the code coverage report to gl-code-quality-report.json
# and print linting issues to stdout in the format: path/to/file:line description
- golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"'
artifacts:
reports:
codequality: gl-code-quality-report.json
paths:
- gl-code-quality-report.json
allow_failure: true
```
Including a `.golangci.yml` in the root directory of the project allows for
configuration of `golangci-lint`. All options for `golangci-lint` are listed in
this [example](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml).
Once [recursive includes](https://gitlab.com/gitlab-org/gitlab-foss/issues/56836)
become available, you will be able to share job templates like this
[analyzer](https://gitlab.com/gitlab-org/security-products/ci-templates/raw/master/includes-dev/analyzer.yml).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment