Skip to content

Commit

Permalink
Fix linter issues and use const version of golangci-lint (#214)
Browse files Browse the repository at this point in the history
This fixes an issue surfacing after updating golangci-lint.
Switched to using a constant version of the tool to avoid such
issues in the future.

Signed-off-by: Piotr Piotrowski <[email protected]>
  • Loading branch information
piotrpio authored Oct 2, 2024
1 parent 55e094d commit 939c926
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
26 changes: 6 additions & 20 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
test:
strategy:
matrix:
go: [ '1.22' ]
go: [ '1.23' ]
os: [ ubuntu-latest, macOS-latest ]
runs-on: ${{matrix.os}}
steps:
Expand All @@ -19,29 +19,15 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: ${{matrix.go}}
- name: Install deps
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
cd /tmp
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: Lint
- name: go vet
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
go mod tidy
go vet ./...
golangci-lint run \
--no-config --exclude-use-default=false --max-same-issues=0 \
--disable errcheck \
--disable gocritic \
--enable stylecheck \
--enable unconvert \
--enable gofmt \
--enable misspell \
--enable unparam \
--enable nakedret \
--enable prealloc \
--enable misspell \
./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60

- name: Run tests
shell: bash --noprofile --norc -x -eo pipefail {0}
Expand Down
17 changes: 17 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
issues:
exclude-use-default: false
max-same-issues: 0

linters:
enable:
- stylecheck
- unconvert
- gofmt
- misspell
- unparam
- nakedret
- prealloc
- misspell
disable:
- errcheck
- gocritic
24 changes: 12 additions & 12 deletions surveyor/jetstream_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,47 +283,47 @@ func (o *JSAdvisoryConfig) Validate() error {
return fmt.Errorf("js advisory config cannot be nil")
}

var errs []string
var errs []error
if o.ID == "" {
errs = append(errs, "id is required")
errs = append(errs, fmt.Errorf("id is required"))
}

if o.AccountName == "" {
errs = append(errs, "name is required")
errs = append(errs, fmt.Errorf("name is required"))
}

if o.ExternalAccountConfig != nil {
if o.ExternalAccountConfig.MetricsSubject == "" {
errs = append(errs, "external_account_config.metrics_subject is required when importing metrics from external accounts")
errs = append(errs, fmt.Errorf("external_account_config.metrics_subject is required when importing metrics from external accounts"))
}
metricsTokens := strings.Split(o.ExternalAccountConfig.MetricsSubject, ".")
switch {
case o.ExternalAccountConfig.MetricsAccountTokenPosition <= 0:
errs = append(errs, "external_account_config.metrics_account_token_position is required when importing metrics from external accounts")
errs = append(errs, fmt.Errorf("external_account_config.metrics_account_token_position is required when importing metrics from external accounts"))
case o.ExternalAccountConfig.MetricsAccountTokenPosition > len(metricsTokens):
errs = append(errs, "external_account_config.metrics_account_token_position is greater than the number of tokens in external_account_config.metrics_subject")
errs = append(errs, fmt.Errorf("external_account_config.metrics_account_token_position is greater than the number of tokens in external_account_config.metrics_subject"))
case metricsTokens[o.ExternalAccountConfig.AdvisoryAccountTokenPosition-1] != "*":
errs = append(errs, "external_account_config.metrics_subject must have a wildcard token at the position specified by external_account_config.metrics_account_token_position")
errs = append(errs, fmt.Errorf("external_account_config.metrics_subject must have a wildcard token at the position specified by external_account_config.metrics_account_token_position"))
}

if o.ExternalAccountConfig.AdvisorySubject == "" {
errs = append(errs, "external_account_config.advisory_subject is required when importing advisories from external accounts")
errs = append(errs, fmt.Errorf("external_account_config.advisory_subject is required when importing advisories from external accounts"))
}
advisoryTokens := strings.Split(o.ExternalAccountConfig.AdvisorySubject, ".")
switch {
case o.ExternalAccountConfig.AdvisoryAccountTokenPosition <= 0:
errs = append(errs, "external_account_config.advisory_account_token_position is required when importing advisories from external accounts")
errs = append(errs, fmt.Errorf("external_account_config.advisory_account_token_position is required when importing advisories from external accounts"))
case o.ExternalAccountConfig.AdvisoryAccountTokenPosition > len(advisoryTokens):
errs = append(errs, "external_account_config.advisory_account_token_position is greater than the number of tokens in external_account_config.advisory_subject")
errs = append(errs, fmt.Errorf("external_account_config.advisory_account_token_position is greater than the number of tokens in external_account_config.advisory_subject"))
case advisoryTokens[o.ExternalAccountConfig.AdvisoryAccountTokenPosition-1] != "*":
errs = append(errs, "external_account_config.advisory_subject must have a wildcard token at the position specified by external_account_config.advisory_account_token_position")
errs = append(errs, fmt.Errorf("external_account_config.advisory_subject must have a wildcard token at the position specified by external_account_config.advisory_account_token_position"))
}
}
if len(errs) == 0 {
return nil
}

return errors.New(strings.Join(errs, ", "))
return errors.Join(errs...)
}

func (o *JSAdvisoryConfig) copy() *JSAdvisoryConfig {
Expand Down

0 comments on commit 939c926

Please sign in to comment.