Skip to content

Commit

Permalink
Some spring cleaning stuff similarly to what went on in ironlib (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmlb authored May 23, 2024
2 parents 5978f78 + 2fea6fc commit d698b4b
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 258 deletions.
11 changes: 11 additions & 0 deletions .chainguard/source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
spec:
authorities:
# Accept all keyless signatures validated from the public sigstore instance.
# This is open source software after all. All we want to know is that the
# person that did the commit has control over their email address.
- keyless:
url: https://fulcio.sigstore.dev
# Add this if you also want to allow commits signed by GitHub.
- key:
kms: https://github.com/web-flow.gpg
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @joelrebel @mmlb @splaspood @DoctorVin
6 changes: 3 additions & 3 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version-file: go.mod

- name: install cosign
uses: sigstore/cosign-installer@main
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version-file: go.mod

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.48.0
args: "--timeout=5m --out-${NO_FUTURE}format colored-line-number"
run: make lint
270 changes: 76 additions & 194 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,211 +1,93 @@
run:
# The default runtime timeout is 1m, which doesn't work well on Github Actions.
timeout: 4m
#
# 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!
#

# NOTE: This file is populated by the lint-install tool. Local adjustments may be overwritten.
linters-settings:
cyclop:
# NOTE: This is a very high transitional threshold
max-complexity: 37
package-average: 34.0
skip-tests: true

gocognit:
# NOTE: This is a very high transitional threshold
min-complexity: 98

dupl:
threshold: 200

threshold: 125
goconst:
min-len: 4
min-occurrences: 5
ignore-tests: true

gosec:
excludes:
- G107 # Potential HTTP request made with variable url
- G204 # Subprocess launched with function call as argument or cmd arguments
- G404 # Use of weak random number generator (math/rand instead of crypto/rand

errorlint:
# these are still common in Go: for instance, exit errors.
asserts: false
# Forcing %w in error wrapping forces authors to make errors part of their package APIs. The decision to make
# an error part of a package API should be a concious decision by the author.
# Also see Hyrums Law.
errorf: false

exhaustive:
default-signifies-exhaustive: true

nestif:
min-complexity: 8

nolintlint:
require-explanation: true
allow-unused: false
require-specific: true

min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- experimental
- performance
- style
disabled-checks:
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
gofumpt:
extra-rules: true
govet:
enable:
- shadow
lll:
line-length: 140
misspell:
locale: US
revive:
ignore-generated-header: true
severity: warning
rules:
- name: atomic
- name: blank-imports
- name: bool-literal-in-expr
- name: confusing-naming
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: deep-exit
- name: defer
- name: range-val-in-closure
- name: range-val-address
- name: dot-imports
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: identical-branches
- name: if-return
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: indent-error-flow
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
- name: struct-tag
- name: time-naming
- name: unexported-naming
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
- name: unconditional-recursion
- name: waitgroup-by-value

staticcheck:
go: "1.18"

unused:
go: "1.18"

output:
sort-results: true
confidence: 0

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
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
- dogsled
- dupl
- durationcheck
- errcheck
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- deadcode # deprecated
- depguard
- errname # maybe should be enabled
- exhaustivestruct # deprecated
- exhaustruct
- forbidigo
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- godot
- gofmt
- gofumpt
- gosec
- goheader
- goimports
- goprintffuncname
- gosimple
- govet
#- ifshort
- importas
- ineffassign
- makezero
- misspell
- nakedret
- 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
- nilerr
- noctx
- nilnil
- nlreturn
- nolintlint
- predeclared
# disabling for the initial iteration of the linting tool
# - promlinter
- revive
#- rowserrcheck
#- sqlclosecheck
- staticcheck
#- structcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
#- varcheck
#- wastedassign
- whitespace

# Disabled linters, due to being misaligned with Go practices
# - exhaustivestruct
# - gochecknoglobals
# - gochecknoinits
# - goconst
# - godox
# - goerr113
# - gomnd
# - lll
# - nlreturn
# - testpackage
# - wsl
# Disabled linters, due to not being relevant to our code base:
# - maligned
# - prealloc "For most programs usage of prealloc will be a premature optimization."
# Disabled linters due to bad error messages or bugs
# - tagliatelle
- 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:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- dupl
- errcheck
- forcetypeassert
- gocyclo
- gosec
- noctx

- path: .*cmd.*
linters:
- noctx

- path: main\.go
linters:
- noctx

- path: .*cmd.*
text: "deep-exit"

- path: main\.go
text: "deep-exit"

# This check is of questionable value
- linters:
- tparallel
text: "call t.Parallel on the top level as well as its subtests"

# Don't hide lint issues just because there are many of them
max-same-issues: 0
max-issues-per-linter: 0
- stylecheck
text: "ST1016"
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ build:
-X $(LDFLAG_LOCATION).Version=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"
lint:
golangci-lint run --config .golangci.yml --timeout=5m --out-${NO_FUTURE}format colored-line-number
go run github.com/golangci/golangci-lint/cmd/[email protected] run --config .golangci.yml --timeout=5m --out-format colored-line-number

lint-fix:
go run github.com/golangci/golangci-lint/cmd/[email protected] run --fix --config .golangci.yml --timeout=5m --out-format colored-line-number

test: lint
CGO_ENABLED=0 $(GOBINARY) test -timeout 1m -v -covermode=atomic ./...
5 changes: 2 additions & 3 deletions cmd/format_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package cmd
import (
"context"

"github.com/spf13/cobra"

"github.com/metal-toolbox/vogelkop/pkg/model"
"github.com/spf13/cobra"
)

var formatPartitionCmd = &cobra.Command{
Use: "format-partition",
Short: "Formats a partition",
Long: "Formats a partition with your choice of filesystem",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
ctx := context.Background()

if GetString(cmd, "device") == "" && GetString(cmd, "filesystem-device") == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/partition_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var partitionDiskCmd = &cobra.Command{
Short: "Partitions a block device",
Long: "Partitions a block device with a GPT table",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
ctx := context.Background()

partitions := GetStringSlice(cmd, "partitions")
Expand Down
Loading

0 comments on commit d698b4b

Please sign in to comment.