Walk up directory tree to find php-cs-fixer config#227
Closed
benmatselby wants to merge 1 commit intomainfrom
Closed
Walk up directory tree to find php-cs-fixer config#227benmatselby wants to merge 1 commit intomainfrom
benmatselby wants to merge 1 commit intomainfrom
Conversation
Instead of using the target file's directory as the working directory, walk up the directory tree to find a php-cs-fixer config file (.php-cs-fixer.php, .php-cs-fixer.dist.php, .php_cs, .php_cs.dist). This ensures php-cs-fixer picks up project-level configuration even when editing files in nested subdirectories.
Owner
Author
|
Might come back to this at a later date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #226
Summary
The Fixer command previously set its working directory to the target file's immediate parent directory. This meant php-cs-fixer could miss project-level config files (e.g.
.php-cs-fixer.php) when editing files in nested subdirectories. This PR adds afind_config_dirmethod that walks up the directory tree from the target file looking for a recognised php-cs-fixer config file, and uses that directory as the working directory. If no config file is found, it falls back to the previous behaviour.Changes
phpcs.py: AddedCONFIG_FILESclass constant listing the four config file names php-cs-fixer recognises (.php-cs-fixer.php,.php-cs-fixer.dist.php,.php_cs,.php_cs.dist)phpcs.py: AddedFixer.find_config_dir()method that walks up from a starting directory to the filesystem root, checking for any of the config files at each levelphpcs.py: UpdatedFixer.execute()to usefind_config_dir()to determine the working directory instead of always using the target file's parent directorytests/test_phpcs.py: Updated existingtest_fixer_sets_working_dirtest to mockos.path.isfile(renamed totest_fixer_sets_working_dir_to_file_dir_when_no_config)tests/test_phpcs.py: Addedtest_fixer_sets_working_dir_to_config_dirintegration-style testtests/test_phpcs.py: AddedTestFixerFindConfigDirtest class with 6 tests covering: no config found, config in start dir, config in parent dir, dist config, legacy config, and priority ordering