Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move golangci-lint options to dedicated config file #42

Closed
atc0005 opened this issue Apr 10, 2020 · 0 comments · Fixed by #45
Closed

Move golangci-lint options to dedicated config file #42

atc0005 opened this issue Apr 10, 2020 · 0 comments · Fixed by #45
Assignees
Labels
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Apr 10, 2020

What

Instead of specifying the options like this:

golangci-lint run \
    -E goimports \
    -E gosec \
    -E stylecheck \
    -E goconst \
    -E depguard \
    -E prealloc \
    -E misspell \
    -E maligned \
    -E dupl \
    -E unconvert \
    -E golint \
    -E gocritic

Specify them something like this (copy/paste from another repo, not customized for our linters):

linters:
  enable:
    - dogsled
    - dupl
    - gocognit
    - goconst
    - gocritic
    - gocyclo
    - gofmt
    - golint
    - gosec
    - maligned
    - nakedret
    - prealloc
    - scopelint
    - unconvert
    - unparam
    - whitespace

linters-settings:
  funlen:
    lines: 60
    statements: 40

  gocognit:
    # minimal code complexity to report, 30 by default (but we recommend 10-20)
    min-complexity: 10

  gocyclo:
    # minimal code complexity to report, 30 by default (but we recommend 10-20)
    min-complexity: 15

  golint:
    # minimal confidence for issues, default is 0.8
    min-confidence: 0.3

  maligned:
    # print struct with more effective memory layout or not, false by default
    suggest-new: true

  nakedret:
    # make an issue if func has more lines of code than this setting and it has naked returns; default is 30
    max-func-lines: 2

  unparam:
    # Inspect exported functions, default is false. Set to true if no external program/library imports your code.
    # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
    # if it's called for subdir of a project it can't find external interfaces. All text editor integrations
    # with golangci-lint call it on a directory with the changed file.
    check-exported: true

  unused:
    # treat code as a program (not a library) and report unused exported identifiers; default is false.
    # XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
    # if it's called for subdir of a project it can't find funcs usages. All text editor integrations
    # with golangci-lint call it on a directory with the changed file.
    check-exported: false

  whitespace:
    # Enforces newlines (or comments) after every multi-line if statement
    multi-if: true
    # Enforces newlines (or comments) after every multi-line function signature
    multi-func: true

issues:
  # Not using default exclusions because we want to require comments on public
  # functions and types.
  exclude-use-default: false

# options for analysis running
run:
  # include test files or not, default is true
  tests: false

  # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
  # If invoked with -mod=readonly, the go command is disallowed from the implicit
  # automatic updating of go.mod described above. Instead, it fails when any changes
  # to go.mod are needed. This setting is most useful to check that go.mod does
  # not need updates, such as in a continuous integration and testing system.
  # If invoked with -mod=vendor, the go command assumes that the vendor
  # directory holds the correct copies of dependencies and ignores
  # the dependency descriptions in go.mod.
  modules-download-mode: vendor

service:
  # use the fixed version to not introduce new linters unexpectedly
  golangci-lint-version: 1.20.x

Why

By having an external config file (that is picked up automatically), this can be used in the Makefile, in manual golangci-lint runs and (I believe) via Visual Studio Code when golangci-lint is set as the default linter. It would be good to be able to set the linting options in one place and have all applicable use cases covered.

References

@atc0005 atc0005 added this to the v0.3.0 milestone Apr 10, 2020
@atc0005 atc0005 self-assigned this Apr 10, 2020
@atc0005 atc0005 modified the milestones: v0.3.0, Future Apr 10, 2020
atc0005 added a commit that referenced this issue Apr 11, 2020
Summary:

- Move linter choices from Makefile to separate include file

- Add scopelint linter to help catch variable use
  outside of intended scope

References:

- #42
- #44
- atc0005/todo#4
- dasrick/go-teams-notify#14
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant