Skip to content

Enforce accepted values for the type attribute of the <exclude-pattern> and <include-pattern> tags #727

Open
@rodrigoprimo

Description

@rodrigoprimo

Is your feature request related to a problem?

While reviewing #705 (review), I noticed that in the code documentation, PHPCS specifies that there are two possible values for the type attribute of the <exclude-pattern> and <include-pattern> tags that can be used in a ruleset file: absolute and relative.

/**
* A list of regular expressions used to ignore specific sniffs for files and folders.
*
* Is also used to set global exclude patterns.
* The key is the regular expression and the value is the type
* of ignore pattern (absolute or relative).
*
* @var array<string, array>
*/
public $ignorePatterns = [];

/**
* A list of regular expressions used to include specific sniffs for files and folders.
*
* The key is the sniff code and the value is an array with
* the key being a regular expression and the value is the type
* of ignore pattern (absolute or relative).
*
* @var array<string, array<string, string>>
*/
public $includePatterns = [];

But the code does not validate that one of those values is passed and any value is accepted:

$this->ignorePatterns[$code][(string) $pattern] = (string) $pattern['type'];

$this->includePatterns[$code][(string) $pattern] = (string) $pattern['type'];

Adding the following to a ruleset.xml file, will add a exclude pattern (called ignore pattern in the code) with the type InvalidValue:

<exclude-pattern type="InvalidValue">./vendor/*</exclude-pattern>

Describe the solution you'd like

PHPCS should validate the values passed to the type attribute and warn users if an invalid value is passed.

Additional context (optional)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions