Add condition for fully-qualified global functions #4
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.
The current implementation doesn't cover the case of a WordPress i18n global function written with a leading backslash (e.g.
\__()
) because the PHP parser does not identify\__()
as aT_STRING
but rather as aT_NAME_FULLY_QUALIFIED
.The proposed change takes that case into account by adding a new condition that is satisfied when the current
token
isT_NAME_FULLY_QUALIFIED
and its text, starting from the second character (i.e.text.slice(1)
), is one of the i18n functions.This case is necessary when a WordPress component uses external libraries that are automatically namespaced by a processor such as PHP Scoper, which transforms the name of every global function into a fully-qualified name (e.g.
esc_html__()
becomes\esc_html__()
).