diff --git a/.golangci.example.yml b/.golangci.example.yml index 37a6a07e..8722d3f8 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -191,6 +191,39 @@ issues: exclude: - abcdef + # Excluding configuration per-path and per-linter + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + + # Ease some gocritic warnings on test files. + - path: _test\.go + text: "(unnamedResult|exitAfterDefer)" + linters: + - gocritic + + # Exclude known linters from partially hard-vendored code, + # which is impossible to exclude via "nolint" comments. + - path: internal/hmac/ + text: "weak cryptographic primitive" + linters: + - gosec + - path: internal/hmac/ + text: "Write\\` is not checked" + linters: + - errcheck + + # Ease linting on benchmarking code. + - path: cmd/stun-bench/ + linters: + - gosec + - errcheck + # Independently from option `exclude` we use default exclude patterns, # it can be disabled by this option. To list all # excluded by default patterns execute `golangci-lint run --help`. diff --git a/.golangci.yml b/.golangci.yml index 16bfba3e..e777c2e3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -37,7 +37,6 @@ linters: disable: - maligned - prealloc - - gosec - gochecknoglobals run: @@ -50,3 +49,9 @@ service: golangci-lint-version: 1.13.x # use fixed version to not introduce new linters unexpectedly prepare: - echo "here I can run custom commands, but no preparation needed" + +issues: + exclude-rules: + - text: "weak cryptographic primitive" + linters: + - gosec \ No newline at end of file diff --git a/README.md b/README.md index 70d74896..3847e798 100644 --- a/README.md +++ b/README.md @@ -715,6 +715,39 @@ issues: exclude: - abcdef + # Excluding configuration per-path and per-linter + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + + # Ease some gocritic warnings on test files. + - path: _test\.go + text: "(unnamedResult|exitAfterDefer)" + linters: + - gocritic + + # Exclude known linters from partially hard-vendored code, + # which is impossible to exclude via "nolint" comments. + - path: internal/hmac/ + text: "weak cryptographic primitive" + linters: + - gosec + - path: internal/hmac/ + text: "Write\\` is not checked" + linters: + - errcheck + + # Ease linting on benchmarking code. + - path: cmd/stun-bench/ + linters: + - gosec + - errcheck + # Independently from option `exclude` we use default exclude patterns, # it can be disabled by this option. To list all # excluded by default patterns execute `golangci-lint run --help`. @@ -785,7 +818,6 @@ linters: disable: - maligned - prealloc - - gosec - gochecknoglobals run: @@ -798,17 +830,24 @@ service: golangci-lint-version: 1.13.x # use fixed version to not introduce new linters unexpectedly prepare: - echo "here I can run custom commands, but no preparation needed" + +issues: + exclude-rules: + - text: "weak cryptographic primitive" + linters: + - gosec ``` ## False Positives False positives are inevitable, but we did our best to reduce their count. For example, we have a default enabled set of [exclude patterns](#command-line-options). If a false positive occurred you have the following choices: -1. Exclude issue by text using command-line option `-e` or config option `issues.exclude`. It's helpful when you decided to ignore all issues of this type. +1. Exclude issue by text using command-line option `-e` or config option `issues.exclude`. It's helpful when you decided to ignore all issues of this type. Also, you can use `issues.exclude-rules` config option for per-path or per-linter configuration. 2. Exclude this one issue by using special comment `//nolint[:linter1,linter2,...]` on issued line. Comment `//nolint` disables all issues reporting on this line. Comment e.g. `//nolint:govet` disables only govet issues for this line. If you would like to completely exclude all issues for some function prepend this comment above function: +3. Exclude issues in path by `run.skip-dirs`, `run.skip-files` or `issues.exclude-rules` config options. ```go //nolint diff --git a/README.tmpl.md b/README.tmpl.md index c76d2229..549af438 100644 --- a/README.tmpl.md +++ b/README.tmpl.md @@ -407,11 +407,12 @@ than the default and have more strict settings: False positives are inevitable, but we did our best to reduce their count. For example, we have a default enabled set of [exclude patterns](#command-line-options). If a false positive occurred you have the following choices: -1. Exclude issue by text using command-line option `-e` or config option `issues.exclude`. It's helpful when you decided to ignore all issues of this type. +1. Exclude issue by text using command-line option `-e` or config option `issues.exclude`. It's helpful when you decided to ignore all issues of this type. Also, you can use `issues.exclude-rules` config option for per-path or per-linter configuration. 2. Exclude this one issue by using special comment `//nolint[:linter1,linter2,...]` on issued line. Comment `//nolint` disables all issues reporting on this line. Comment e.g. `//nolint:govet` disables only govet issues for this line. If you would like to completely exclude all issues for some function prepend this comment above function: +3. Exclude issues in path by `run.skip-dirs`, `run.skip-files` or `issues.exclude-rules` config options. ```go //nolint