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

Use golangci-lint config from metal-toolbo/golangci-lint-config #108

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/push-pr-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
args: --config .golangci.yml --timeout 2m
version: v1.56.2
# Also need to update Makefile if/when renovate updates this
version: v1.57

- name: Test
run: go test ./...
Expand Down
170 changes: 70 additions & 100 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,123 +1,93 @@
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: v1.56.2 # use the fixed version to not introduce new linters unexpectedly
#
# This file lives in the github.com/metal-toolbox/golangci-lint-config repo.
#
# Do not edit this file outside of this repo otherwise we will be grumpy.
# Seriously though, this is meant to help promote a "standard" config and coding style.
# If you don't like something, lets have a discussion in GitHub issues!
#

linters-settings:
govet:
auto-fix: true
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
revive:
min-confidence: 0
gocyclo:
min-complexity: 15
dupl:
threshold: 100
threshold: 125
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
misspell:
locale: US
auto-fix: true
lll:
line-length: 140
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- experimental
- performance
- style
- experimental
disabled-checks:
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
gofumpt:
extra-rules: true
whitespace:
auto-fix: true
govet:
enable:
- shadow
lll:
line-length: 140
misspell:
locale: US
revive:
confidence: 0

linters:
enable:
- errcheck
- gosimple
- govet
- gofmt
- gocyclo
- ineffassign
- stylecheck
- misspell
- staticcheck
- unused
- prealloc
- typecheck
# additional linters
- bodyclose
- gocritic
- goerr113
- goimports
- revive
- misspell
- noctx
- stylecheck
- gosec
- contextcheck
- durationcheck
- errchkjson
- errorlint
- gochecksumtype
- nilerr
- reassign
- whitespace
- exportloopref

enable-all: false
disable-all: true

run:
# build-tags:
skip-dirs:
- internal/fixtures
skip-files:
- "(.*/)*.*_test.go"
enable-all: true
disable-all: false
# Linters we don't like
# Comments help explain why its disabled or point at ones we should not disable but will take a little work
# If its not commented its likely because its just too annoying or we don't find useful
disable:
- copyloopvar # requires go >=1.22
- cyclop
- deadcode # deprecated
- depguard
- errname # maybe should be enabled
- exhaustivestruct # deprecated
- exhaustruct
- forbidigo
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- godot
- godox
- golint # deprecated
- gomnd
- ifshort # deprecated
- inamedparam
- interfacebloat
- interfacer # deprecated
- intrange # requires go >=1.22
- ireturn # should be enabled, ironlib needs some changes
- lll # not previously enabled, ironlib and mctl both fail this
- maligned # deprecated
- nestif
- nilnil
- nlreturn
- nolintlint
- nonamedreturns # should be enabled, probably
- nosnakecase # deprecated
- paralleltest
- perfsprint
- scopelint # deprecated
- structcheck # deprecated
- tagliatelle
- tenv # should be enabled
- testpackage
- testifylint # should be enabled
- thelper # should be enabled
- varcheck # deprecated
- varnamelen
- wrapcheck
- wsl

issues:
exclude-rules:
- linters:
- gosec
text: "weak cryptographic primitive"

- linters:
- stylecheck
text: "ST1016"
exclude:
# Default excludes from `golangci-lint run --help` with EXC0002 removed
# EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments
# - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form)
# EXC0003 golint: False positive when tests are defined in package 'test'
- func name will be used as test\.Test.* by other packages, and that stutters; consider calling this
# EXC0004 govet: Common false positives
- (possible misuse of unsafe.Pointer|should have signature)
# EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
- ineffective break statement. Did you mean to break out of the outer loop
# EXC0006 gosec: Too many false-positives on 'unsafe' usage
- Use of unsafe calls should be audited
# EXC0007 gosec: Too many false-positives for parametrized shell calls
- Subprocess launch(ed with variable|ing should be audited)
# EXC0008 gosec: Duplicated errcheck checks
- (G104|G307)
# EXC0009 gosec: Too many issues in popular repos
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
# EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)'
- Potential file inclusion via variable
exclude-use-default: false
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ BUILD_DATE := $(shell date +%s)

## lint
lint:
golangci-lint run --config .golangci.yml
go run github.com/golangci/golangci-lint/cmd/[email protected] run --config .golangci.yml

