Skip to content

Commit

Permalink
chore: housekeeping, actions/lint bumps, some basic cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
carlmontanari committed Oct 1, 2023
1 parent 882eead commit ed717fe
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 79 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Commit
name: commit

on:
- push
Expand All @@ -9,7 +9,7 @@ jobs:
unit-test:
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 8
max-parallel: 12
matrix:
os:
- ubuntu-latest
Expand All @@ -19,9 +19,11 @@ jobs:
- "1.17"
- "1.18"
- "1.19"
- "1.20"
- "1.21"
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: set up go ${{ matrix.go-version }}
Expand All @@ -31,9 +33,9 @@ jobs:
- name: lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50
version: v1.54
args: --timeout 5m
- name: install gotestsum
run: go install gotest.tools/gotestsum@latest
run: go install gotest.tools/gotestsum@v1.10.1
- name: tests
run: make test
run: make test-race
108 changes: 48 additions & 60 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
linters-settings:
depguard:
list-type: blacklist
dupl:
threshold: 100
funlen:
lines: 100
lines: 150
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
Expand All @@ -17,95 +10,86 @@ linters-settings:
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
govet:
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
lll:
line-length: 100
tab-width: 4
stylecheck:
checks:
- "-ST1000"
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
revive:
rules:
- name: exported

linters:
enable:
- nlreturn
- forbidigo
- gofumpt
- asciicheck
- bodyclose
- depguard
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
- lll
- maintidx
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nlreturn
- noctx
- nolintlint
- nolintlint
- prealloc
- predeclared
- reassign
- revive
- rowserrcheck
- exportloopref
- staticcheck
- stylecheck
- tenv
- testpackage
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
- asciicheck
- gochecknoglobals
- gocognit
- godot
- godox
- goerr113
- nestif
- prealloc
- testpackage
- wsl

issues:
max-issues-per-linter: 0
max-same-issues: 0
# https://github.com/golangci/golangci-lint/issues/2439#issuecomment-1002912465
exclude-use-default: false
exclude-rules:
Expand All @@ -116,20 +100,24 @@ issues:
- structcheck
- unused
- unparam

# ignoring long lines due to json/yaml tags in platform
- path: platform/definition.go
linters:
- lll

# ignore package comments complaints in revive
- linters:
- revive
text: "package-comments"

run:
# running w/ 1.17 because we dont actually need/use 1.18 things and 1.18 breaks some linters.
go: '1.17'
go: '1.21'
skip-dirs:
- private

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
output:
uniq-by-line: false

service:
golangci-lint-version: 1.49.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
golangci-lint-version: 1.54.x
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ lint: ## Run linters

test: ## Run unit tests
gotestsum --format testname --hide-summary=skipped -- -coverprofile=cover.out ./...

