-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
PrefixAllGlobalsSniff: always flag blocked prefixes #2480
Comments
That's a good one @swissspidy ! |
I'm not keen on this suggestion for the following reasons:
All in all, I don't think the proposed change is acceptable. It could be considered to have a separate sniff which only checks global function declaration names against a banned prefix list, though I'm not fully convinced of the usefulness of such a sniff as what we want is that devs use a consistent prefix, while selectively flagging unwanted prefixes would undermine that advise. As an alternative, what about if the |
Thanks, I appreciate the quick feedback!
From a WPCS point of view that definitely makes sense. For the plugins team it's different though, at least that's my understanding as an outsider. So I think we'll have to create such a new sniff for Plugin Check to accommodate our needs.
This would help people getting started with WPCS, as they might otherwise never realize that the sniff is silently not running. So that makes sense to me 👍 |
I'm not so sure it is different. After all, unless you require a consistent - and preferably unique - prefix(es) in all plugins/themes, that "ban" list would just keep expanding until it is a dictionary. That's something for the plugin team to discuss further though and outside the scope of WPCS.
Let's give other people some time to pitch in to see if anyone has a good reason why this shouldn't be done. If there are no objections, this is a change for which a PR would be welcome. Notes for anyone who wants to work on this:
|
Is your feature request related to a problem?
This is related WordPress/plugin-check#523. In the Plugin Check plugin we need to find a way to flag the lack of prefixes for global functions.
Describe the solution you'd like
PrefixAllGlobalsSniff
has a hardcoded blocklist of disallowed prefixes:WordPress-Coding-Standards/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php
Lines 78 to 91 in 7f76630
However, this blocklist is only used to compare it against the user-provided prefixes list.
So if I provide
myplugin,wp
as valid prefixes, the sniff will warn aboutwp
as disallowed and remove it from the list. After that, all functions are checked for themyplugin
prefix.Now, when I don't pass any custom prefixes, the sniff doesn't do anything, as it doesn't know what valid prefix to look for.
However, since we already know that
wp
is not allowed, the sniff could always check for that regardless.So I am proposing that, if no list of valid prefixes is passed, the sniff should always at least flag the blocked ones.
In other words, if I don't pass any configuration
wp_awesomefunc()
would get reported as having a disallowed prefix.Additional context (optional)
The text was updated successfully, but these errors were encountered: