Skip to content

Commit 6d9e14c

Browse files
authored
chore: update Go version and configure golangci-lint v2
- Update `.golangci.yml` to use the v2 configuration format for linters and exclusions. - Explicitly define enabled linters and formatters, moving `gofmt` and `goimports` to the `formatters.enable` section. - Remove `gosimple` and `stylecheck` from the enabled linters. - Update the GitHub Actions workflow to specify `version: v2` for `golangci-lint-action` to match the project configuration. - Update `go.mod` to use `go 1.24.0` and update the toolchain to `go1.24.3`. - Update `CONTRIBUTING.md` to reflect that `golangci-lint` is managed as a project dependency via Go's tool system. - Modify `Makefile` to use `go tool golangci-lint run` for linting. - Adjust logging calls in `commands/build.go`, `commands/logging.go`, `commands/render.go`, `commands/run.go`, and `commands/serve.go` by removing `//nolint:govet` and ensuring correct formatting. - Update `filters/filters_test.go` to remove `rand.Seed(1)` and move the sample filter test to a dedicated function. - Update dependencies in `go.mod` and `go.sum` to newer versions. - Modify `renderers/markdown_toc.go` to use a `switch` statement for tag types, improving clarity. - Modify `server/watcher.go` and `site/rebuild.go` to use `%s` for error logging, replacing `err.Error()`.
1 parent 7aa68eb commit 6d9e14c

File tree

15 files changed

+1233
-73
lines changed

15 files changed

+1233
-73
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ jobs:
2222
# Cache disabled because golangci-lint-action has its own caching
2323
cache: false
2424
- name: golangci-lint
25-
uses: golangci/golangci-lint-action@v6
25+
uses: golangci/golangci-lint-action@v7
2626
with:
27-
# Use latest to automatically get versions built with newer Go
28-
version: latest
27+
version: v2.6.2
2928
# On PRs, only check new issues introduced by the PR
3029
only-new-issues: ${{ github.event_name == 'pull_request' }}
3130
args: --timeout=30m

.golangci.yml

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: "2"
2+
13
run:
24
timeout: 30m
35
tests: true
@@ -7,18 +9,13 @@ linters:
79
enable:
810
# Enabled by default
911
- errcheck # Check for unchecked errors
10-
- gosimple # Simplify code
1112
- govet # Reports suspicious constructs
1213
- ineffassign # Detect ineffectual assignments
1314
- staticcheck # Static analysis
1415
- unused # Check for unused code
1516

1617
# Additional recommended linters
17-
- gofmt # Check whether code was gofmt-ed
18-
- goimports # Check import statements are formatted
1918
- misspell # Find commonly misspelled English words
20-
- revive # Fast, configurable, extensible linter
21-
- stylecheck # Replacement for golint
2219
- unconvert # Remove unnecessary type conversions
2320
- gocyclo # Check cyclomatic complexity
2421
- gocritic # Comprehensive Go linter
@@ -27,34 +24,42 @@ linters:
2724
- depguard # Can be too restrictive for general use
2825
- unparam # Too many false positives for functions keeping params for consistency
2926

30-
linters-settings:
31-
gocyclo:
32-
# Maximum cyclomatic complexity of a function
33-
min-complexity: 15
27+
exclusions:
28+
rules:
29+
# Common false positives - fmt print functions and deferred cleanup don't need error checking
30+
- text: "Error return value of .((os\\.RemoveAll|fmt\\.(Fprint|Fprintf|Fprintln)|.*\\.Close|.*\\.Write|.*\\.Flush)). is not checked"
31+
linters: [errcheck]
3432

35-
misspell:
36-
locale: US
33+
# Exclude some linters from running on tests files
34+
- path: _test\.go
35+
linters:
36+
- gocyclo
37+
- errcheck
38+
- dupl
39+
- gosec
3740

38-
revive:
39-
# Minimal config - can be expanded based on project needs
40-
rules:
41-
- name: exported
42-
disabled: false
43-
- name: package-comments
44-
disabled: true # Not all packages need comments
41+
settings:
42+
gocyclo:
43+
min-complexity: 15
44+
45+
misspell:
46+
locale: US
47+
48+
revive:
49+
rules:
50+
- name: exported
51+
disabled: false
52+
- name: package-comments
53+
disabled: true
54+
55+
formatters:
56+
enable:
57+
- gofmt # Check whether code was gofmt-ed
58+
- goimports # Check import statements are formatted
4559

4660
issues:
4761
# Maximum issues count per linter
4862
max-issues-per-linter: 0
4963

