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

Fix duplicate error being thrown / space after cast #1518

Merged
merged 1 commit into from Nov 2, 2018

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 2, 2018

Given the following test code:

<?php
$a = (bool) $b;
$a = (bool)$b;
$a = (bool)       $b;

The current sniffs/ruleset would result in the following errors related to cast spacing:

 3 | ERROR | [x] No space after closing casting parenthesis is prohibited
   |       |     (WordPress.WhiteSpace.CastStructureSpacing.NoSpaceAfterCloseParenthesis)
 3 | ERROR | [x] A cast statement must be followed by a single space
   |       |     (Generic.Formatting.SpaceAfterCast.NoSpace)
 4 | ERROR | [x] A cast statement must be followed by a single space
   |       |     (Generic.Formatting.SpaceAfterCast.TooMuchSpace)

The errors for line 3 are basically duplicates.
Additionally, as shown by line 4, as the upstream sniff also checks the width of the space after a type cast, that sniff is the better choice.

So in this PR, I'm removing the code which generated the WordPress.WhiteSpace.CastStructureSpacing.NoSpaceAfterCloseParenthesis error.

Includes adjusted unit test fixed file.

Given the following test code:
```php
<?php
$a = (bool) $b;
$a = (bool)$b;
$a = (bool)       $b;
```

The current sniffs/ruleset would result in the following errors related to cast spacing:
```
 3 | ERROR | [x] No space after closing casting parenthesis is prohibited
   |       |     (WordPress.WhiteSpace.CastStructureSpacing.NoSpaceAfterCloseParenthesis)
 3 | ERROR | [x] A cast statement must be followed by a single space
   |       |     (Generic.Formatting.SpaceAfterCast.NoSpace)
 4 | ERROR | [x] A cast statement must be followed by a single space
   |       |     (Generic.Formatting.SpaceAfterCast.TooMuchSpace)
```

The errors for line 3 are basically duplicates.
Additionally, as shown by line 4, as the upstream sniff also checks the width of the space after a type cast, that sniff is the better choice.

So in this PR, I'm removing the code which generated the `WordPress.WhiteSpace.CastStructureSpacing.NoSpaceAfterCloseParenthesis` error.

Includes adjusted unit test `fixed` file.
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting, that the upstream sniff does include fixers already, though they wouldn't apply when doing the unit tests for WPCS, hence, the .fixed file becomes a little un-fixed, to account for only the bits that WPCS does fix!

@GaryJones GaryJones merged commit aacadbd into develop Nov 2, 2018
@GaryJones GaryJones deleted the feature/remove-duplicate-castspacing-error branch November 2, 2018 15:11
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

2 participants