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

Whitespace checks flexibility #135

Open
Gama11 opened this issue Mar 8, 2016 · 5 comments
Open

Whitespace checks flexibility #135

Gama11 opened this issue Mar 8, 2016 · 5 comments

Comments

@Gama11
Copy link
Member

Gama11 commented Mar 8, 2016

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 ;)
@AlexHaxe
Copy link
Member

AlexHaxe commented Mar 8, 2016

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.

@Gama11
Copy link
Member Author

Gama11 commented Mar 8, 2016

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

Gama11 commented Mar 10, 2016

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

@AlexHaxe
Copy link
Member

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.

@Gama11
Copy link
Member Author

Gama11 commented Mar 10, 2016

Seems like a good idea!

AlexHaxe added a commit to AlexHaxe/haxe-checkstyle that referenced this issue Mar 17, 2016
@AlexHaxe AlexHaxe self-assigned this Mar 17, 2016
AlexHaxe added a commit that referenced this issue Mar 19, 2016
added OperatorWhitespaceCheck, see #135
@AlexHaxe AlexHaxe removed their assignment Oct 8, 2016
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

2 participants