Core: add section about namespace declaration rules with select new sniffs #2247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refs:
Universal.Namespaces.DisallowCurlyBraceSyntax
sniff PHPCSStandards/PHPCSExtra#4Universal.Namespaces.OneDeclarationPerFile
sniff PHPCSStandards/PHPCSExtra#6Universal.Namespaces.DisallowDeclarationWithoutName
sniff PHPCSStandards/PHPCSExtra#50Notes:
An issue will need to be opened about this in WPCS. The corresponding issue in PHPCSExtra is Sniff to enforce naming conventions for namespace names PHPCSStandards/PHPCSExtra#231
My research shows the following:
PSR2.Namespaces.NamespaceDeclaration
sniff, which is included inExtra
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.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.
With the "only one namespace declaration per file" rule being enforced, placing the namespace declaration anywhere else than at the top of the file would be a parse error.
Other notes:
Generic.PHP.LowerCaseKeyword
sniff.Generic.WhiteSpace.LanguageConstructSpacing
sniff, which was moved toCore
in Core: move rules related to include/require statements fromExtra
toCore
#2097.Closes #1763