test-race: ## Run unit tests with race flag
gotestsum --format testname --hide-summary=skipped -- -coverprofile=cover.out ./... -race
2 changes: 1 addition & 1 deletion aristaeos/loadconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *Platform) parseConfigPayload(config string) (stdConfig, eagerCfg string
eagerCfg = strings.Join(eagerS, "\n")

for _, s := range eagerS {
stdConfig = strings.Replace(stdConfig, s, "!", -1)
stdConfig = strings.ReplaceAll(stdConfig, s, "!")
}

return stdConfig, eagerCfg
Expand Down
2 changes: 1 addition & 1 deletion aristaeos/normalizeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "strings"
// kind of "header" pattern(s), but may vary from platform to platform.
func (p *Platform) NormalizeConfig(config string) string {
config = p.patterns.globalCommentLine.ReplaceAllString(config, "")
config = strings.Replace(config, "\n\n", "\n", -1)
config = strings.ReplaceAll(config, "\n\n", "\n")

return config
}
4 changes: 3 additions & 1 deletion ciscoiosxe/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var (
patternsOnce sync.Once //nolint:gochecknoglobals
)

const spaceAvailBufferPerc = 10

func getPatterns() *patterns {
patternsOnce.Do(func() {
patternsInst = &patterns{
Expand Down Expand Up @@ -44,7 +46,7 @@ func NewCiscoIOSXE(conn *network.Driver, opts ...util.Option) (*Platform, error)
"running": "show running-config",
"startup": "show startup-config",
},
spaceAvailBuffPerc: 10,
spaceAvailBuffPerc: spaceAvailBufferPerc,
}

for _, option := range opts {
Expand Down
2 changes: 1 addition & 1 deletion ciscoiosxr/normalizeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "strings"
// kind of "header" pattern(s), but may vary from platform to platform.
func (p *Platform) NormalizeConfig(config string) string {
config = p.patterns.outputHeader.ReplaceAllString(config, "")
config = strings.Replace(config, "\n\n", "\n", -1)
config = strings.ReplaceAll(config, "\n\n", "\n")

return config
}
2 changes: 1 addition & 1 deletion cisconxos/getcheckpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// GetCheckpoint gets a checkpoint file of the current running configuration.
func (p *Platform) GetCheckpoint(source string) (*response.Response, error) {
func (p *Platform) GetCheckpoint(_ string) (*response.Response, error) {
r := response.NewResponse("GetCheckpoint", p.conn.Transport.GetHost())

timestamp := time.Now().Unix()
Expand Down
2 changes: 1 addition & 1 deletion cisconxos/normalizeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "strings"
func (p *Platform) NormalizeConfig(config string) string {
config = p.patterns.outputHeader.ReplaceAllString(config, "")
config = p.patterns.checkpointLine.ReplaceAllString(config, "")
config = strings.Replace(config, "\n\n", "\n", -1)
config = strings.ReplaceAll(config, "\n\n", "\n")

return config
}
2 changes: 1 addition & 1 deletion juniperjunos/normalizeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "strings"
func (p *Platform) NormalizeConfig(config string) string {
config = p.patterns.outputHeader.ReplaceAllString(config, "")
config = p.patterns.edit.ReplaceAllString(config, "")
config = strings.Replace(config, "\n\n", "\n", -1)
config = strings.ReplaceAll(config, "\n\n", "\n")

return config
}
6 changes: 3 additions & 3 deletions platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *Cfg) Prepare() error {
if c.OnPrepare != nil {
err = c.OnPrepare(c.Conn)
if err != nil {
return nil
return err
}
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func (c *Cfg) LoadConfigFromFile(
}

// AbortConfig aborts a loaded candidate configuration.
func (c *Cfg) AbortConfig() (*response.Response, error) { //nolint: dupl
func (c *Cfg) AbortConfig() (*response.Response, error) {
c.Logger.Info("AbortConfig requested")

if !c.prepared {
Expand Down Expand Up @@ -262,7 +262,7 @@ func (c *Cfg) AbortConfig() (*response.Response, error) { //nolint: dupl
}

// CommitConfig commits a loaded candidate configuration.
func (c *Cfg) CommitConfig() (*response.Response, error) { //nolint: dupl
func (c *Cfg) CommitConfig() (*response.Response, error) {
c.Logger.Info("CommitConfig requested")

if !c.prepared {
Expand Down
11 changes: 8 additions & 3 deletions response/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"golang.org/x/term"
)

const (
half = 2
termWidthBuffer = 5
)

// NewDiffResponse returns a new DiffResponse object.
func NewDiffResponse(host string, opts ...util.Option) *DiffResponse {
r := &Response{
Expand Down Expand Up @@ -94,8 +99,8 @@ func (r *DiffResponse) SideBySideDiff() string {

termWidth := r.terminalWidth()

halfTermWidth := termWidth / 2
diffSideWidth := halfTermWidth - 5
halfTermWidth := termWidth / half
diffSideWidth := halfTermWidth - termWidthBuffer

sideBySideDiffLines := make([]string, 0)

Expand All @@ -106,7 +111,7 @@ func (r *DiffResponse) SideBySideDiff() string {
difflineLen := len(line)

if difflineLen-1 <= trimLen {
trimLen = difflineLen - 2
trimLen = difflineLen - 2 //nolint:gomnd
}

switch line[:2] {
Expand Down

0 comments on commit ed717fe

Please sign in to comment.