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

Namespaces are a valid alternative to prefixing for constants #1056

Closed
grappler opened this issue Jul 25, 2017 · 5 comments
Closed

Namespaces are a valid alternative to prefixing for constants #1056

grappler opened this issue Jul 25, 2017 · 5 comments

Comments

@grappler
Copy link
Member

I have the following code in a plugin:

define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ );

I am getting a warning for this WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound

Namespaces are a valid alternative to prefixing.

Related to #764

@jrfnl jrfnl self-assigned this Jul 25, 2017
@jrfnl jrfnl added this to the 0.14.0 milestone Jul 25, 2017
@jrfnl
Copy link
Member

jrfnl commented Jul 25, 2017

@grappler Good point. I've got a PR ready for this, but will wait to pull this until 0.13.0 has been released.

@GaryJones
Copy link
Member

Related, is this false positive:

add_action( 'after_setup_theme', __NAMESPACE__ . '\\load_textdomain', 5 );
/**
 * Load theme text domain.
 *
 * @since 1.0.0
 */
function load_textdomain() : void {
	\load_child_theme_textdomain( 'my-textdomain', get_stylesheet_directory() . '/languages' );
}

Gives:

94 | ERROR   | Functions declared by a theme/plugin should start with the theme/plugin prefix. Found: "load_textdomain". (WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound)

@jrfnl
Copy link
Member

jrfnl commented Jul 31, 2017

@GaryJones I presume your code sample is missing a namespace MyNamespace; at the top ?

If not, this is not a false positive as without a namespace at the top of the file (or a scoped namespace) __NAMESPACE__ resolves to '', i.e. global namespace.

@GaryJones
Copy link
Member

GaryJones commented Jul 31, 2017

I presume your code sample is missing a namespace MyNamespace; at the top ?

No.... it seems my file didn't have the namespace declared...

Sorry 😊 My issue is not a bug.

@jrfnl
Copy link
Member

jrfnl commented Jul 31, 2017

@GaryJones Happens to the best of us ;-)

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

3 participants