-
-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Is your feature request related to a problem?
I would like PHPCS to do nothing if the provided file is not explicitly included through the phpcs.xml(.dist).
Given we have /home/developer/project set up as follows:
src/
-- included/
---- test.php
-- ignored/
---- test.php
vendor/
composer.json
phpcs.xml
...
And a phpcs.xml as such:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<rule ref="PSR12"/>
<file>src/included</file>
</ruleset>And you run the phpcs command on a non-included file, it still outputs errors.
./vendor/bin/phpcs /home/developer/project/ignored/test.php -q -s
So I would like to add a flag to silence phpcs if the provided file is not in phpcs.xml.
Context: neovim users can use phpcs as a "language server" through none-ls (formerly known as null-ls) (somewhat related to #640 I suppose, neovim superiority 😆). We can add custom arguments, and it essentially just runs phpcs on the current open file.
spawning command "./vendor/bin/phpcs" at /home/developer/project with args { "--report=json", "-q", "-s", "--runtime-set", "ignore_warnings_on_exit", "1", "--runtime-set", "ignore_errors_on_exit", "1", "--stdin-path=/home/developer/project/src/ignored/test.php", "--basepath=", "-q", "--report=emacs", "-" }
Then it parses the output, and adds in-line errors/warnings/...
Currently it's also doing this for files that aren't even in the project, like in vendor, in ignored directories,... which is really annoying. I don't care if a vendor uses a different codestyle from me..
Describe the solution you'd like
When a phpcs.xml is detected, and it has file entries, and the file provided through stdin is not in one of the file entries, just return nothing.
I understand this might break backwards compatibility, for that reason, perhaps this behavior could be added behind a new flag? (we have the ability to customize the input args in none-ls, so we can easily add an extra flag)
Additional context (optional)
- I have read the Contribution Guidelines and this is not a support question.
- I intend to create a pull request to implement this feature. (provided I get some pointers where to look)