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

Interest in a namespace declaration sniff to check scoped/no name usage ? #2324

Closed
jrfnl opened this issue Dec 20, 2018 · 2 comments
Closed

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Dec 20, 2018

Is there interest in a namespace declaration sniff which would check for things like:

  • Scoped namespaces and forbid their use.
  • Namespace declarations without a namespace name (= global namespace), i.e namespace;, and forbid their use.
  • Multiple (scoped) namespaces in a file and forbid this.

I wrote a sniff for this for an in-company standard already and if there is interest, they're happy to let me pull it here.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 19, 2019

First, what is a "scoped namespace?" I cannot find this verbiage in the PHP docs.

Namespace declarations with curly brackets - in PHPCS - create scope conditions for the code contained between them. That's what the term is about.

As for multiple namespaces in the same file, I am going to argue against adding a filter for it. Let me explain:

Sorry, but your arguments are irrelevant to this issue.

  1. This issue is not about whether you should use the sniff, only about whether there is interest in such a sniff.
  2. The sniff would go into Generic and would not be added to any of the PHPCS native standards, so by default, it wouldn't be used, unless you specifically choose to turn it on.

In other words, once it would be added to PHPCS, it would be possible for people to choose to add it to their standard, but if you don't like, it's simple: just don't add it.

@jrfnl
Copy link
Contributor Author

jrfnl commented Sep 16, 2020

I'm going to close this issue. While these sniffs ended up not being pulled to PHPCS itself, they did get written and are now publicly available via the PHPCSExtra package (Packagist/Composer: phpcsstandards/phpcsextra).

The sniffs are called:

  • Universal.Namespaces.DisallowDeclarationWithoutName
  • Universal.Namespaces.DisallowCurlyBraceSyntax
  • Universal.Namespaces.EnforceCurlyBraceSyntax
  • Universal.Namespaces.OneDeclarationPerFile

@jrfnl jrfnl closed this as completed Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants