Symflower lint
Lint files. This feature 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 [OPTIONS] lint [lint-OPTIONS] [filters...]
The command takes the following arguments:
--fix
: Fix linting problems.--issue-url
: Holds the issue URL regular expression to check issue urls.--root
: The root package path of the project.- workspace options
--language
: Analyze with this language. By default all languages are used.--workspace
: The root directory of the project to analyze. (default: .)
The linter can also be enabled in editors (see Configuration section), offering quick fixes to resolve linting issues.
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!
Tutorial: symflower lint --fix
Linting issues detected by the command can be resolved using the --fix
flag in the CLI. Alternatively, you can use an editor to help fix the issues.
The following tutorial demonstrates how to use VSCode's quick fixes to resolve linting problems.