Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore empty lines #8

Closed
ldez opened this issue Apr 5, 2021 · 5 comments
Closed

Ignore empty lines #8

ldez opened this issue Apr 5, 2021 · 5 comments

Comments

@ldez
Copy link

ldez commented Apr 5, 2021

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
Copy link
Contributor

NiseVoid commented Apr 6, 2021

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
Copy link
Author

ldez commented Apr 6, 2021

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

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

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

@ldez
Copy link
Author

ldez commented Apr 6, 2021

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

@ldez
Copy link
Author

ldez commented Apr 6, 2021

main.go:5: Function 'main' is too long (80 > 60) (funlen)
func main() {
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
Copy link
Author

ldez commented Apr 6, 2021

So now I understand your explanation, thank you 👍

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

@ldez ldez closed this as completed Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants