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

File and Method Length Ignore Empty Lines #353

Open
pypmannetjies opened this issue Aug 22, 2017 · 7 comments
Open

File and Method Length Ignore Empty Lines #353

pypmannetjies opened this issue Aug 22, 2017 · 7 comments

Comments

@pypmannetjies
Copy link
Contributor

Sometimes it's nice to add new lines to create logical blocks inside a function. It would be great if there were an option to ignore empty lines when doing a line count.

I propose:

{
    "type": "MethodLength",
    "props": {
        "severity": "ERROR",
        "max": 50,
        "ignoreEmptyLines": true 
    }
}
@AlexHaxe
Copy link
Member

How about calling it countEmpty (see http://checkstyle.sourceforge.net/config_sizes.html#MethodLength)?
We might even go as far as making it an enum, e.g. with All, NoEmptyLines and NoEmptyLinesAndComments (maybe find shorter names).

@Gama11
Copy link
Member

Gama11 commented Aug 22, 2017

What if you want to ignore comments, but not empty lines? ;)

@pypmannetjies
Copy link
Contributor Author

pypmannetjies commented Aug 23, 2017

how about:

"ignore": [
    "comments",
    "emptyLines"
]

@AlexHaxe
Copy link
Member

I'm not sure users will actually use it, but if we change it, then we might as well go for a maximum of flexibility.
I mean it would be possible to have two MethodLength definitions (or more) inside your checkstyle.json, one with no ignores and one with ignore lines and / or comments, so you could have a hard limit of e.g. 200 lines and a limit for the number of active code lines of 100 per method, allowing up to 100 non-code lines.
It might help someone having lots of comments in their methods to lower the MethodLength maximum.

This might even lead to a separate test calculating a code vs non-code ratio...

@pypmannetjies
Copy link
Contributor Author

So would you have like "ActiveMethodLength" and the normal "MethodLength" as well?

@AlexHaxe
Copy link
Member

No, MethodLength can handle both cases (or all four), you can even define them in the same config file.

A check for measuring code to non-code ratios is a whole different thing, I'm not even sure if that makes sense on a method level.

@AlexHaxe
Copy link
Member

AlexHaxe commented Dec 1, 2019

I've come to the conclusion, that ignoreEmptyLines is much easier to understand than countEmpty.

Compatibility with Java checkstyle is not really necessary, since config files are not interchangeable between Haxe and Java and specific implementations might vary in scope or function. So people will have to read checkstyle docs either way.

I haven't added ignoring for comments, so I'll keep this issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants