-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Warning for translate triggers class function #719
Comments
The problem in the i18nSniff is that it is not distinguishing between this example of defining a method and a function call for |
If the code was formatted as per WP coding standards, instead of all on one line, would the supposed (but incorrect) lack of i18n be flagged still? |
@westonruter FYI: I'm working on a number of utility functions which I hope to introduce into WPCS soonish, one of these will be to determine if a |
The function doesn't actually look like that anywhere in the codebase, just gave a simply one-liner as an example The actual function in the abstract is:
|
Right - so does the same error still happen when it's formatted correctly? I just want to ascertain that the issues is the naming of your method that is causing the issue, rather than the way the code is formatted. |
@GaryJones -- is the above function formatted incorrectly? |
public function translate( $key ) {
return '';
} is correctly formatted, yes. |
<?php
class Foo {
public function translate( $key ) {
return '';
}
} Yields:
This warning and error are bugs. |
I have a class function in my plugin:
abstract class myclass { public function translate( $key ) {} }
This function doesn't do anything by default, but allows extending classes to pull a database value by $key and translate it. The extending classes ultimately run through some WP core i18n function like
__()
During PHPCS runs this function triggers the i18nSniff error: The $text arg should be single a string literal, not "$key".
I see that some sniffs -- the "DontExtract" for example -- seem to allow this pattern, but this translate function doesn't follow the pattern
I tried to figure out how to rewrite the tests to allow for this exception to submit a PR but after some digging and attempts I decided I am not qualified to do so. Sorry...
Thanks,
The text was updated successfully, but these errors were encountered: