Skip to content

PrefixAllGlobals not reporting for file autoloaded in composer.json #1632

@mundschenk-at

Description

@mundschenk-at

Bug Description

I've got a legacy function named avapr_get_avatar_checkbox in one of my include files. When I enabled the WordPress.NamingConventions.PrefixAllGlobals sniff, I expected this function to be flagged. (Other "incorrect" function names are!)

Minimal Code Snippet

<?php
/**
 *  Foobar.
 *
 *  @package Foo
 */

/**
 * Foobar.
 */
function avapr_get_avatar_checkbox() {
}

/**
 * Something else.
 */
function another_function() {
}

Minimal phpcs.xml:

<?xml version="1.0"?>
<ruleset name="Foobar">
	<config name="minimum_supported_wp_version" value="4.9"/>

	<rule ref="WordPress"/>

	<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
		<properties>
			<property name="prefixes" type="array">
				<element value="foobar"/>
			</property>
		</properties>
	</rule>
</ruleset>

I'd expect both function names to be flagged, but only the later one is.

Error Code

--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 17 | ERROR | Functions declared by a theme/plugin should start with the
    |       | theme/plugin prefix. Found: "another_function".
    |       | (WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound)
--------------------------------------------------------------------------------

Environment

Question Answer
PHP version 7.3.1
PHP_CodeSniffer version 3.4.0
WPCS version 2.0.0
WPCS install type Composer project local

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions