Skip to content
Open
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
223 changes: 115 additions & 108 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,91 +1,81 @@
version: '2'
run:
build-tags:
- integration
concurrency: 4
issues-exit-code: 1
tests: true
timeout: 5m

linters-settings:
errcheck:
check-blank: true
check-type-assertions: true
exhaustive:
default-signifies-exhaustive: true
goconst:
ignore-calls: false
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 15
gofumpt:
module-path: github.com/snyk/code-client-go
extra-rules: true
goimports:
local-prefixes: github.com/snyk/code-client-go
gosimple:
checks: ['all']
govet:
enable-all: true
disable:
- fieldalignment
lll:
line-length: 160
misspell:
locale: US
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
prealloc:
simple: true
range-loops: true
for-loops: true
promlinter:
strict: true
revive:
rules:
- name: blank-imports
disabled: true
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
disable-stuttering-check: true
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
disabled: true
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
staticcheck:
checks: ['all']
stylecheck:
checks: ['all']
http-status-code-whitelist: []
varcheck:
exported-fields: true

linters:
settings:
errcheck:
check-blank: true
check-type-assertions: true
exhaustive:
default-signifies-exhaustive: true
goconst:
ignore-calls: false
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 15
govet:
enable-all: true
disable:
- fieldalignment
lll:
line-length: 160
misspell:
locale: US
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
prealloc:
simple: true
range-loops: true
for-loops: true
promlinter:
strict: true
revive:
rules:
- name: blank-imports
disabled: true
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
disabled: true
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
staticcheck:
checks:
- all
- -ST1000 # Disable package comment enforcement.
- -ST1003 # Disable naming convention checks (e.g. myId -> myID).
unused:
exported-fields-are-used: false # Check unused exported fields
enable:
- asasalint
- asciicheck
Expand Down Expand Up @@ -146,6 +136,7 @@ linters:
#- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
# TODO(stylecheck): revisit in a followup; some breaking API changes
#- stylecheck
# NOTE: removed tagliatelle as it conflicts too much with existing API wireformats
Expand All @@ -156,36 +147,52 @@ linters:
- unconvert
# TODO(unparam): revisit
#- unparam
- unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can safely remove the - unused line from your linters.enable section because it's already covered by staticcheck with checks: ['all'].

Unless you really want it to be explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, I really dislike these linters being enabled without you actually realising it... I got confused multiple times during this task about why I was seeing lint rules for things I had removed...
I don't know if it is better to be explicit or not, I will let you decide.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These linters do not need to be listed.

Linters you can safely remove:

  • unused (line 150) - Already covered by staticcheck
  • gosimple - Not explicitly listed, but if it were, it would be redundant
  • stylecheck - Not explicitly listed, but if it were, it would be redundant

All other linters in your configuration provide unique functionality not covered by staticcheck.

Id think either list all linters that can be listed (that are in use), or don't list linters that are enabled by staticcheck already?

Copy link
Contributor Author

@rrama rrama Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to remove it and then I realised it feels weird to have unused listed in the settings, but not in the list of enabled linters. To someone who doesn't know better, this would look like a mistake.
I could add a comment on line 77 that it is enabled by staticcheck, would that be better than just listing it here even though it is redundant?

- usestdlibvars
- usetesting
- wastedassign
- whitespace
# TODO(wrapcheck): wrap errors in a followup
#- wrapcheck

issues:
exclude-dirs:
- "licenses"
- "pact"
- ".bin"
- ".github"
- ".vscode"
- "build"

exclude-rules:
- path: _test\.go
linters:
- bodyclose
- forcetypeassert
- goconst
- ireturn
- path: test/
linters:
- testpackage
- path: \.go
# TODO: remove this soon; unchecked errors are BAD
linters:
- errcheck
include:
- EXC0012
- EXC0014
exclusions:
paths:
- "licenses"
- "pact"
- ".bin"
- ".github"
- ".vscode"
- "build"
rules:
- path: _test\.go
linters:
- bodyclose
- forcetypeassert
- goconst
- ireturn
- path: test/
linters:
- testpackage
- path: \.go
# TODO: remove this soon; unchecked errors are BAD
linters:
- errcheck
formatters:
enable:
# TODO(gofumpt): revisit
#- gofumpt
- goimports
settings:
gofumpt:
module-path: github.com/snyk/code-client-go
extra-rules: true
goimports:
local-prefixes:
- github.com/snyk/code-client-go
exclusions:
paths:
- "licenses"
- "pact"
- ".bin"
- ".github"
- ".vscode"
- "build"
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ GOARCH = $(shell go env GOARCH)

TOOLS_BIN := $(shell pwd)/.bin