5064
# Maximum count of issues with the same text
5165
max-same-issues: 0
52-
53-
# Exclude some linters from running on tests files
54-
exclude-rules:
55-
- path: _test\.go
56-
linters:
57-
- gocyclo
58-
- errcheck
59-
- dupl
60-
- gosec

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ make setup
2727
go get -t ./...
2828
```
2929

30-
[Install golangci-lint](https://golangci-lint.run/usage/install/#local-installation).
31-
On macOS: `brew install golangci-lint`
30+
golangci-lint is managed as a project dependency via Go's tool system. It will be automatically available after running `go get -t ./...`
3231

3332
Install the Dart Sass executable (required for tests):
3433
- On macOS: `brew install sass/sass/sass`

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ install:
4242
go install ${LDFLAGS} ${PACKAGE}
4343

4444
lint:
45-
golangci-lint run
45+
go tool golangci-lint run
4646

4747
test:
4848
go test ./...

commands/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func buildCommand(site *site.Site) error {
2626
elapsed := time.Since(commandStartTime)
2727
bannerLog.label("", "wrote %d files in %.2fs.", count, elapsed.Seconds())
2828
case watch:
29-
log.Error(err.Error())
29+
log.Error("%s", err.Error())
3030
default:
3131
return err
3232
}

commands/logging.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ func (l *bannerLogger) label(label string, msg string, a ...interface{}) {
2323
}
2424

2525
func (l *bannerLogger) path(label string, filename string) {
26-
//nolint:govet
27-
l.label(label, utils.MustAbs(filename))
26+
l.label(label, "%s", utils.MustAbs(filename))
2827
}

commands/render.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ func renderCommand(site *site.Site) error {
1616
return err
1717
}
1818
bannerLog.path("Render:", filepath.Join(site.SourceDir(), p.Source()))
19-
//nolint:govet
20-
bannerLog.label("URL:", p.URL())
19+
bannerLog.label("URL:", "%s", p.URL())
2120
bannerLog.label("Content:", "")
2221
return site.WriteDocument(os.Stdout, p)
2322
}

commands/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ func run(cmd string) error { // nolint: gocyclo
5454
// labels will line up. And print it even if
5555
// loading the site produced an error.
5656
if *versionFlag {
57-
//nolint:govet
58-
bannerLog.label("Version:", version.Version)
57+
bannerLog.label("Version:", "%s", version.Version)
5958
}
6059
if err != nil {
6160
return err

commands/serve.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var (
1515
func serveCommand(site *site.Site) error {
1616
server := server.Server{Site: site}
1717
return server.Run(*open, func(label, value string) {
18-
//nolint:govet
19-
bannerLog.label(label, value)
18+
bannerLog.label(label, "%s", value)
2019
})
2120
}

filters/filters_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package filters
22

33
import (
44
"fmt"
5-
"math/rand"
65
"strings"
76
"testing"
87
"time"
@@ -22,7 +21,6 @@ var filterTests = []struct{ in, expected string }{
2221

2322
// arrays
2423
{`{{ array | array_to_sentence_string }}`, "first, second, and third"},
25-
{`{{ array | sample }}`, "third"},
2624

2725
{`{{ site.members | group_by: "graduation_year" | map: "name" | sort | join }}`, "2013 2014 2015"},
2826
{`{{ site.members | group_by_exp: "item", "item.graduation_year" | size }}`, "4"},
@@ -107,15 +105,27 @@ var filterTestBindings = liquid.Bindings{
107105
}
108106

109107
func TestFilters(t *testing.T) {
110-
//nolint:staticcheck // Ignore this for now
111-
rand.Seed(1)
112108
for i, test := range filterTests {
113109
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
114110
requireTemplateRender(t, test.in, filterTestBindings, test.expected)
115111
})
116112
}
117113
}
118114

115+
func TestSampleFilter(t *testing.T) {
116+
engine := liquid.NewEngine()
117+
cfg := config.Default()
118+
AddJekyllFilters(engine, &cfg)
119+
120+
// Test that sample returns one of the array elements
121+
data, err := engine.ParseAndRender([]byte(`{{ array | sample }}`), filterTestBindings)
122+
require.NoError(t, err)
123+
result := strings.TrimSpace(string(data))
124+
125+
validResults := []string{"first", "second", "third"}
126+
require.Contains(t, validResults, result, "sample should return one of the array elements")
127+
}
128+
119129
// func TestXMLEscapeFilter(t *testing.T) {
120130
// data := map[string]interface{}{
121131
// "obj": map[string]interface{}{

0 commit comments

Comments
 (0)