Skip to content

Handbook: require one blank line before and after a namespace declaration #2305

Open
@jrfnl

Description

@jrfnl

Is your feature request related to a problem?

A sniff should be added to address the following handbook rule:

Namespace declarations should have exactly one blank line before the declaration and at least one blank line after.

Ref: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#namespace-declarations

Additional context (optional)

From an analysis done of available sniffs:

The "Namespace declarations should have exactly one blank line before the declaration and at least one blank line after" will probably also need a new sniff.
My research shows the following:

  • The PSR2.Namespaces.NamespaceDeclaration sniff, which is included in Extra can sort of cover the "after" part, as in: it check for exactly one blank line after, which is close to, but not exactly what we want.
  • The PSR12.Files.FileHeader sniff can check both "before" and "after", but will also, again, check for exactly one blank line.
    The problem with that sniff is that it currently is "all or nothing", it does not have modular error codes, so we cannot ignore some other things from that sniff (requires blank line between PHP open tag and file docblock), which makes it problematic to include the sniff.
    If upstream PR PSR12/FileHeader: make "SpacingAfter" and "SpacingInside" errorcodes modular squizlabs/PHP_CodeSniffer#2729 would (finally) be merged, we could reconsider adding that sniff though.

Ref: #2247

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions