haxe-checkstyle icon indicating copy to clipboard operation
haxe-checkstyle copied to clipboard

File and Method Length Ignore Empty Lines

Open pypmannetjies opened this issue 8 years ago • 7 comments

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 
    }
}

pypmannetjies avatar Aug 22 '17 13:08 pypmannetjies

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).

AlexHaxe avatar Aug 22 '17 16:08 AlexHaxe

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

Gama11 avatar Aug 22 '17 21:08 Gama11

how about:

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

pypmannetjies avatar Aug 23 '17 06:08 pypmannetjies

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...

AlexHaxe avatar Aug 23 '17 08:08 AlexHaxe

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

pypmannetjies avatar Aug 23 '17 09:08 pypmannetjies

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 avatar Aug 23 '17 10:08 AlexHaxe

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.

AlexHaxe avatar Dec 01 '19 11:12 AlexHaxe