WordPress / WordPress/WordPress-Coding-Standards
PrefixAllGlobalsSniff: always flag blocked prefixes
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem?
This is related https://github.com/WordPress/plugin-check/issues/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:
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 about wp as disallowed and remove it from the list. After that, all functions are checked for the myplugin 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)
- I intend to create a pull request to implement this feature.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php, especially the hardcoded blocked-prefix list around lines 78–91, and review the behavior described in issue #523. Confirm that with no configured prefixes, a function such as wp_awesomefunc() is reported for its blocked prefix, while configured valid prefixes continue to work as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100