File tree Expand file tree Collapse file tree 6 files changed +58
-0
lines changed Expand file tree Collapse file tree 6 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -2183,6 +2183,7 @@ linters:
21832183 - whitespace
21842184 - wrapcheck
21852185 - wsl
2186+ - xmlencoderclose
21862187 - zerologlint
21872188
21882189 # Enable all available linters.
@@ -2297,6 +2298,7 @@ linters:
22972298 - whitespace
22982299 - wrapcheck
22992300 - wsl
2301+ - xmlencoderclose
23002302 - zerologlint
23012303
23022304 # Enable presets.
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ require (
127127
128128require (
129129 github.com/Masterminds/semver v1.5.0 // indirect
130+ github.com/adamdecaf/xmlencoderclose v0.0.0 // indirect
130131 github.com/beorn7/perks v1.0.1 // indirect
131132 github.com/cespare/xxhash/v2 v2.1.2 // indirect
132133 github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 // indirect
@@ -147,6 +148,7 @@ require (
147148 github.com/google/go-cmp v0.5.9 // indirect
148149 github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
149150 github.com/gostaticanalysis/comment v1.4.2 // indirect
151+ github.com/gostaticanalysis/sqlrows v0.0.0-20200307153552-ea5697937269 // indirect
150152 github.com/hashicorp/errwrap v1.0.0 // indirect
151153 github.com/hashicorp/hcl v1.0.0 // indirect
152154 github.com/inconshreveable/mousetrap v1.1.0 // indirect
Original file line number Diff line number Diff line change 1+ package golinters
2+
3+ import (
4+ "github.com/adamdecaf/xmlencoderclose/pkg/analyzer"
5+ "golang.org/x/tools/go/analysis"
6+
7+ "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+ )
9+
10+ func NewXMLEncoderClose () * goanalysis.Linter {
11+ return goanalysis .NewLinter (
12+ "xmlencoderclose" ,
13+ "Checks that xml.Encoder is closed" ,
14+ []* analysis.Analyzer {
15+ analyzer .NewAnalyzer (),
16+ },
17+ nil ,
18+ ).WithLoadMode (goanalysis .LoadModeTypesInfo )
19+ }
Original file line number Diff line number Diff line change @@ -900,6 +900,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
900900 WithPresets (linter .PresetStyle ).
901901 WithURL ("https://github.com/bombsimon/wsl" ),
902902
903+ linter .NewConfig (golinters .NewXMLEncoderClose ()).
904+ WithSince ("v1.54.0" ).
905+ WithPresets (linter .PresetBugs ).
906+ WithLoadForGoAnalysis ().
907+ WithURL ("https://github.com/adamdecaf/xmlencoderclose" ),
908+
903909 // nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
904910 linter .NewConfig (golinters .NewNoLintLint (noLintLintCfg )).
905911 WithSince ("v1.26.0" ).
Original file line number Diff line number Diff line change 1+ //golangcitest:args -Exmlencoderclose
2+ package testdata
3+
4+ import (
5+ "bytes"
6+ "encoding/xml"
7+ )
8+
9+ func xmlEncoderClose () (string , error ) {
10+ type document struct {
11+ A string `xml:"a"`
12+ }
13+
14+ var buf bytes.Buffer
15+ err := xml .NewEncoder (& buf ).Encode (document { // want "Encoder.Close must be called"
16+ A : "abc123" ,
17+ })
18+ if err != nil {
19+ return "" , err
20+ }
21+ return buf .String (), nil
22+ }
You can’t perform that action at this time.
0 commit comments