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

Fix linter issues and use const version of golangci-lint #214

Merged
merged 1 commit into from
Oct 2, 2024
Merged
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
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