haxe-checkstyle
haxe-checkstyle copied to clipboard
Whitespace checks flexibility
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 inWhitespaceAfter
doesn't work, since there is no way to differentiate between object declarations and type hints (I still wantname:Type
for the latter). - Using the
{
token inWhitespaceAfter
doesn't work, since it also triggers on empty blocks{}
and reification expressions. - Using the
}
token inWhitespaceBefore
doesn't work, since there is noWhitespaceBefore
check yet ;)
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.
Sounds good to me, I actually had something similar in mind!
For the modes I'd suggest different names: Before
, After
, Around
and None
.
One question is whether the old whitespace checks should be removed when adding this (breaking change).
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.
Seems like a good idea!