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

Commits on Dec 7, 2022

  1. Core: add sniffs to check formatting for type declarations

    > 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
    jrfnl committed Dec 7, 2022
    Configuration menu
    Copy the full SHA
    cbde80c View commit details
    Browse the repository at this point in the history