OVERRIDE_GOCI_LINT_V := v1.64.8
GOCI_LINT_TARGETS := $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/.golangci-lint_$(OVERRIDE_GOCI_LINT_V)
GOCI_LINT_V := v2.3.0
GOCI_LINT_TARGETS := $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/.golangci-lint_$(GOCI_LINT_V)

PACT_CLI_V := v2.4.4
PACT_CLI_TARGETS := $(TOOLS_BIN)/pact/bin/pact-broker $(TOOLS_BIN)/.pact_$(PACT_CLI_V)
Expand All @@ -21,14 +21,14 @@ tools: $(GOCI_LINT_TARGETS) $(PACT_CLI_TARGETS) $(PACT_GO_LIB_TARGETS)
$(TOOLS_BIN):
@mkdir -p $(TOOLS_BIN)

$(GOCI_LINT_TARGETS): $(TOOLS_BIN)
$(GOCI_LINT_TARGETS): | $(TOOLS_BIN)
@rm -f $(TOOLS_BIN)/.golangci-lint_*
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(OVERRIDE_GOCI_LINT_V)/install.sh | sh -s -- -b $(TOOLS_BIN) $(OVERRIDE_GOCI_LINT_V)
@touch $(TOOLS_BIN)/.golangci-lint_$(OVERRIDE_GOCI_LINT_V)
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOCI_LINT_V)/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOCI_LINT_V)
@touch $(TOOLS_BIN)/.golangci-lint_$(GOCI_LINT_V)

$(PACT_CLI_TARGETS): $(TOOLS_BIN)
$(PACT_CLI_TARGETS): | $(TOOLS_BIN)
@rm -f $(TOOLS_BIN)/.pact_*
@cd $(TOOLS_BIN); curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=$(PACT_CLI_V) bash; cd ../
@cd $(TOOLS_BIN) && curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=$(PACT_CLI_V) bash && cd ../
@touch $(TOOLS_BIN)/.pact_$(PACT_CLI_V)

$(PACT_GO_LIB_TARGETS):
Expand All @@ -39,16 +39,16 @@ $(PACT_GO_LIB_TARGETS):
.PHONY: format
format: $(GOCI_LINT_TARGETS)
@gofmt -w -l -e .
@$(TOOLS_BIN)/golangci-lint run --fix ./...
@$(TOOLS_BIN)/golangci-lint run --timeout=10m --fix ./...

.PHONY: lint
lint: $(GOCI_LINT_TARGETS)
ifdef CI
mkdir -p test/results
@$(TOOLS_BIN)/golangci-lint run --out-format junit-xml ./... > test/results/lint-tests.xml
else
@$(TOOLS_BIN)/golangci-lint run ./...
endif
ifdef CI
mkdir -p test/results
@$(TOOLS_BIN)/golangci-lint run --timeout=10m --output.junit-xml.path=test/results/lint-tests.xml ./...
else
@$(TOOLS_BIN)/golangci-lint run --timeout=10m ./...
endif

.PHONY: build
build:
Expand Down
7 changes: 3 additions & 4 deletions bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ import (
"os"
"testing"

"golang.org/x/net/html/charset"

"github.com/golang/mock/gomock"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/html/charset"

"github.com/snyk/code-client-go/bundle"
"github.com/snyk/code-client-go/internal/deepcode"
deepcodeMocks "github.com/snyk/code-client-go/internal/deepcode/mocks"
"github.com/snyk/code-client-go/internal/util"
"github.com/snyk/code-client-go/observability/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var bundleWithFiles = bundle.NewBatch(map[string]deepcode.BundleFile{"file": {}})
Expand Down
4 changes: 2 additions & 2 deletions internal/deepcode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"strconv"

"github.com/rs/zerolog"
"github.com/snyk/code-client-go/config"

"github.com/snyk/code-client-go/config"
codeClientHTTP "github.com/snyk/code-client-go/http"
"github.com/snyk/code-client-go/observability"
)
Expand Down Expand Up @@ -195,7 +195,7 @@ func (s *deepcodeClient) Host() (string, error) {

organization := s.config.Organization()
if organization == "" {
return "", errors.New("Organization is required in a fedramp environment")
return "", errors.New("organization is required in a fedramp environment")
}

u.Path = "/hidden/orgs/" + organization + "/code"
Expand Down
6 changes: 4 additions & 2 deletions internal/util/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package util_test

import (
"github.com/snyk/code-client-go/internal/util"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"

"github.com/snyk/code-client-go/internal/util"
)

func TestHttp_Hash(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions internal/util/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package util_test

import (
"github.com/snyk/code-client-go/internal/util"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"

"github.com/snyk/code-client-go/internal/util"
)

func TestHttp_ToRelativeUnixPath(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/util/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ package util

import (
"fmt"
"github.com/go-git/go-git/v5"
"net/url"

"github.com/go-git/go-git/v5"
)

func GetRepositoryUrl(path string) (string, error) {
Expand Down
Loading