Open top-master opened 5 years ago
I believe this is the same issue as is being described in the JetBrains issue tracker (for PhpStorm): https://youtrack.jetbrains.com/issue/WI-36028
My use case is that I have a project (a WordPress site) which contains multiple subprojects (WordPress themes and plugins), each of which may have their own configurations for PHPCS, ESLint, etc. When editing a JS file in a subproject, the IDEA lints the file according to the nearest ESLint config in that file's directory tree. In order to get the same behavior with PHPCS, as noted by @MaXal:
So to support this properly we have to change the working directory for each file but that, in turn, will break a lot of configurations since they depend on the working directory being the project root so I suggest filing the feature request to PHPCS to add an option or change the default behavior inline with JSHint (it looks more than reasonable to me).
Just want to leave a note here that the workflow as described above presumes a Composer based project, while PHPCS is not limited to Composer supported projects.
In #3378 I took the approach of pushing the logic for finding the actual configs into the filter, so that people who want to try out things like looking for a composer.json can do that. I took a different approach in my own filter's implementation.
Taking just one rule-set XML file from the command line (or something) is really not enough to cover our entire project, its unit test dir specific rules, its sub-module related rules, and so on; all this in a single XML file can get quite complex.
For example, when
git add .
command is executed it handles current and all sub-directories and:.gitignore
files in each directory (starting from the nearest root directory which contains the.git
directory until currently being handled directory)..gitignore
exists its rules get added to the rule-stack, and once that directory is finished those rules are removed again from the rule-stack (it is using "Last In, First Out" queue or something).I would like
PHPCS
to handle the.phpcs.xml
files in a similar way, I mean:PHPCS
should find its root directory by searching in current and parent directories for the nearestcomposer.json
file, which's rule-set is not set to "<use-parent>
" (The<use-parent>
rule-set should be a reserved keyword to allow sub-modules to reuse the settings from a parent directory, which might be the main project).PHPCS
should get its initial rule-set from thatcomposer.json
file (and ignore.phpcs.xml
files of any parent directories).git
does for.gitignore
files,PHPCS
should search for.phpcs.xml
files in each directory (starting from the root directory, until currently being handled directory)..phpcs.xml
exists its rules should get added to the rule-stack, and once that directory is finished those rules should get removed from the rule-stack again.phpcs .
orphpcbf .
command (for backward compatibility, when nocomposer.json
file in current-path contains the initial rule-set,PHPCS
should just do as it does currently).