-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix fix
command to handle --fixers
option when contains extra and excluding fixers
#599
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
Conversation
$this->config = $config; | ||
} | ||
|
||
public function resolve($levelOption, $fixersOption) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really, create extra class and do everything in one, the only one method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create extra class is because to get testability and separate responsibilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! but why only one magic method to do all things?
Maybe this is good plase to separate Config::$fixers into two values? |
$addNames = []; | ||
$removeNames = []; | ||
foreach ($names as $name) { | ||
if (strpos($name, '-') === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use Symfony standards here: 0 === $sth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
Idea itself looks nice! |
--filter? where? |
|
||
// remove/add fixers based on the fixers option | ||
$names = array_map('trim', explode(',', $fixersOption)); | ||
$addNames = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crash on php5.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on PHP 5.3, not on 5.2 (the whole library crashes on 5.2 because it uses namespaces)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, @fivestar point it out 9 days ago and I already sorry for my typo ;)
fix
command to handle --filter
option when contains extra and excluding filtersfix
command to handle --fixers
option when contains extra and excluding filters
Thanks for your comments! I replied some line notes.
|
If you will keep this PR with only one commit then please, do it. If PR will has several then I will do it during merge.
Yeah, 5.3, sorry ;)
No problems on that, just now we have one variable with dual responsibility. You are dealing with them now so it will be cool to fix it as well ;) Just create Config::$level for level value and change Config::$fixers to handle only fixers array |
fix
command to handle --fixers
option when contains extra and excluding filtersfix
command to handle --fixers
option when contains extra and excluding fixers
Please rebase on master ;) |
any news @fivestar ? The work you have already done is cool! |
Sorry, I've been so busy lately... Please wait for a little while longer! |
343be2f
to
45a1c1f
Compare
@keradus Please check it! |
} | ||
} | ||
$fixers = $fixersResolver->resolveByLevel($levelOption); | ||
$fixers = $fixersResolver->resolveByNames($fixers, $fixersOption); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we have here sth like:
$fixersResolver = new FixersResolver($this->fixer->getFixers());
$fixers = $fixersResolver->resolveByLevel($levelOption);
$fixers = $fixersResolver->resolveByNames($fixers, $fixersOption);
So we passing $fixersOption
, $levelOption
, $fixers
and $fixersOption, where
$levelOptionis calculated here from
$config->getFixers();or input itself. We also calculate sth from
FixersResolverand passing it to
FixerResolver` again - just use a state.
It would be great if you have some setters to set $level
and $fixers
from input/config, then resolveBy*
would be a private methods and at finish FixersResolver
will have some public method like getFixers
/resolve
(which do all the magic like parsing inputs and calling private helpers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already done.
Nice progress @fivestar ;) |
It would be great to see that on master! Waiting for progress ;) |
I test this branch a lot, results are below.
Result: Take level from config.
Result:
Result: Take level from option.
Result: Take level from option and apply fixers from options as patch.
Result:
Result: Take level from option and ignore level from config. Then apply fixers from config as patch. When sb run |
@fabpot @fivestar @stof @sstok @GrahamCampbell BTW, tests and solution for that behavior are availeble here: fivestar#2 |
Thanks!! I misread your specified commit number so I'll squash after merging your PR ;) |
I've seen test results and your PR, so I think your strategy is better because it's is useful for actual use case. |
I am not PR-ing with code I don't want to be merged ;) If you agreed with changes just accept that PR (fivestar#2). I don't change the whole strategy - just fix 2 cases. The other thing is if this PR (#599) will be merged - and I will be glad to see more opinions here. |
bc4c879
to
97a8abf
Compare
Ok I merged your PR. (What is |
Uh oh I thought you are judged. I'll remove commits later. Please resend PR. |
Why to remove? The new commits are good - they improve this PR (#599).
Yes, I can perform a merge. But since this PR change tool interface and break BC it is worthly to give community a time to give a feedback with opinion :) |
👍 |
|
||
In combination with these config and command line options, you can choose various usage. | ||
|
||
For example, default level is ``symfony``, but if you also don't want to use ``psr0`` fixer, you can specify ``--fixers="-psr0"`` option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if you also don't want to use the psr0 fixer.
you can specify the --fixers="-psr0"
option.
And try to wrap lines a bit ;) approx 80 chars max
👍 for this feature. |
97a8abf
to
23c07bb
Compare
I've just got it! I squashed some commits. @sstok Thanks for your help! I fixed some messages. |
👍 great job ! |
Thank you @fivestar. |
…ins extra and excluding fixers (fivestar, keradus) This PR was merged into the 1.0.x-dev branch. Discussion ---------- Fix `fix` command to handle `--fixers` option when contains extra and excluding fixers Currently, when `--fixers` option contains extra and excluding mixed filters such as `-eol_ending,concat_with_spaces`, excluding filter will be enabled, however, extra filter will not be enabled. This PR fixes this behavior, so enable both type filters when mixed filters given. ---- `sample.php` ```php <?php echo 'foo'.'bar', PHP_EOL; ``` Current version: (`concat_with_spaces` is not enabled) ``` % php-cs-fixer fix -v --diff --fixers="-eol_ending,concat_with_spaces" --dry-run sample.php 1) /home/fivestar/sample.php (eof_ending) ---------- begin diff ---------- --- Original +++ New @@ @@ <?php echo 'foo'.'bar', PHP_EOL; - ---------- end diff ---------- ``` Fixed version: (`concat_with_spaces` is enabled) ``` % php-cs-fixer fix -v --diff --fixers="-eol_ending,concat_with_spaces" --dry-run sample.php 1) /home/fivestar/sample.php (eof_ending, concat_with_spaces) ---------- begin diff ---------- --- Original +++ New @@ @@ <?php -echo 'foo'.'bar', PHP_EOL; - +echo 'foo' . 'bar', PHP_EOL; ---------- end diff ---------- ``` Commits ------- 23c07bb FixersResolver - make class more state aware and enhance it's tests e75c985 Fix README and some codes. 6876726 FixersResolver - simplify code f3c966f Fix `fix` command to handle `--fixers` option when contains include and excluding fixers
Thank you too!! |
Currently, when
--fixers
option contains extra and excluding mixed filters such as-eol_ending,concat_with_spaces
, excluding filter will be enabled, however, extra filter will not be enabled.This PR fixes this behavior, so enable both type filters when mixed filters given.
sample.php
Current version: (
concat_with_spaces
is not enabled)Fixed version: (
concat_with_spaces
is enabled)