File tree Expand file tree Collapse file tree 6 files changed +60
-0
lines changed Expand file tree Collapse file tree 6 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -2184,6 +2184,7 @@ linters:
21842184 - whitespace
21852185 - wrapcheck
21862186 - wsl
2187+ - xmlencoderclose
21872188 - zerologlint
21882189
21892190 # Enable all available linters.
@@ -2298,6 +2299,7 @@ linters:
22982299 - whitespace
22992300 - wrapcheck
23002301 - wsl
2302+ - xmlencoderclose
23012303 - zerologlint
23022304
23032305 # 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 @@ -873,6 +873,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
873873 WithPresets (linter .PresetStyle ).
874874 WithURL ("https://github.com/bombsimon/wsl" ),
875875
876+ linter .NewConfig (golinters .NewXMLEncoderClose ()).
877+ WithSince ("v1.54.0" ).
878+ WithPresets (linter .PresetBugs ).
879+ WithLoadForGoAnalysis ().
880+ WithURL ("https://github.com/adamdecaf/xmlencoderclose" ),
881+
876882 linter .NewConfig (golinters .NewZerologLint ()).
877883 WithSince ("v1.53.0" ).
878884 WithPresets (linter .PresetBugs ).
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