ultraware / funlen

MIT License
37 stars 8 forks source link

Ignore empty lines #8

Closed ldez closed 3 years ago

ldez commented 3 years ago

funlen counts lines, but if you 2 functions with the same effective lines of code, one can produce a report and the other not, only because there are empty lines.

By following this rule, you promote the fact to remove the empty lines, I'm not sure this is expected.

I will great if you can, at least, add an option to ignore empty line from the count or just don't add the empty lines to the counters.

NiseVoid commented 3 years ago

The linecount including newlines is intended. Since in many cases people wouldn't try to workaround by removing newlines, and newlines are usually there because there's a lot of different things happening and still make you scroll trough the function a lot.

If you don't want funlen to consider whitespace it would probably be best to disable the check on lines and instead use only the check on statements, which looks at the number of statements in a function rather than how many lines those statements take up.

An example, this is 2 statements but 5 lines.

func main() {
    a := 1

    fmt.Println(
        `a:`, a,
    )
}
ldez commented 3 years ago

I'm talking about an empty line, not a new line :wink:

func main() {
    fmt.Println("foo")

    fmt.Println("bar")
}
func main() {
    fmt.Println("foo")
    fmt.Println("bar")
}
ldez commented 3 years ago

:thinking: maybe I did a wrong analysis, I try to reproduce a real case.

ldez commented 3 years ago
main.go:5: Function 'main' is too long (80 > 60) (funlen)
func main() {
```go package main import "fmt" func main() { fmt.Println("foo") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") fmt.Println("bar") } ```

So it's related to lines count not statements count.

ldez commented 3 years ago

So now I understand your explanation, thank you :+1:

Note for other users: to disable lines the value must a negative number.