Configuration

Isaev Denis edited this page Nov 29, 2018 · 12 revisions

Configuration

An analysis run in https://golangci.com can be configured by .golangci.(yml|toml|json) file. We will use the yaml format for examples.

A config file controls:

  1. how golangci-lint is run: which linters are enabled, which issues to skip, etc.
  2. https://golangci.com service work: how to fetch dependencies and prepare the environment, which version of golangci-lint to use, etc.

golangci-lint configuration

The description of this part of configuration can be found in golangci-lint doc

Service configuration

The service section isn't required in .golangci.yml config file, use it only if https://golangci.com can't analyze your repo by default.

.golangci.yml example:

service:
  project-path: mysite.com/goproject # vanity import path if needed
  golangci-lint-version: 1.12.x
  prepare:
    - make deps
    - make generate

How to test

To check the configuration, to check how https://golangci.com works with your repo, run:

docker run --rm -v $(pwd):/goapp -e RUN=1 -e REPO=github.com/project/repo golangci/build-runner goenvbuild

Use your repo's path instead of github.com/project/repo. If this run timeouts add -e TIMEOUT=10m to the docker command.

Config directives

  1. project-path - by default the project source code will be placed in $GOPATH/src/github.com/project/repo. By if vanity imports are necessary you may specify the import path by this directive. For example, the github.com/kubernetes/kubernetes project may specify project-path: k8s.io/kubernetes.

    Also, even if this option isn't specified we try to auto-detect a vanity import path:

    • parse go.mod file
    • search import aliases
    • extract go_import_path from .travis.yml
    • extract package from glide.yaml

    Setting this directive often can be useful when you connect forked repos to GolangCI to properly set the project path to the parent repository.

  2. golangci-lint-version: set golangci-lint version to use. The default value is 1.12.x - it means that we use the latest patch version in 1.12. You can set values like 1.12.1, 1.11.x. It's recommended to set the value to the version you use in CI and locally: otherwise there can be a mismatch between versions: e.g. you can see new issues in https://golangci.com.

  3. prepare: the list of shell commands to execute for the project preparation: dependencies fetching, running code generation, etc. Without this directive we try to fetch dependencies:

  • if the repo has non-empty vendor dir we do nothing
  • otherwise we guess the dependency tool: dep, godep, govendor, go mod or glide
  • if we can't fetch dependencies we fallback to go get. We run commands by bash -c {command} inside golangci/build-runner docker container.

Examples

Install needed library for Ullaakut/cameradar analysis (link):

# https://github.com/golangci/golangci/wiki/Configuration

service:
  project-path: github.com/Ullaakut/cameradar
  prepare:
    - apt-get update && apt-get install -y libcurl4-gnutls-dev
    - dep ensure

Run code generation before analysis (link):

# https://github.com/golangci/golangci/wiki/Configuration

service:
  project-path: github.com/fabric8-services/fabric8-auth
  prepare:
    - make deps generate

Install libsecret-1 before analysis (link):

# https://github.com/golangci/golangci/wiki/Configuration

service:
  prepare:
    - apt-get update && apt-get install -y libsecret-1-dev
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.