Symflower lint
symflower lint
runs static analysis with preconfigured linting rules on your project. Default linting rules cover formatting and rules for more idiomatic code, enabling you to find bugs and performance issues. The command also offers simplifications and enforces style rules in the analyzed files.
Usage:
symflower lint --language=$language --workspace=$workspace
The command takes the following arguments:
--language
: Defines the language of your project. Currently, only Go is supported.--workspace
: Defines the path to your project.
Tutorial: symflower lint
The following tutorials provide examples of some of the rules offered by symflower lint
.
Rule: Instead of strconv.ParseInt(s, 10, 0)
, use strconv.Atoi(s)
as it is more readable and idiomatic.
Example:
package lint
import (
"strconv"
)
func parseStringToInt(s string) (int, error) {
result, err := strconv.ParseInt(s, 10, 0)
if err != nil {
return 0, err
}
return int(result), nil
}
Running the command symflower lint --language=golang
, we get the following output:
lint/lint.go:8: warning: Instead of `strconv.ParseInt(s, 10, 0)` use `strconv.Atoi(s)`
Give us your feedback and let us know how we can improve Symflower at hello@symflower.com or https://github.com/symflower/symflower. Thanks so much for your help!
Rule: Use strconv.Itoa
instead of fmt.Sprintf
for converting an integer to a string, since it is more efficient, readable, and idiomatic.
Example:
package lint
import (
"fmt"
)
func parseIntToString(i int) string {
return "Your number is " + fmt.Sprintf("%d", i)
}
Running the command symflower lint --language=golang
, we get the following output:
lint/lint.go:8: warning: Use "strconv.Itoa" instead of "fmt.Sprintf" for converting an integer to a string
Give us your feedback and let us know how we can improve Symflower at hello@symflower.com or https://github.com/symflower/symflower. Thanks so much for your help!
Rule: Do not use print
or println
calls as they are debugging functions.
Example:
package lint
func fullName(firstName string, lastName string) string {
println(firstName + " " + lastName)
return firstName + " " + lastName
}
After running the command with symflower lint --language=golang
, we get the following output:
lint/lint.go:4: warning: Do not use `print` or `println` calls as they are debugging functions
Give us your feedback and let us know how we can improve Symflower at hello@symflower.com or https://github.com/symflower/symflower. Thanks so much for your help!