File tree 6 files changed +58
-0
lines changed
6 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -2183,6 +2183,7 @@ linters:
2183
2183
- whitespace
2184
2184
- wrapcheck
2185
2185
- wsl
2186
+ - xmlencoderclose
2186
2187
- zerologlint
2187
2188
2188
2189
# Enable all available linters.
@@ -2297,6 +2298,7 @@ linters:
2297
2298
- whitespace
2298
2299
- wrapcheck
2299
2300
- wsl
2301
+ - xmlencoderclose
2300
2302
- zerologlint
2301
2303
2302
2304
# 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 @@ -900,6 +900,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
900
900
WithPresets (linter .PresetStyle ).
901
901
WithURL ("https://github.com/bombsimon/wsl" ),
902
902
903
+ linter .NewConfig (golinters .NewXMLEncoderClose ()).
904
+ WithSince ("v1.54.0" ).
905
+ WithPresets (linter .PresetBugs ).
906
+ WithLoadForGoAnalysis ().
907
+ WithURL ("https://github.com/adamdecaf/xmlencoderclose" ),
908
+
903
909
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
904
910
linter .NewConfig (golinters .NewNoLintLint (noLintLintCfg )).
905
911
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