File tree 6 files changed +60
-0
lines changed
6 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -2184,6 +2184,7 @@ linters:
2184
2184
- whitespace
2185
2185
- wrapcheck
2186
2186
- wsl
2187
+ - xmlencoderclose
2187
2188
- zerologlint
2188
2189
2189
2190
# Enable all available linters.
@@ -2298,6 +2299,7 @@ linters:
2298
2299
- whitespace
2299
2300
- wrapcheck
2300
2301
- wsl
2302
+ - xmlencoderclose
2301
2303
- zerologlint
2302
2304
2303
2305
# Enable presets.
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ require (
127
127
128
128
require (
129
129
github.com/Masterminds/semver v1.5.0 // indirect
130
+ github.com/adamdecaf/xmlencoderclose v0.0.0 // indirect
130
131
github.com/beorn7/perks v1.0.1 // indirect
131
132
github.com/cespare/xxhash/v2 v2.1.2 // indirect
132
133
github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 // indirect
@@ -147,6 +148,7 @@ require (
147
148
github.com/google/go-cmp v0.5.9 // indirect
148
149
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
149
150
github.com/gostaticanalysis/comment v1.4.2 // indirect
151
+ github.com/gostaticanalysis/sqlrows v0.0.0-20200307153552-ea5697937269 // indirect
150
152
github.com/hashicorp/errwrap v1.0.0 // indirect
151
153
github.com/hashicorp/hcl v1.0.0 // indirect
152
154
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 {
873
873
WithPresets (linter .PresetStyle ).
874
874
WithURL ("https://github.com/bombsimon/wsl" ),
875
875
876
+ linter .NewConfig (golinters .NewXMLEncoderClose ()).
877
+ WithSince ("v1.54.0" ).
878
+ WithPresets (linter .PresetBugs ).
879
+ WithLoadForGoAnalysis ().
880
+ WithURL ("https://github.com/adamdecaf/xmlencoderclose" ),
881
+
876
882
linter .NewConfig (golinters .NewZerologLint ()).
877
883
WithSince ("v1.53.0" ).
878
884
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