mirror of
https://github.com/siderolabs/sidero.git
synced 2026-05-05 12:26:40 +02:00
chore: add golangci-lint configuration
Adapt it from Talos repo. Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
This commit is contained in:
parent
b3afd17a8e
commit
d15a960f93
@ -8,6 +8,7 @@
|
||||
!pkg
|
||||
!sfyra
|
||||
!templates
|
||||
!.golangci.yml
|
||||
!go.mod
|
||||
!go.sum
|
||||
!*.go
|
||||
|
||||
189
.golangci.yml
Normal file
189
.golangci.yml
Normal file
@ -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
|
||||
@ -38,7 +38,7 @@ ENV GOMODCACHE /.cache/mod
|
||||
RUN --mount=type=cache,target=/.cache go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0
|
||||
RUN --mount=type=cache,target=/.cache go install k8s.io/code-generator/cmd/conversion-gen@v0.21.0
|
||||
RUN --mount=type=cache,target=/.cache go install mvdan.cc/gofumpt/gofumports@v0.1.1
|
||||
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)
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
// nolint: golint,stylecheck
|
||||
//nolint:golint,stylecheck
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
// nolint: golint,stylecheck
|
||||
//nolint:golint,stylecheck
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
// nolint: golint,stylecheck
|
||||
//nolint:golint,stylecheck
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
|
||||
@ -31,7 +31,7 @@ var (
|
||||
setupLog = ctrl.Log.WithName("setup")
|
||||
)
|
||||
|
||||
// nolint: wsl
|
||||
//nolint:wsl
|
||||
func init() {
|
||||
_ = clientgoscheme.AddToScheme(scheme)
|
||||
_ = capiv1.AddToScheme(scheme)
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
// nolint: scopelint
|
||||
//nolint:scopelint
|
||||
package v1alpha1_test
|
||||
|
||||
import (
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
@ -73,7 +73,7 @@ func bootFileHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, bootFile)
|
||||
}
|
||||
|
||||
//nolint: unparam
|
||||
//nolint:unparam
|
||||
func bootFromDiskHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, ipxeBootFromDisk)
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ func NewClient(spec metalv1alpha1.ManagementAPI) (*Client, error) {
|
||||
func (c *Client) postRequest(path string) error {
|
||||
failureMode := DefaultDice.Roll()
|
||||
|
||||
switch failureMode { //nolint: exhaustive
|
||||
switch failureMode { //nolint:exhaustive
|
||||
case ExplicitFailure:
|
||||
return fmt.Errorf("simulated failure from the power management")
|
||||
case SilentFailure:
|
||||
@ -91,7 +91,7 @@ func (c *Client) SetPXE() error {
|
||||
func (c *Client) IsPoweredOn() (bool, error) {
|
||||
failureMode := DefaultDice.Roll()
|
||||
|
||||
switch failureMode { //nolint: exhaustive
|
||||
switch failureMode { //nolint:exhaustive
|
||||
case ExplicitFailure:
|
||||
return false, fmt.Errorf("simulated failure from the power management")
|
||||
case SilentFailure:
|
||||
|
||||
@ -43,7 +43,7 @@ var (
|
||||
setupLog = ctrl.Log.WithName("setup")
|
||||
)
|
||||
|
||||
// nolint: wsl
|
||||
//nolint:wsl
|
||||
func init() {
|
||||
_ = clientgoscheme.AddToScheme(scheme)
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ var testIntegrationCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
if !options.SkipTeardown {
|
||||
defer bootstrapCluster.TearDown(ctx) //nolint: errcheck
|
||||
defer bootstrapCluster.TearDown(ctx) //nolint:errcheck
|
||||
}
|
||||
|
||||
if err = bootstrapCluster.Setup(ctx); err != nil {
|
||||
@ -73,7 +73,7 @@ var testIntegrationCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
if !options.SkipTeardown {
|
||||
defer managementSet.TearDown(ctx) //nolint: errcheck
|
||||
defer managementSet.TearDown(ctx) //nolint:errcheck
|
||||
}
|
||||
|
||||
if err = managementSet.Setup(ctx); err != nil {
|
||||
|
||||
@ -121,7 +121,7 @@ func TestServerClassPatch(ctx context.Context, metalClient client.Client, cluste
|
||||
dummyServer, err := createDummyServer(ctx, metalClient, "dummyserver-0", dummySpec)
|
||||
require.NoError(t, err)
|
||||
|
||||
//nolint: errcheck
|
||||
//nolint:errcheck
|
||||
defer metalClient.Delete(ctx, &dummyServer)
|
||||
|
||||
installConfig := talosconfig.InstallConfig{
|
||||
@ -152,7 +152,7 @@ func TestServerClassPatch(ctx context.Context, metalClient client.Client, cluste
|
||||
dummyClass, err := createServerClass(ctx, metalClient, "dummyservers", classSpec)
|
||||
require.NoError(t, err)
|
||||
|
||||
//nolint: errcheck
|
||||
//nolint:errcheck
|
||||
defer metalClient.Delete(ctx, &dummyClass)
|
||||
|
||||
// Create "cluster" using serverclass above
|
||||
@ -214,7 +214,7 @@ func TestServerClassPatch(ctx context.Context, metalClient client.Client, cluste
|
||||
require.NoError(t, err)
|
||||
|
||||
if obj.GroupVersionKind().Kind == "Cluster" {
|
||||
//nolint: errcheck
|
||||
//nolint:errcheck
|
||||
defer dr.Delete(ctx, obj.GetName(), metav1.DeleteOptions{})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user