Skip to content

Commit

Permalink
chore: update lint settings, cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <[email protected]>
  • Loading branch information
kzantow committed Feb 9, 2024
1 parent d809cb4 commit 860923e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
46 changes: 34 additions & 12 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
run:
timeout: 10m
linters-settings:
funlen:
lines: 75
issues:
max-same-issues: 25

# TODO: enable this when we have coverage on docstring comments
# # The list of ids of default excludes to include or disable.
# include:
# - EXC0002 # disable excluding of issues about comments from golint

linters:
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
Expand Down Expand Up @@ -37,18 +39,38 @@ linters:
- unused
- whitespace

linters-settings:
funlen:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
# Default: 60
lines: 70
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
statements: 50
output:
uniq-by-line: false
run:
timeout: 10m

# do not enable...
# - deadcode # The owner seems to have abandoned the linter. Replaced by "unused".
# - deadcode # The owner seems to have abandoned the linter. Replaced by "unused".
# - depguard # We don't have a configuration for this yet
# - goprintffuncname # does not catch all cases and there are exceptions
# - nakedret # does not catch all cases and should not fail a build
# - gochecknoglobals
# - gochecknoinits # this is too aggressive
# - rowserrcheck disabled per generics https://github.com/golangci/golangci-lint/issues/2649
# - godot
# - godox
# - goerr113
# - golint # deprecated
# - gomnd # this is too aggressive
# - interfacer # this is a good idea, but is no longer supported and is prone to false positives
# - lll # without a way to specify per-line exception cases, this is not usable
# - maligned # this is an excellent linter, but tricky to optimize and we are not sensitive to memory layout optimizations
# - goimports # we're using gosimports now instead to account for extra whitespaces (see https://github.com/golang/go/issues/20818)
# - golint # deprecated
# - gomnd # this is too aggressive
# - interfacer # this is a good idea, but is no longer supported and is prone to false positives
# - lll # without a way to specify per-line exception cases, this is not usable
# - maligned # this is an excellent linter, but tricky to optimize and we are not sensitive to memory layout optimizations
# - nestif
# - nolintlint # as of go1.19 this conflicts with the behavior of gofmt, which is a deal-breaker (lint-fix will still fail when running lint)
# - prealloc # following this rule isn't consistently a good idea, as it sometimes forces unnecessary allocations that result in less idiomatic code
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LINT_CMD = $(TEMP_DIR)/golangci-lint run --tests=false --config .golangci.yaml
GOIMPORTS_CMD := $(TEMP_DIR)/gosimports -local github.com/anchore

# Tool versions #################################
GOLANGCILINT_VERSION := v1.52.2
GOLANGCILINT_VERSION := v1.56.0
GOSIMPORTS_VERSION := v0.3.8
BOUNCER_VERSION := v0.4.0
CHRONICLE_VERSION := v0.6.0
Expand Down
10 changes: 4 additions & 6 deletions deprecated.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stereoscope

import (
"slices"
"strings"
)

Expand All @@ -11,19 +12,16 @@ import (
// in the user input text is not necessary and should be avoided due to some ambiguity this introduces
func ExtractSchemeSource(userInput string, sources ...string) (source, newInput string) {
const SchemeSeparator = ":"

parts := strings.SplitN(userInput, SchemeSeparator, 2)
if len(parts) < 2 {
return "", userInput
}
// the user may have provided a source hint (or this is a split from a path or docker image reference, we aren't certain yet)
sourceHint := parts[0]
sourceHint = strings.TrimSpace(strings.ToLower(sourceHint))
// validate the hint against the possible tags
for _, source = range sources {
if source == sourceHint {
return source, parts[1]
}
// check the hint against the possible tags
if slices.Contains(sources, sourceHint) {
return sourceHint, parts[1]
}
// did not have any matching tags, scheme is not a valid provider scheme
return "", userInput
Expand Down
9 changes: 3 additions & 6 deletions tagged/tagged.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tagged
import (
"fmt"
"reflect"
"slices"
)

// Value holds an arbitrary value with associated tags
Expand Down Expand Up @@ -117,14 +118,10 @@ func (t ValueSet[T]) Join(taggedValues ...Value[T]) ValueSet[T] {
// Tags returns the unique set of tags from all entries
func (t ValueSet[T]) Tags() (tags []string) {
for _, entry := range t {
nextTag:
for _, tag := range entry.Tags {
for _, existing := range tags {
if tag == existing {
continue nextTag
}
if !slices.Contains(tags, tag) {
tags = append(tags, tag)
}
tags = append(tags, tag)
}
}
return tags
Expand Down

0 comments on commit 860923e

Please sign in to comment.