Remove //nolint: gas directives from fmt.Fprintf #590 (#656)

Summary:
Filter out gas linter error checks for fmt.Fprintf commands. This required defining a custom linter around gas that additionally included the offending code.

Notes:

Gas format, without piping it through gometalinter, gives output like this:

$ gas -fmt=csv geth/jail/console/console.go
geth/jail/console/console.go,21,Errors unhandled.,LOW,HIGH,"fmt.Fprintf(w, ""%s: %s"", consoleEventName, formatForConsole(fn.ArgumentList))"
Gometalinter, by default, does not grab the line of code when it filters gas errors. To resolve this, I created a wrapper around gas (I wasn't sure what to call this "gas wrapper", I opted for gasv2, open to other names).

The first part of the regular expression was taken directly from gometalinter (see https://github.com/alecthomas/gometalinter/blob/master/linters.go#L236), and I then appended ,\".*\" to additionally grab the line of code of the offending line. Lastly, I excluded ".*Errors unhandled.*fmt.Fprintf.*" to filter out only fmt.Fprintf errors around omitted errors.

Also as a result of this change, gas lint output will now include the offending code.

Closes #590
This commit is contained in:
Alex Kohler 2018-02-14 12:58:20 -05:00 committed by Dmitry Shulyak
parent 15c72f3c6b
commit 228bda9fb3
5 changed files with 14 additions and 7 deletions

View File

@ -1,15 +1,22 @@
{
"Exclude": [
".*_mock.go",
"geth/jail/doc.go"
"geth/jail/doc.go",
".*Errors unhandled.*fmt.Fprint.*gasv2.*"
],
"Skip": ["helpers", "static"],
"Vendor": true,
"Test": true,
"Linters": {
"gasv2": {
"Command": "gas -fmt=csv",
"Pattern": "^(?P<path>.*?\\.go),(?P<line>\\d+),(?P<message>[^,]+,[^,]+,[^,]+,\".*\")"
}
},
"Enable": [
"deadcode",
"errcheck",
"gas",
"gasv2",
"goconst",
"gocyclo",
"gofmt",

View File

@ -276,7 +276,7 @@ Examples:
Options:
`
fmt.Fprint(os.Stderr, usage) // nolint: gas
fmt.Fprintf(os.Stderr, usage)
flag.PrintDefaults()
}

View File

@ -131,9 +131,9 @@ func Fatalf(reason interface{}, args ...interface{}) {
// find out whether error or string has been passed as a reason
r := reflect.ValueOf(reason)
if r.Kind() == reflect.String {
fmt.Fprintf(w, "Fatal Failure: %v\n%v\n", reason.(string), args) //nolint: gas
fmt.Fprintf(w, "Fatal Failure: %v\n%v\n", reason.(string), args)
} else {
fmt.Fprintf(w, "Fatal Failure: %v\n", reason.(error)) //nolint: gas
fmt.Fprintf(w, "Fatal Failure: %v\n", reason.(error))
}
debug.PrintStack()

View File

@ -18,7 +18,7 @@ func Write(fn otto.FunctionCall, w io.Writer, consoleEventName string) otto.Valu
})
// Next print out the giving values.
fmt.Fprintf(w, "%s: %s", consoleEventName, formatForConsole(fn.ArgumentList)) // nolint: gas
fmt.Fprintf(w, "%s: %s", consoleEventName, formatForConsole(fn.ArgumentList))
return otto.UndefinedValue()
}

View File

@ -91,7 +91,7 @@ func SetLogFile(filename string) error {
func levelFromString(level string) log.Lvl {
lvl, err := log.LvlFromString(strings.ToLower(level))
if err != nil {
fmt.Fprintf(os.Stderr, "Incorrect log level: %s, using defaults\n", level) // nolint: gas
fmt.Fprintf(os.Stderr, "Incorrect log level: %s, using defaults\n", level)
lvl = log.LvlInfo
}
return lvl