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

bump golangci-lint #744

Merged
merged 3 commits into from
Feb 21, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
test:
strategy:
matrix:
go-version: ['1.22', '1.21']
go-version: ['1.23', '1.24']
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
timeout-minutes: 10
Expand All @@ -33,7 +33,7 @@ jobs:
cache: true
- uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
version: v1.64.2
args: --verbose
skip-cache: true
- name: Test
Expand Down
44 changes: 32 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,37 @@ issues:
linters:
disable-all: true
enable:
- errorlint
- gocritic
- gofmt
- goimports
- gomodguard
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- revive
- testifylint
- copyloopvar
- depguard
- errcheck
- errorlint
- gocritic
- gocyclo
- gofumpt
- goimports
- gomodguard
- revive
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- nolintlint
- revive
- staticcheck
- testifylint
- typecheck
- unconvert
- unparam
- unused
linters-settings:
depguard:
rules:
all:
deny:
- pkg: gopkg.in/yaml.v2
desc: 'compose-go uses yaml.v3'
gocritic:
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
Expand All @@ -35,6 +53,8 @@ linters-settings:
recommendations:
- errors
- fmt
lll:
line-length: 200
testifylint:
disable:
- float-compare
Expand Down
4 changes: 2 additions & 2 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.21
FROM golang:1.23

WORKDIR /go/src

ARG GOLANGCILINT_VERSION=v1.55.2
ARG GOLANGCILINT_VERSION=v1.64.5
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCILINT_VERSION}
RUN go install github.com/kunalkushwaha/ltag@latest && rm -rf /go/src/github.com/kunalkushwaha

Expand Down
10 changes: 0 additions & 10 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cli

import (
"context"
"fmt"
"io"
"os"
"path/filepath"
Expand All @@ -30,7 +29,6 @@ import (

"github.com/compose-spec/compose-go/v2/consts"
"github.com/compose-spec/compose-go/v2/dotenv"
"github.com/compose-spec/compose-go/v2/errdefs"
"github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/v2/types"
"github.com/compose-spec/compose-go/v2/utils"
Expand Down Expand Up @@ -551,14 +549,6 @@ func withListeners(options *ProjectOptions) func(*loader.Options) {
}
}

// getConfigPaths retrieves the config files for project based on project options
func (o *ProjectOptions) getConfigPaths() ([]string, error) {
if len(o.ConfigPaths) != 0 {
return absolutePaths(o.ConfigPaths)
}
return nil, fmt.Errorf("no configuration file provided: %w", errdefs.ErrNotFound)
}

func findFiles(names []string, pwd string) []string {
candidates := []string{}
for _, n := range names {
Expand Down
7 changes: 4 additions & 3 deletions cli/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ func TestProjectName(t *testing.T) {
})

t.Run("by COMPOSE_PROJECT_NAME", func(t *testing.T) {
os.Setenv("COMPOSE_PROJECT_NAME", "my_project_from_env") //nolint:errcheck
defer os.Unsetenv("COMPOSE_PROJECT_NAME") //nolint:errcheck
err := os.Setenv("COMPOSE_PROJECT_NAME", "my_project_from_env")
assert.NilError(t, err)
defer os.Unsetenv("COMPOSE_PROJECT_NAME")
opts, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithOsEnv)
assert.NilError(t, err)
p, err := ProjectFromOptions(context.TODO(), opts)
Expand Down Expand Up @@ -254,7 +255,7 @@ services:
os.Stdin = originalStdin
}()

w.WriteString(composeData)
_, _ = w.WriteString(composeData)
w.Close()

os.Stdin = r
Expand Down
2 changes: 1 addition & 1 deletion dotenv/godotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var startsWithDigitRegex = regexp.MustCompile(`^\s*\d.*`) // Keys starting with
// LookupFn represents a lookup function to resolve variables from
type LookupFn func(string) (string, bool)

var noLookupFn = func(s string) (string, bool) {
var noLookupFn = func(_ string) (string, bool) {
return "", false
}

Expand Down
5 changes: 2 additions & 3 deletions dotenv/godotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ func TestExpanding(t *testing.T) {
}
})
}

}

