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

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

Open
1 of 2 tasks
rodrigoprimo opened this issue Nov 25, 2024 · 0 comments

Comments

@rodrigoprimo
Copy link
Contributor

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)

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

2 participants