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
Allow passing multiple filenames without a configuration #4279
Comments
Sorry to pile on, but I'm a recent adopter and very surprised to see this limitation. While I can understand there is some confusion which config file to use (based on previous threads), there should be a way to still pass multiple paths, especially when passed Example usage:
|
Since we do not try to find a config file when Therefore I think we can add support for that use-case, for example: So the restriction changes from;
To:
like to hear other opinions on this case as well :) |
@jdufresne, use this: @jasonmccreary , passing
@SpacePossum , oh we do |
@jdufresne , you can use slightly modified version of what we suggest to use on CI: |
IIUC, both of the suggestions are passing a |
the thing is to distinguish do we have no config and we are fine with it or we do have a config but we want to ignore it. |
I don't think it's related to "having no config". Maybe what should be done as does other tools is to have an option Especially as when giving only one path, the error messages doesn't popup, so it's kinda inconsistent... (sorry for upping this subject, just hit my head on that problem) |
The ci code suggested by @keradus does not solve the issue. The following command always detects one file.
|
Why can't we just have nice things? This concept is very straightforward, and yet it's almost 2 years later and it's still not built in. |
I find this claim not accurate.
example execution - take a look at two dots (
|
@crazytonyi , as already described in this and some other threads, it's tricky to autodetect the configuration if we don't know which is the main dir of the project, and it could be that one run the tool to fix multiple projects in a single line, which, in the current state, PHP CS Fixer does not handle. imagine:
Which configuration should be taken to apply fixing? how can we be sure that all files are part of the same project, and not different ones (with different configuration) ? The current way, as the easiest approach, is to ask the user explicitly for the configuration file. But hey, your question is very right ! 2 years and such a feature was not yet implemented? How can that be! The answer is simple, actually - welcome into the open-source. EVERYONE can contribute! And maintainers, well - while investing their free time, which is limited, they are focusing on topics with high demand (eg PHP8) rather than request raised by few individuals without the bigger amount of community asking for it, especially if an alternative solution is available. With that, as I don't see this feature request be picked up anytime soon, I am closing this request. |
I guess I don't understand the role of the config file or how php_cs_fixer is project oriented. If I pass in one file and a list of rules, it formats it and says it used the default config. Why would I expect it not to have the same functionality for multiple files? If I pass it 5 files, I'm effectively saying "hey, imagine I just did this 5 times, and do that". I don't usually work out of an ide (one of the reasons I want php_cs_fixer, since I'm not in an environment that auto formats) so there's no potential for multiple projects with different configs. Perhaps this tool could detect that? Or have a switch to tell it to use the default config (or a "non-project-mode" switch)? Or it could prompt with something about how since no config was set, it will use the one it would use for the first file in the list. |
You know that by heart, but the tool has no such knowledge. and somehow, that knowledge has to be provided to the tool, otherwise there is risk that files will be converted using different rules than intended (case with multi-projects). Strong recommendation: avoid the frustration that nobody provided the feature you are looking for and think how you can encourage ppl to provide it, or maybe even provide it yourself? We need a decent PR followed by a decent review. If the feature has nobody willing to implement it, or maybe there is one alone soul willing to raise a PR, yet nobody willing to review it within the community, then, well, unfortunately - it's not realistic to expect from limited maintainers group to fulfil all requests. |
@keradus, in fairness, I did submit a PR years ago (#4411). After some back and forth it was closed as you did not provide any actionable feedback. I still have a use case for being able to use php-cs-fixer fix --rules=no_unused_imports -- app database I'd be willing to offer a bounty if it helps. |
Same here, I always run 3 times the php-cs-fixer binary to fix 3 folders:
it's very annoying. |
2022 Still doesn't work with multiple changed files .. |
why not create a config file that specifies those 3 directories?
It does, but it requires some work, you would have to make a config file that specifies those changed files (dynamically typically), this can be done through returning a Finder object. |
@SpacePossum, yes, I can create a config, also we can remove all available parameters and use only a config file. The idea is if we allow the path as parameter and we can set the multiple paths in the config file, why not add the multipath feature also as parameter? |
There are 2 challanges for doing so, about which config file to use. Please raise the suggestion how to overcome those, and if it's agreed to go that path by community, please raise the PR. |
When multiple paths are passed, PHP CS Fixer requires the `--config` parameter. PHP-CS-Fixer/PHP-CS-Fixer#4279
When multiple paths are passed, PHP CS Fixer requires the `--config` parameter. PHP-CS-Fixer/PHP-CS-Fixer#4279
When reporting an issue (bug) please provide the following information:
The PHP version you are using (
$ php -v
):PHP CS Fixer version you are using (
$ php-cs-fixer -V
):The command you use to run PHP CS Fixer:
The configuration file you are using, if any:
None!
I've read through the rationale as to why this occurs here:
I'm asking if the project can reconsider this decision and allow multiple paths without a configuration file. Typically, POSIX CLI tools are built to allow an arbitrary number of paths. If you take a look at other static analysis and code formatting tools, you'll see this is very common. Standard POSIX tools like
xargs
are built with this in mind.My project chooses not to use a PHP-CS-Fixer configuration file. The goal is to have minimal fuss w/r/t code formatting and instead accept community defaults. As a result, I get the above error when using php-cs-fixer with multiple files.
This became a particular pain point when integrating with pre-commit. pre-commit is built to pass all changed files to a tool in a single command. Requests to allow a "one at a time feature" have been rejected with the response "the best way to improve the community is to improve the specific linter to take filenames in a more standard way." So here I am.
As a user, I'm stuck between these two tools. My team's workaround has been to configure pre-commit to run php-cs-fixer against the entire source directory on every change. But it would be nice to apply it to just the changed files instead (like other tools).
The text was updated successfully, but these errors were encountered: