Skip to main content

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 two arguments:

  • --language: Defines the language of your project. Currently, only Go is supported.
  • --workspace: Defines the path to your project.

Tutorial: symflower lint

Let's take a look at some examples of rules covered by the symflower lint command.

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!