## lint-fix - auto fix lint errors - for the linters that support auto fix
lint-fix:
golangci-lint run --config .golangci.yml --fix
go run github.com/golangci/golangci-lint/cmd/[email protected] run --fix --config .golangci.yml

## Go test
test:
Expand Down
4 changes: 1 addition & 3 deletions cmd/bios/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"github.com/spf13/cobra"
)

var (
biosFlags *biosActionFlags
)
var biosFlags *biosActionFlags

type biosActionFlags struct {
serverID string
Expand Down
3 changes: 1 addition & 2 deletions cmd/collect/collect.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package collect

import (
"github.com/spf13/cobra"

"github.com/metal-toolbox/mctl/cmd"
"github.com/spf13/cobra"
)

var collect = &cobra.Command{
Expand Down
11 changes: 3 additions & 8 deletions cmd/collect/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import (
"log"

"github.com/google/uuid"
"github.com/spf13/cobra"

coapiv1 "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
rctypes "github.com/metal-toolbox/rivets/condition"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
rctypes "github.com/metal-toolbox/rivets/condition"
"github.com/spf13/cobra"
)

type collectInventoryFlags struct {
Expand All @@ -21,16 +19,13 @@ type collectInventoryFlags struct {
skipBiosConfigCollect bool
}

var (
flagsDefinedCollectInventory *collectInventoryFlags
)
var flagsDefinedCollectInventory *collectInventoryFlags

var collectInventoryCmd = &cobra.Command{
Use: "inventory",
Short: "Collect current server firmware status and bios configuration",
Run: func(cmd *cobra.Command, _ []string) {
collectInventory(cmd.Context())

},
}

Expand Down
6 changes: 2 additions & 4 deletions cmd/collect/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"log"

"github.com/google/uuid"
"github.com/spf13/cobra"

rctypes "github.com/metal-toolbox/rivets/condition"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
rctypes "github.com/metal-toolbox/rivets/condition"
"github.com/spf13/cobra"
)

type inventoryStatusParams struct {
Expand Down
11 changes: 5 additions & 6 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import (
"strings"
"time"

bmclibcomm "github.com/bmc-toolbox/common"
"github.com/davecgh/go-spew/spew"
"github.com/google/uuid"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/pkg/errors"
"golang.org/x/net/context"

bmclibcomm "github.com/bmc-toolbox/common"
coapiv1 "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
fleetdbapi "github.com/metal-toolbox/fleetdb/pkg/api/v1"
"github.com/metal-toolbox/mctl/internal/app"
rctypes "github.com/metal-toolbox/rivets/condition"
rt "github.com/metal-toolbox/rivets/types"
"github.com/pkg/errors"
"golang.org/x/net/context"
)

var (
Expand Down Expand Up @@ -265,7 +264,7 @@ func FormatConditionResponse(response *coapiv1.ServerResponse, kind rctypes.Kind
func PrintResults(format string, data ...any) {
switch format {
case "text":
spew.Dump(data)
spew.Dump(data...)
case "json", "JSON":
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions cmd/create/bomupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"log"
"os"

"github.com/spf13/cobra"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/spf13/cobra"
)

// Create Bom informations.
Expand All @@ -16,9 +15,7 @@ type uploadBomFileFlags struct {
bomXlsxFile string
}

var (
flagsUploadBomFileFlags *uploadBomFileFlags
)
var flagsUploadBomFileFlags *uploadBomFileFlags

var uploadBomFile = &cobra.Command{
Use: "bom",
Expand Down
1 change: 0 additions & 1 deletion cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package create

import (
"github.com/metal-toolbox/mctl/cmd"

"github.com/spf13/cobra"
)

Expand Down
8 changes: 2 additions & 6 deletions cmd/create/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"os"

fleetdbapi "github.com/metal-toolbox/fleetdb/pkg/api/v1"

"github.com/spf13/cobra"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/spf13/cobra"
)

// Create
Expand All @@ -19,9 +17,7 @@ type createFirmwareFlags struct {
firmwareConfigFile string
}

var (
flagsDefinedCreateFirmware *createFirmwareFlags
)
var flagsDefinedCreateFirmware *createFirmwareFlags

var createFirmware = &cobra.Command{
Use: "firmware",
Expand Down
Loading
Loading