func TestVariableStringValueSeparator(t *testing.T) {
Expand Down Expand Up @@ -470,7 +469,7 @@ func TestLinesToIgnore(t *testing.T) {

for n, c := range cases {
t.Run(n, func(t *testing.T) {
got := string(newParser().getStatementStart(c.input))
got := newParser().getStatementStart(c.input)
if got != c.want {
t.Errorf("Expected:\t %q\nGot:\t %q", c.want, got)
}
Expand Down Expand Up @@ -718,7 +717,7 @@ func TestLoadWithFormat(t *testing.T) {
"ZOT": "QIX",
}

custom := func(r io.Reader, f string, lookup func(key string) (string, bool)) (map[string]string, error) {
custom := func(r io.Reader, _ string, lookup func(key string) (string, bool)) (map[string]string, error) {
vars := map[string]string{}
scanner := bufio.NewScanner(r)
for scanner.Scan() {
Expand Down
6 changes: 3 additions & 3 deletions dotenv/godotenv_var_expansion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var envMap = map[string]string{
"TEST_VAR": "Test Value",
}

var notFoundLookup = func(s string) (string, bool) {
var notFoundLookup = func(_ string) (string, bool) {
return "", false
}

Expand Down Expand Up @@ -45,7 +45,7 @@ func TestExpandIfEmptyOrUnset(t *testing.T) {
t.Run(expected.name, func(t *testing.T) {
result, err := expandVariables(expected.input, envMap, notFoundLookup)
require.NoError(t, err)
assert.Equal(t, result, expected.result)
assert.Equal(t, expected.result, result)
})
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestExpandIfUnset(t *testing.T) {
t.Run(expected.name, func(t *testing.T) {
result, err := expandVariables(expected.input, envMap, notFoundLookup)
require.NoError(t, err)
assert.Equal(t, result, expected.result)
assert.Equal(t, expected.result, result)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions dotenv/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ loop:
switch rune {
case '=', ':', '\n':
// library also supports yaml-style value declaration
key = string(src[0:i])
key = src[0:i]
offset = i + 1
inherited = rune == '\n'
break loop
Expand Down Expand Up @@ -157,7 +157,7 @@ func (p *parser) extractVarValue(src string, envMap map[string]string, lookupFn
// Remove inline comments on unquoted lines
value, _, _ = strings.Cut(value, " #")
value = strings.TrimRightFunc(value, unicode.IsSpace)
retVal, err := expandVariables(string(value), envMap, lookupFn)
retVal, err := expandVariables(value, envMap, lookupFn)
return retVal, rest, err
}

Expand Down
1 change: 0 additions & 1 deletion dotenv/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestParseBytes(t *testing.T) {
func TestParseVariable(t *testing.T) {
err := newParser().parse("%!(EXTRA string)=foo", map[string]string{}, nil)
assert.Error(t, err, "line 1: unexpected character \"%\" in variable name \"%!(EXTRA string)=foo\"")

}

func TestMemoryExplosion(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/compose-spec/compose-go/v2

go 1.21
go 1.23

require (
github.com/distribution/reference v0.5.0
Expand Down
8 changes: 4 additions & 4 deletions graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestTraversalWithMultipleParents(t *testing.T) {
done <- struct{}{}
}()

err := InDependencyOrder(ctx, &project, func(ctx context.Context, name string, _ types.ServiceConfig) error {
err := InDependencyOrder(ctx, &project, func(_ context.Context, name string, _ types.ServiceConfig) error {
svc <- name
return nil
})
Expand All @@ -80,7 +80,7 @@ func TestInDependencyUpCommandOrder(t *testing.T) {

var order []string
result, err := CollectInDependencyOrder(ctx, exampleProject(),
func(ctx context.Context, name string, _ types.ServiceConfig) (string, error) {
func(_ context.Context, name string, _ types.ServiceConfig) (string, error) {
order = append(order, name)
return name, nil
}, WithMaxConcurrency(10))
Expand All @@ -98,7 +98,7 @@ func TestInDependencyReverseDownCommandOrder(t *testing.T) {
t.Cleanup(cancel)

var order []string
fn := func(ctx context.Context, name string, _ types.ServiceConfig) error {
fn := func(_ context.Context, name string, _ types.ServiceConfig) error {
order = append(order, name)
return nil
}
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestWith_RootNodesAndUp(t *testing.T) {
expected.AddAll("C", "G", "D", "F")
var visited []string

gt := newTraversal(func(ctx context.Context, name string, service types.ServiceConfig) (any, error) {
gt := newTraversal(func(_ context.Context, name string, _ types.ServiceConfig) (any, error) {
mx.Lock()
defer mx.Unlock()
visited = append(visited, name)
Expand Down
4 changes: 2 additions & 2 deletions graph/traversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func newTraversal[S, T any](fn CollectorFn[S, T]) *traversal[S, T] {
}

// WithMaxConcurrency configure traversal to limit concurrency walking graph nodes
func WithMaxConcurrency(max int) func(*Options) {
func WithMaxConcurrency(concurrency int) func(*Options) {
return func(o *Options) {
o.maxConcurrency = max
o.maxConcurrency = concurrency
}
}

Expand Down
6 changes: 3 additions & 3 deletions interpolation/interpolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestInterpolateWithDefaults(t *testing.T) {
}

func TestValidUnexistentInterpolation(t *testing.T) {
var testcases = []struct {
testcases := []struct {
test string
expected string
errMsg string
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestValidUnexistentInterpolation(t *testing.T) {
}

func TestValidExistentInterpolation(t *testing.T) {
var testcases = []struct {
testcases := []struct {
test string
expected string
}{
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestInterpolateWithCast(t *testing.T) {
}

func TestPathMatches(t *testing.T) {
var testcases = []struct {
testcases := []struct {
doc string
path tree.Path
pattern tree.Path
Expand Down
5 changes: 4 additions & 1 deletion loader/extends.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a
source := deepClone(base).(map[string]any)

for _, processor := range post {
processor.Apply(map[string]any{
err = processor.Apply(map[string]any{
"services": map[string]any{
name: source,
},
})
if err != nil {
return nil, err
}
}
merged, err := override.ExtendService(source, service)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions loader/extends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ services:
}, func(options *Options) {
options.ResolvePaths = false
options.Listeners = []Listener{
func(event string, metadata map[string]any) {
func(event string, _ map[string]any) {
if event == "extends" {
extendsCount++
}
Expand Down Expand Up @@ -238,7 +238,6 @@ services:
})
assert.NilError(t, err)
assert.Equal(t, len(p.Services["test"].Ports), 1)

}

func TestLoadExtendsSameFile(t *testing.T) {
Expand Down Expand Up @@ -285,7 +284,7 @@ services:
options.SkipConsistencyCheck = true
options.SetProjectName("project", true)
options.Listeners = []Listener{
func(event string, metadata map[string]any) {
func(event string, _ map[string]any) {
if event == "extends" {
extendsCount++
}
Expand Down Expand Up @@ -433,7 +432,7 @@ func TestLoadExtendsListener(t *testing.T) {
options.SkipNormalization = true
options.ResolvePaths = true
options.Listeners = []Listener{
func(event string, metadata map[string]any) {
func(event string, _ map[string]any) {
if event == "extends" {
extendsCount++
}
Expand Down Expand Up @@ -481,7 +480,7 @@ services:
options.SkipConsistencyCheck = true
options.SetProjectName("project", true)
options.Listeners = []Listener{
func(event string, metadata map[string]any) {
func(event string, _ map[string]any) {
if event == "extends" {
extendsCount++
}
Expand Down
3 changes: 2 additions & 1 deletion loader/full-struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func services(workingDir, homeDir string) types.Services {
Devices: []types.DeviceMapping{
{
Source: "/dev/ttyUSB0", Target: "/dev/ttyUSB0", Permissions: "rwm",
}},
},
},
DNS: []string{"8.8.8.8", "9.9.9.9"},
DNSSearch: []string{"dc1.example.com", "dc2.example.com"},
DomainName: "foo.com",
Expand Down
Loading