Skip to content
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

Fix warnings/errors reported by static code analysers #120

Merged
merged 1 commit into from
Nov 1, 2020

Conversation

shmsr
Copy link
Contributor

@shmsr shmsr commented Aug 21, 2020

Tools used: go vet, staticcheck, golangci-lint

Fixed some basic, small errors such as:

  1. Remove unnecessary use of fmt.Sprintf when arg is already a string
  2. Check errors
  3. Remove dead code blocks
  4. Remove unreachable code
  5. Don't put punctuation or new after error messages (in packages)

Sample output from golangci-lint, staticcheck:

  • staticcheck:
wsdl/wsdl.go:59:25: the argument is already a string, there's no need to use fmt.Sprintf (S1025)
wsdl/wsdl.go:61:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025)
wsdlgen/cli.go:44:10: error strings should not be capitalized (ST1005)
wsdlgen/cli.go:44:10: error strings should not end with punctuation or a newline (ST1005)
wsdlgen/config.go:42:20: func (*Config).publicName is unused (U1000)
xmltree/xmltree.go:272:12: error strings should not be capitalized (ST1005)
xmltree/xmltree_test.go:284:3: the surrounding loop is unconditionally terminated (SA4004)
xsd/parse.go:285:11: error strings should not be capitalized (ST1005)
xsd/parse.go:364:11: error strings should not end with punctuation or a newline (ST1005)
xsdgen/cli.go:104:10: error strings should not be capitalized (ST1005)
xsdgen/cli.go:104:10: error strings should not end with punctuation or a newline (ST1005)
xsdgen/config.go:49:20: func (*Config).errorf is unused (U1000)
xsdgen/config.go:438:16: error strings should not be capitalized (ST1005)
xsdgen/config.go:493:8: const soapenc is unused (U1000)
xsdgen/xsdgen.go:300:11: error strings should not end with punctuation or a newline (ST1005)
xsdgen/xsdgen.go:937:20: func (*Config).addTokenListMethods is unused (U1000)
  • golangci-lint:
wsdl/wsdl.go:18:2: `mimeNS` is unused (deadcode)
	mimeNS    = "https://schemas.xmlsoap.org/wsdl/mime/"
	^
wsdl/wsdl.go:19:2: `soapencNS` is unused (deadcode)
	soapencNS = "https://schemas.xmlsoap.org/soap/encoding/"
	^
wsdl/wsdl.go:20:2: `soapenvNS` is unused (deadcode)
	soapenvNS = "https://schemas.xmlsoap.org/soap/envelope/"
	^
wsdl/wsdl.go:21:2: `xsiNS` is unused (deadcode)
	xsiNS     = "https://www.w3.org/2000/10/XMLSchema-instance"
	^
wsdl/wsdl.go:22:2: `xsdNS` is unused (deadcode)
	xsdNS     = "https://www.w3.org/2000/10/XMLSchema"
	^
xsd/xsd.go:29:2: `schemaInstanceNS` is unused (deadcode)
	schemaInstanceNS = "https://www.w3.org/2001/XMLSchema-instance"
	^
xmltree/marshal.go:90:12: Error return value of `e.w.Write` is not checked (errcheck)
		e.w.Write([]byte("<!-- cycle detected -->"))
		         ^
xmltree/marshal.go:99:13: Error return value of `e.w.Write` is not checked (errcheck)
			e.w.Write(el.Content)
			         ^
xmltree/marshal.go:139:18: Error return value of `io.WriteString` is not checked (errcheck)
			io.WriteString(e.w, e.indent)
			              ^
xmltree/marshal.go:151:18: Error return value of `io.WriteString` is not checked (errcheck)
			io.WriteString(e.w, "\n")
			              ^
xmltree/marshal.go:161:19: Error return value of `io.WriteString` is not checked (errcheck)
				io.WriteString(e.w, e.indent)
				              ^
xmltree/xmltree.go:330:10: Error return value of `el.walk` is not checked (errcheck)
		el.walk(search)
		       ^
xmltree/xmltree.go:332:11: Error return value of `root.walk` is not checked (errcheck)
	root.walk(search)
	         ^
xmltree/xmltree_test.go:164:9: Error return value of `el.walk` is not checked (errcheck)
	el.walk(func(el *Element) {
	       ^
xmltree/xmltree_test.go:165:10: Error return value of `el.walk` is not checked (errcheck)
		el.walk(func(el *Element) {
		       ^
xsdgen/cli.go:102:10: Error return value of `fs.Parse` is not checked (errcheck)
	fs.Parse(arguments)
	        ^
wsdlgen/cli.go:42:10: Error return value of `fs.Parse` is not checked (errcheck)
	fs.Parse(arguments)
	        ^
wsdlgen/wsdlgen.go:309:16: composites: `encoding/xml.Name` composite literal uses unkeyed fields (govet)
			XMLName:    xml.Name{p.wsdl.TargetNS, part.Name},
			            ^
wsdlgen/wsdlgen.go:331:13: composites: `encoding/xml.Name` composite literal uses unkeyed fields (govet)
			XMLName: xml.Name{p.wsdl.TargetNS, part.Name},
			         ^
xmltree/xmltree.go:134:9: composites: `encoding/xml.Name` composite literal uses unkeyed fields (govet)
	return xml.Name{defaultns, qname}
	       ^
xmltree/example_test.go:228:1: tests: ExampleMarshalNested refers to unknown identifier: MarshalNested (govet)
func ExampleMarshalNested() {
^
xsd/xsd.go:303:2: unreachable: unreachable code (govet)
	return xml.Name{}
	^
xmltree/xmltree_test.go:284:3: SA4004: the surrounding loop is unconditionally terminated (staticcheck)
		break
		^
xsdgen/config.go:488:8: const `soapenc` is unused (unused)

Tools used: go vet, staticcheck, golangci-lint

Fixed some basic, small errors such as:
1. Remove unnecessary use of fmt.Sprintf when arg is already a string
2. Check errors
3. Remove dead code blocks
4. Remove unreachable code
5. Dont put punctuation or new after error messages (in packages)

There are still some warning(s) and error(s) that are left to be fixed.
@droyo droyo merged commit 900b57e into droyo:master Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants