Skip to content

Ensure that Typed Properties are spaced correctly #166

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

Merged
merged 1 commit into from
Mar 23, 2020

Conversation

carusogabriel
Copy link
Contributor

@carusogabriel carusogabriel commented Mar 22, 2020

This new rule checks for things like:

  • one space between the typehint and the property name
  • one space between the typehint and the property's modifiers
  • no space between the nullability symbol and the typehint

This rule does not check for:

  • How many lines the typed properties are separated by
  • If two consecutive properties have default values, the = sign will be aligned

This also falls under the PSR-12, by the item 4.3:

There MUST be a space between type declaration and property name.

This new rule checks for things like:

- no space between the typehint and the property name
- no space between the typehint and the property's modifiers
- no space between the nullability symbol and the typehint

This rule does not check for:

- How many lines the typed properties are separated by
- If two consecutive properties have default values, the `=` sign will be aligned# Please enter the commit message for your changes. Lines starting
@carusogabriel carusogabriel added this to the 8.0.0 milestone Mar 22, 2020
@carusogabriel carusogabriel requested a review from a team as a code owner March 22, 2020 16:48
@@ -380,6 +380,7 @@
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing"/>
Copy link
Contributor Author

@carusogabriel carusogabriel Mar 22, 2020

Choose a reason for hiding this comment

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

The comment for this rule and the others are on lines 360-362:

<!-- Require types to be written as natively if possible;
require iterable types to specify phpDoc with their content;
forbid useless/duplicated information in phpDoc -->

@@ -29,7 +29,8 @@ index d1fdd9f..4b5f6e4 100644
tests/input/new_with_parentheses.php 18 0
tests/input/not_spacing.php 8 0
tests/input/null_coalesce_operator.php 3 0
@@ -27,21 +29,22 @@ tests/input/optimized-functions.php 1 0
tests/input/optimized-functions.php 1 0
+tests/input/PropertyTypeHintSpacing.php 6 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Output of ./vendor/bin/phpcs tests/input/PropertyTypeHintSpacing.php:

E 1 / 1 (100%)



FILE: tests/input/PropertyTypeHintSpacing.php
--------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 4 LINES
--------------------------------------------------------------------------------------------------
  9 | ERROR | [x] Equals sign not aligned correctly; expected 1 space but found 2 spaces
 10 | ERROR | [x] There must be 1 space after the property type declaration; 2 found
 10 | ERROR | [x] There must be exactly one space between type hint and property.
 11 | ERROR | [x] Scope keyword "public" must be followed by a single space; found 2
 11 | ERROR | [x] There must be exactly one space before type hint.
 12 | ERROR | [x] There must be no whitespace between type hint nullability symbol and type hint.
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------

Time: 95ms; Memory: 8MB

@kukulich
Copy link
Contributor

@carusogabriel The description looks wrong:

no space between the typehint and the property name
no space between the typehint and the property's modifiers

I think there should be one space

@carusogabriel carusogabriel merged commit bfeda8c into master Mar 23, 2020
@carusogabriel carusogabriel deleted the feature/property-type-hints-spacing branch March 23, 2020 12:12
@carusogabriel carusogabriel self-assigned this Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants