diff --git a/.golangci.yaml b/.golangci.yaml index dfd5fe5c..39a9e2e3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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 @@ -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 diff --git a/Makefile b/Makefile index 38651e08..dced9302 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/deprecated.go b/deprecated.go index 65c52686..3d4d20d9 100644 --- a/deprecated.go +++ b/deprecated.go @@ -1,6 +1,7 @@ package stereoscope import ( + "slices" "strings" ) @@ -11,7 +12,6 @@ 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 @@ -19,11 +19,9 @@ func ExtractSchemeSource(userInput string, sources ...string) (source, newInput // 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 diff --git a/tagged/tagged.go b/tagged/tagged.go index 9e3a9443..3b03bba9 100644 --- a/tagged/tagged.go +++ b/tagged/tagged.go @@ -3,6 +3,7 @@ package tagged import ( "fmt" "reflect" + "slices" ) // Value holds an arbitrary value with associated tags @@ -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