Skip to content

Commit

Permalink
Add new linter canonicalheader (#4672)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasiar authored Apr 25, 2024
1 parent e953689 commit b2df2f4
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,7 @@ linters:
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
- copyloopvar
Expand Down Expand Up @@ -2639,6 +2640,7 @@ linters:
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
- copyloopvar
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ require (
github.com/kulti/thelper v0.6.3
github.com/kunwardeep/paralleltest v1.0.10
github.com/kyoh86/exportloopref v0.1.11
github.com/lasiar/canonicalheader v1.0.5
github.com/ldez/gomoddirectives v0.2.4
github.com/ldez/tagliatelle v0.5.0
github.com/leonklingele/grouper v1.1.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
"asciicheck",
"bidichk",
"bodyclose",
"canonicalheader",
"containedctx",
"contextcheck",
"copyloopvar",
Expand Down
19 changes: 19 additions & 0 deletions pkg/golinters/canonicalheader/canonicalheader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package canonicalheader

import (
"github.com/lasiar/canonicalheader"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func New() *goanalysis.Linter {
a := canonicalheader.Analyzer

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
11 changes: 11 additions & 0 deletions pkg/golinters/canonicalheader/canonicalheader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package canonicalheader_test

import (
"testing"

"github.com/golangci/golangci-lint/test/testshared/integration"
)

func TestFromTestdata(t *testing.T) {
integration.RunTestdata(t)
}
19 changes: 19 additions & 0 deletions pkg/golinters/canonicalheader/testdata/canonicalheader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//golangcitest:args -Ecanonicalheader
package testdata

import "net/http"

func canonicalheader() {
v := http.Header{}

v.Get("Test-HEader") // want `non-canonical header "Test-HEader", instead use: "Test-Header"`
v.Set("Test-HEader", "value") // want `non-canonical header "Test-HEader", instead use: "Test-Header"`
v.Add("Test-HEader", "value") // want `non-canonical header "Test-HEader", instead use: "Test-Header"`
v.Del("Test-HEader") // want `non-canonical header "Test-HEader", instead use: "Test-Header"`
v.Values("Test-HEader") // want `non-canonical header "Test-HEader", instead use: "Test-Header"`

v.Set("Test-Header", "value")
v.Add("Test-Header", "value")
v.Del("Test-Header")
v.Values("Test-Header")
}
7 changes: 7 additions & 0 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/golangci/golangci-lint/pkg/golinters/asciicheck"
"github.com/golangci/golangci-lint/pkg/golinters/bidichk"
"github.com/golangci/golangci-lint/pkg/golinters/bodyclose"
"github.com/golangci/golangci-lint/pkg/golinters/canonicalheader"
"github.com/golangci/golangci-lint/pkg/golinters/containedctx"
"github.com/golangci/golangci-lint/pkg/golinters/contextcheck"
"github.com/golangci/golangci-lint/pkg/golinters/copyloopvar"
Expand Down Expand Up @@ -154,6 +155,12 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithPresets(linter.PresetPerformance, linter.PresetBugs).
WithURL("https://github.com/timakin/bodyclose"),

linter.NewConfig(canonicalheader.New()).
WithSince("v1.58.0").
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/lasiar/canonicalHeader"),

linter.NewConfig(containedctx.New()).
WithSince("1.44.0").
WithLoadForGoAnalysis().
Expand Down

0 comments on commit b2df2f4

Please sign in to comment.