PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
906 stars 55 forks source link

Explicitly passing paths/files to command should still honour the configured exclusions #498

Closed claudiu-cristea closed 3 months ago

claudiu-cristea commented 4 months ago

Describe the bug

phpcs.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="foo">
  <arg name="extensions" value="inc,php"/>
  <file>/var/www/html/</file>
  <exclude-pattern>/var/www/html/excluded.php</exclude-pattern>
</ruleset>

When I run

phpcs /var/www/html/excluded.php

The file shouldn't be checked because is has been excluded in phpcs.xml, which is used to run the command.

Here's a use case: I'm detecting all changed files when pushing to a Git remote repository because I want to run PHPCS on Git pre-push hook. The set of files may contain files that are excluded phpcs.xml. I'm expecting that, even I'm passing them to phpcs, as arguments, phpcs.xml is honoured.

Code sample

See "Describe the bug" section

Custom ruleset

See "Describe the bug" section

To reproduce

See "Describe the bug" section

Expected behavior

Even paths or files are passed as arguments to the command line, I'm expecting that file/path exclusions, configured in phpcs.xml are respected.

Versions (please complete the following information)

Operating System Linux
PHP version 8.3
PHP_CodeSniffer version 3.9.2
Standard custom
Install type Composer

Additional context

None.

Please confirm

jrfnl commented 4 months ago

@claudiu-cristea Thanks for reporting this, but I don't think this is a bug in PHPCS. Rather, I think this is a problem with the paths not matching.

And yes, I've tested and could not reproduce the issue with the scenarios I ran.

To help you figure this out, I need more information though.

jrfnl commented 3 months ago

Closing for lack of feedback. The issue can be reopened if the OP responds.