Skip to content

Add new linter canonicalheader #4672

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

Merged
merged 1 commit into from
Apr 25, 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
2 changes: 2 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,7 @@ linters:
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
- copyloopvar
Expand Down Expand Up @@ -2633,6 +2634,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
Loading