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

✨ New Universal.WhiteSpace.CommaSpacing sniff #254

Merged
merged 1 commit into from
Jul 18, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 18, 2023

New sniff to enforce no space before a comma and exactly one space, or a new line, after a comma.
Additionally, the sniff also enforces that the comma should follow the code and not be placed after a trailing comment.

For the spacing part, the sniff makes the following exceptions:

  1. A comma preceded or followed by a parenthesis, curly or square bracket.
    These will not be flagged to prevent conflicts with sniffs handling spacing around braces.
  2. A comma preceded or followed by another comma, like for skipping items in a list assignment.
    These will not be flagged.
  3. A comma preceded by a non-indented heredoc/nowdoc closer.
    In that case, unless the php_version config directive is set to a version higher than PHP 7.3.0, a new line before will be enforced to prevent parse errors on PHP < 7.3.

The sniff has a separate error code for when a comma is found with more than one space after it, followed by a trailing comment.
That way trailing comment alignment can be allowed by excluding that error code.

Additionally, the sniff uses modular error code suffixes for select situations, like *InFunctionDeclaration, *InFunctionCall, to allow for preventing duplicate messages if another sniff is already handling the comma spacing.

Includes raising the minimum PHPCSUtils version to 1.0.8 to prevent running into a particular bug in the SpacesFixer.

Note: a few of the test files will only run when the tests are run on PHP 7.3+ as the tests involve PHP 7.3+ flexible heredoc/nowdoc tokens, which is the one syntax which PHPCS cannot polyfill in the Tokenizer.

Includes fixers.
Includes unit tests.
Includes documentation.
Includes metrics.

New sniff to enforce no space before a comma and exactly one space, or a new line, after a comma.
Additionally,  the sniff also enforces that the comma should follow the code and not be placed after a trailing comment.

For the spacing part, the sniff makes the following exceptions:
1. A comma preceded or followed by a parenthesis, curly or square bracket.
    These will not be flagged to prevent conflicts with sniffs handling spacing around braces.
2. A comma preceded or followed by another comma, like for skipping items in a list assignment.
    These will not be flagged.
3. A comma preceded by a non-indented heredoc/nowdoc closer.
    In that case, unless the `php_version` config directive is set to a version higher than PHP 7.3.0, a new line before will be enforced to prevent parse errors on PHP < 7.3.

The sniff has a separate error code for when a comma is found with more than one space after it, followed by a trailing comment.
That way trailing comment alignment can be allowed by excluding that error code.

Additionally, the sniff uses modular error code suffixes for select situations, like `*InFunctionDeclaration`, `*InFunctionCall`, to allow for preventing duplicate messages if another sniff is already handling the comma spacing.

Includes raising the minimum PHPCSUtils version to `1.0.8` to prevent running into a particular bug in the `SpacesFixer`.

Note: a few of the test files will only run when the tests are run on PHP 7.3+ as the tests involve PHP 7.3+ flexible heredoc/nowdoc tokens, which is the one syntax which PHPCS cannot polyfill in the Tokenizer.

Includes fixers.
Includes unit tests.
Includes documentation.
Includes metrics.
@jrfnl jrfnl added this to the 1.1.0 milestone Jul 18, 2023
@jrfnl jrfnl merged commit b528415 into develop Jul 18, 2023
37 checks passed
@jrfnl jrfnl deleted the universal/new-commaspacing-sniff branch July 18, 2023 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant