-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add golangci-lint configuration
Adapt it from Talos repo. Signed-off-by: Alexey Palazhchenko <[email protected]>
- Loading branch information
Showing
14 changed files
with
209 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
!pkg | ||
!sfyra | ||
!templates | ||
!.golangci.yml | ||
!go.mod | ||
!go.sum | ||
!*.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
# This file contains all available configuration options | ||
# with their default values. | ||
|
||
# options for analysis running | ||
run: | ||
# default concurrency is a available CPU number | ||
# concurrency: 4 | ||
|
||
# timeout for analysis, e.g. 30s, 5m, default is 1m | ||
deadline: 10m | ||
|
||
# exit code when at least one issue was found, default is 1 | ||
issues-exit-code: 1 | ||
|
||
# include test files or not, default is true | ||
tests: true | ||
|
||
# which files to skip: they will be analyzed, but issues from them | ||
# won't be reported. Default value is empty list, but there is | ||
# no need to include all autogenerated files, we confidently recognize | ||
# autogenerated files. If it's not please let us know. | ||
skip-files: | ||
- .*\\.pb\\.go$ | ||
|
||
# list of build tags, all linters use it. Default is empty list. | ||
build-tags: [] | ||
|
||
# output configuration options | ||
output: | ||
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number" | ||
format: line-number | ||
|
||
# all available settings of specific linters | ||
linters-settings: | ||
errcheck: | ||
# report about not checking of errors in type assetions: `a := b.(MyStruct)`; | ||
# default is false: such cases aren't reported by default. | ||
check-type-assertions: true | ||
|
||
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; | ||
# default is false: such cases aren't reported by default. | ||
check-blank: true | ||
govet: | ||
# report about shadowed variables | ||
check-shadowing: true | ||
golint: | ||
# minimal confidence for issues, default is 0.8 | ||
min-confidence: 0.8 | ||
gofmt: | ||
# simplify code: gofmt with `-s` option, true by default | ||
simplify: true | ||
gocyclo: | ||
# minimal code complexity to report, 30 by default (but we recommend 10-20) | ||
min-complexity: 10 | ||
maligned: | ||
# print struct with more effective memory layout or not, false by default | ||
suggest-new: true | ||
dupl: | ||
# tokens count to trigger issue, 150 by default | ||
threshold: 100 | ||
goconst: | ||
# minimal length of string constant, 3 by default | ||
min-len: 3 | ||
# minimal occurrences count to trigger, 3 by default | ||
min-occurrences: 3 | ||
depguard: {} | ||
misspell: | ||
# Correct spellings using locale preferences for US or UK. | ||
# Default is to use a neutral variety of English. | ||
# Setting locale to US will correct the British spelling of 'colour' to 'color'. | ||
locale: US | ||
lll: | ||
# max line length, lines longer will be reported. Default is 120. | ||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option | ||
line-length: 200 | ||
# tab width in spaces. Default to 1. | ||
tab-width: 1 | ||
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 | ||
unparam: | ||
# call graph construction algorithm (cha, rta). In general, use cha for libraries, | ||
# and rta for programs with main packages. Default is cha. | ||
algo: cha | ||
|
||
# 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: false | ||
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: 30 | ||
nolintlint: | ||
allow-unused: false | ||
allow-leading-space: false | ||
allow-no-explanation: [] | ||
require-explanation: false | ||
require-specific: true | ||
prealloc: | ||
# XXX: we don't recommend using this linter before doing performance profiling. | ||
# For most programs usage of prealloc will be a premature optimization. | ||
|
||
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. | ||
# True by default. | ||
simple: true | ||
range-loops: true # Report preallocation suggestions on range loops, true by default | ||
for-loops: false # Report preallocation suggestions on for loops, false by default | ||
gci: | ||
local-prefixes: github.com/talos-systems/sidero | ||
cyclop: | ||
# the maximal code complexity to report | ||
max-complexity: 20 | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
# FIXME those linters should be enabled ASAP | ||
- cyclop | ||
- errcheck | ||
- forcetypeassert | ||
- gci | ||
- gocyclo | ||
- godot | ||
- golint | ||
- govet | ||
- lll | ||
- misspell | ||
- nlreturn | ||
- predeclared | ||
- revive | ||
- staticcheck | ||
- stylecheck | ||
|
||
- gas | ||
- typecheck | ||
- gochecknoglobals | ||
- gochecknoinits | ||
- ifshort | ||
- forbidigo | ||
- funlen | ||
- godox | ||
- gocognit | ||
- gomnd | ||
- goerr113 | ||
- nestif | ||
- exhaustivestruct | ||
- errorlint | ||
- paralleltest | ||
- thelper | ||
- wrapcheck | ||
# abandoned linters for which golangci shows the warning that the repo is archived by the owner | ||
- interfacer | ||
- maligned | ||
disable-all: false | ||
fast: false | ||
|
||
issues: | ||
# List of regexps of issue texts to exclude, empty list by default. | ||
# But independently from this option we use default exclude patterns, | ||
# it can be disabled by `exclude-use-default: false`. To list all | ||
# excluded by default patterns execute `golangci-lint run --help` | ||
exclude: | ||
- ^ST1000 # ST1000: package comment should be of the form "Package services ..." (stylecheck) | ||
|
||
exclude-rules: [] | ||
|
||
# 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`. | ||
# Default value for this option is true. | ||
exclude-use-default: false | ||
|
||
# Maximum issues count per one linter. Set to 0 to disable. Default is 50. | ||
max-per-linter: 0 | ||
|
||
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3. | ||
max-same: 0 | ||
|
||
# Show only new issues: if there are unstaged changes or untracked files, | ||
# only those changes are analyzed, else only changes in HEAD~ are analyzed. | ||
# It's a super-useful option for integration of golangci-lint into existing | ||
# large codebase. It's not practical to fix all existing issues at the moment | ||
# of integration: much better don't allow issues in new code. | ||
# Default is false. | ||
new: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ ENV GOMODCACHE /.cache/mod | |
RUN --mount=type=cache,target=/.cache go install sigs.k8s.io/controller-tools/cmd/[email protected] | ||
RUN --mount=type=cache,target=/.cache go install k8s.io/code-generator/cmd/[email protected] | ||
RUN --mount=type=cache,target=/.cache go install mvdan.cc/gofumpt/[email protected] | ||
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /usr/local/bin v1.28.0 | ||
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /toolchain/bin v1.38.0 | ||
WORKDIR /src | ||
COPY ./go.mod ./ | ||
COPY ./go.sum ./ | ||
|
@@ -206,9 +206,10 @@ RUN --mount=type=cache,target=/.cache --mount=type=cache,target=/root/.cache/go- | |
# The lint target performs linting on the source code. | ||
# | ||
FROM base AS lint-go | ||
COPY .golangci.yml . | ||
ENV GOGC=50 | ||
ENV GOLANGCI_LINT_CACHE /.cache/lint | ||
RUN --mount=type=cache,target=/.cache /usr/local/bin/golangci-lint run --enable-all --disable gochecknoglobals,gochecknoinits,lll,goerr113,funlen,nestif,maligned,gomnd,gocognit,gocyclo | ||
RUN --mount=type=cache,target=/.cache golangci-lint run --config .golangci.yml | ||
ARG MODULE | ||
RUN --mount=type=cache,target=/.cache FILES="$(gofumports -l -local ${MODULE} .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumports -w -local ${MODULE} .':\n${FILES}"; exit 1) | ||
# | ||
|
@@ -243,9 +244,10 @@ RUN --mount=type=cache,target=/.cache go list -mod=readonly all >/dev/null | |
RUN --mount=type=cache,target=/.cache ! go mod tidy -v 2>&1 | grep . | ||
|
||
FROM sfyra-base AS lint-sfyra | ||
COPY .golangci.yml . | ||
ENV GOGC=50 | ||
ENV GOLANGCI_LINT_CACHE /.cache/lint | ||
RUN --mount=type=cache,target=/.cache /usr/local/bin/golangci-lint run --enable-all --disable gochecknoglobals,gochecknoinits,lll,goerr113,funlen,nestif,maligned,gomnd,gocognit,gocyclo,godox | ||
RUN --mount=type=cache,target=/.cache golangci-lint run --config .golangci.yml | ||
ARG MODULE | ||
RUN --mount=type=cache,target=/.cache FILES="$(gofumports -l -local ${MODULE} .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumports -w -local ${MODULE} .':\n${FILES}"; exit 1) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters