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

Core: add sniffs to check formatting for type declarations #2132

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 7, 2022

  1. Type declarations must have exactly one space before and after the type.
    In case of a multi-line function declaration, a new line + appropriate indentation should be used before the type declaration.
  2. The nullability operator is regarded as part of the type declaration and there should be no space between this operator and the actual type.
  3. Keyword-based type declarations should use lowercase.
  4. Class/interface name based type declarations should use the case of the class/interface name as declared.

And specifically for return type declarations:
5. There should be no space between the closing parenthesis of the function declaration and the colon starting a return type.

These rules apply to all structures allowing for type declarations: functions, closures, catch conditions as well as the PHP 7.4 arrow functions and typed properties.

Refs:

Refs regarding return type spacing:

Closes #547

> 1. Type declarations must have exactly one space before and after the type.
>    In case of a multi-line function declaration, a new line + appropriate indentation should be used before the type declaration.
> 2. The nullability operator is regarded as part of the type declaration and there should be no space between this operator and the actual type.
> 3. Keyword-based type declarations should use lowercase.
> 4. Class/interface name based type declarations should use the case of the class/interface name as declared.
>
> And specifically for return type declarations:
> 5. There should be no space between the closing parenthesis of the function declaration and the colon starting a return type.
>
> These rules apply to all structures allowing for type declarations: functions, closures, catch conditions as well as the PHP 7.4 arrow functions and typed properties.

Refs:
* https://make.wordpress.org/core/2020/03/20/updating-the-coding-standards-for-modern-php/ - Type declarations
* https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#type-declarations
* WordPress/wpcs-docs 102
* WordPress/wpcs-docs 119

Refs regarding return type spacing:
* WordPress/WordPress-Coding-Standards 547
* WordPress/WordPress-Coding-Standards 1084
* WordPress/WordPress-Coding-Standards 1420
* WordPress/WordPress-Coding-Standards 1421

Closes 547
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.

@dingo-d dingo-d merged commit bf4fccd into develop Dec 8, 2022
@dingo-d dingo-d deleted the feature/core-add-type-declaration-formatting-rules branch December 8, 2022 07:57
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.

Spacing for Return Types
3 participants