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

add golangci-lint checks #77

Closed
wants to merge 6 commits into from
Closed
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
27 changes: 27 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://github.com/golangci/golangci-lint/issues/828#issuecomment-658207652
name: golangci-lint
on: [push, pull_request]
jobs:
resolve-modules:
name: Resolve Modules
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- id: set-matrix
run: ./hack/resolve-modules.sh
golangci:
name: Linter
needs: resolve-modules
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.43
working-directory: ${{ matrix.workdir }}
207 changes: 207 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
run:
# The default runtime timeout is 1m, which doesn't work well on Github Actions.
timeout: 4m

# 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

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

exhaustive:
default-signifies-exhaustive: true

nestif:
min-complexity: 8

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

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.16"

unused:
go: "1.16"

output:
sort-results: true

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- cyclop
- deadcode
- dogsled
- dupl
- durationcheck
- errcheck
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gocognit
- goconst
- gocritic
- godot
- gofmt
- gofumpt
- gosec
- goheader
- goimports
- goprintffuncname
- gosimple
- govet
- ifshort
- importas
- ineffassign
- makezero
- misspell
- nakedret
- nestif
- nilerr
- noctx
- 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

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
2 changes: 1 addition & 1 deletion actions/archive2disk/v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
archiveType := os.Getenv("ARCHIVE_TYPE")

if blockDevice == "" {
log.Fatalf("No Block Device speified with Environment Variable [DEST_DISK]")
log.Fatalf("No Block Device specified with Environment Variable [DEST_DISK]")
}

// Create the /mountAction mountpoint (no folders exist previously in scratch container)
Expand Down
13 changes: 7 additions & 6 deletions actions/archive2disk/v1/pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
// with compress set to true it will use gzip compression to expand the data before
// writing to an underlying device
func Write(archiveURL, archiveType, path string) error {

req, err := http.NewRequest("GET", archiveURL, nil)
if err != nil {
return err
Expand All @@ -40,7 +39,9 @@ func Write(archiveURL, archiveType, path string) error {

var out *tar.Reader
absPath, err := filepath.Abs(path)

if err != nil {
return err
}
switch archiveType {
case "gz":
// With compression run data through gzip writer
Expand All @@ -53,16 +54,16 @@ func Write(archiveURL, archiveType, path string) error {
case "tar":
// With compression run data through gzip writer
out = tar.NewReader(resp.Body)
//out = tarOUT
// out = tarOUT
case "targz":
// With compression run data through gzip writer
zipOUT, err := gzip.NewReader(resp.Body)
if err != nil {
log.Fatalf("[ERROR] New gzip reader:", err)
log.Fatal("[ERROR] New gzip reader:", err)
}
defer zipOUT.Close()
out = tar.NewReader(zipOUT)
//out = tarOUT
// out = tarOUT
default:

}
Expand All @@ -81,7 +82,7 @@ func Write(archiveURL, archiveType, path string) error {
absFileName := filepath.Join(absPath, fileName)
// if a dir, create it, then go to next segment
if finfo.Mode().IsDir() {
if err := os.MkdirAll(absFileName, 0755); err != nil {
if err := os.MkdirAll(absFileName, 0o755); err != nil {
return err
}
continue
Expand Down
19 changes: 6 additions & 13 deletions actions/cexec/v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ import (
log "github.com/sirupsen/logrus"
)

// Release - this struct contains the release information populated when building kexec
var Release struct {
Version string
Build string
}

const mountAction = "/mountAction"

func main() {

fmt.Printf("CEXEC - Chroot Exec\n------------------------\n")

// Parse the environment variables that are passed into the action
Expand All @@ -33,7 +26,7 @@ func main() {
var exitChroot func() error

if blockDevice == "" {
log.Fatalf("No Block Device speified with Environment Variable [BLOCK_DEVICE]")
log.Fatalf("No Block Device specified with Environment Variable [BLOCK_DEVICE]")
}

// Create the /mountAction mountpoint (no folders exist previously in scratch container)
Expand Down Expand Up @@ -65,17 +58,17 @@ func main() {
// Split the interpreter by space, in the event that the default intprepretter has flags.
di := strings.Split(defaultInterpreter, " ")
if len(di) == 0 {
log.Fatalln("Error parsing [\"DEFAULT_INTERPETER\"] [%s]", defaultInterpreter)
log.Fatalf("Error parsing [\"DEFAULT_INTERPETER\"] [%s]", defaultInterpreter)
}
// Look for default shell intepreter
// Look for default shell interpreter
_, err = os.Stat(di[0])
if os.IsNotExist(err) {
log.Fatalf("Unable to find the [\"DEFAULT_INTERPETER\"] [%s], check chroot and interpreter path", defaultInterpreter)
}
di = append(di, cmdLine)
cmd := exec.Command(di[0], di[1:]...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
var debugCMD = fmt.Sprintf("%s %v", di[0], di[1:])
debugCMD := fmt.Sprintf("%s %v", di[0], di[1:])
err = cmd.Start()
if err != nil {
log.Fatalf("Error starting [%s] [%v]", debugCMD, err)
Expand All @@ -85,13 +78,13 @@ func main() {
log.Fatalf("Error running [%s] [%v]", debugCMD, err)
}
} else {
// Format the cmdLine string into seperate execution tasks
// Format the cmdLine string into separate execution tasks
commandLines := strings.Split(cmdLine, ";")
for x := range commandLines {
command := strings.Split(commandLines[x], " ")
cmd := exec.Command(command[0], command[1:]...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
var debugCMD = fmt.Sprintf("%s %v", command[0], command[1:])
debugCMD := fmt.Sprintf("%s %v", command[0], command[1:])
err = cmd.Start()
if err != nil {
log.Fatalf("Error starting [%s] [%v]", debugCMD, err)
Expand Down
2 changes: 1 addition & 1 deletion actions/grub2disk/v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
fmt.Println("GRUB2Disk - GRUB streamer\n------------------------\n")
fmt.Print("GRUB2Disk - GRUB streamer\n------------------------\n\n")
grubInstallPath := os.Getenv("GRUB_INSTALL_PATH")
grubBlockDevice := os.Getenv("GRUB_DISK")
filesystemType := os.Getenv("FS_TYPE")
Expand Down
2 changes: 1 addition & 1 deletion actions/grub2disk/v1/pkg/grub/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func makeDirAndMount(devicePath string, mountPoint string, filesystemType string
return err
}

//if err = syscall.Mount(devicePath, mountPoint, filesystemType, flag, ""); err != nil {
// if err = syscall.Mount(devicePath, mountPoint, filesystemType, flag, ""); err != nil {
var params string
if filesystemType != "" {
params = "-t " + filesystemType
Expand Down
1 change: 0 additions & 1 deletion actions/image2disk/v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func main() {

fmt.Printf("IMAGE2DISK - Cloud image streamer\n------------------------\n")
disk := os.Getenv("DEST_DISK")
img := os.Getenv("IMG_URL")
Expand Down
Loading