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

Whitespace checks flexibility

Open Gama11 opened this issue 8 years ago • 5 comments

I'd like to enforce anonymous object declarations that look like this:

{ key: value, key: value }

I think this is currently not possible (except for the space after the comma with WhitespaceAfter and the , token).

  • Using the : token in WhitespaceAfter doesn't work, since there is no way to differentiate between object declarations and type hints (I still want name:Type for the latter).
  • Using the { token in WhitespaceAfter doesn't work, since it also triggers on empty blocks {} and reification expressions.
  • Using the } token in WhitespaceBefore doesn't work, since there is no WhitespaceBefore check yet ;)

Gama11 avatar Mar 08 '16 19:03 Gama11

How about writing a generic WhitespaceCheck, that has four modes: NoWhitespace, OnlyBefore, OnlyAfter and WhitespaceAround. It also has a list of tokens like in WhitespaceAround and a scope / context that limits where the mode applies. Possible scopes / contexts are ObjectDecl, FunctionDef, FieldDef, ArrayAccess, etc. Each check instance has one mode, multiple tokens and multiple scopes / contexts.

Depending on coding style WhitespaceCheck would occur multiple times in checkstyle.json, with different mode, token and context combinations, but I think that could cover all cases and we might even incorporate SpacingCheck (by opening up the range of supported tokens).

I have not started development, so if you would like to work on it, go ahead.

AlexHaxe avatar Mar 08 '16 20:03 AlexHaxe

Sounds good to me, I actually had something similar in mind!

For the modes I'd suggest different names: Before, After, Around and None.

Gama11 avatar Mar 08 '16 21:03 Gama11

One question is whether the old whitespace checks should be removed when adding this (breaking change).

Gama11 avatar Mar 10 '16 10:03 Gama11

Maybe we can keep them (marked as deprecated), but refactor them to use new whitespace check with matching parameters, so they are like dumbed down versions of the full check.

AlexHaxe avatar Mar 10 '16 10:03 AlexHaxe

Seems like a good idea!

Gama11 avatar Mar 10 '16 11:03 Gama11