I am trying to apply only a rule, without create a .php_cs config file, for example:
$ php vendor/friendsofphp/php-cs-fixer/php-cs-fixer --rules=array_syntax mysrc
But that will take the default value for array_syntax value (which is syntax => long).
I would like use params via command line, something like:
$ php vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --rules=array_syntax[syntax=>short] mysrc
That should convert all the arrays with syntax short (that is array() to [] ) which is more syntax sugar and clean for improve readability. But this obviously doesn't work and it doesn't take the "syntax" param as supported.
Alternative ways (using quoted parameters) could be this one:
$ php vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --rules=array_syntax['syntax' => 'short'] mysrc
In fact this produces a weird exception (probably a bug) assuming that is a path:
[PhpCsFixer\ConfigurationException\InvalidConfigurationException]
The path "=" is not readable.
But this is mostly a regresion, because in previous versions the documentation says that you can use short_array_syntax that was "deprecated" as you can read in UPGRADE file, but it is only possible to use the values via config file and don't via parameters in command line?
expected behaviour is not possible.
using config file is advised
@keradus and it would be possible to implement in future as feature request? It should be only a matter of how to parse params via command line
Could be done, however some config is pretty complex. Passing such config by the commandline might not be easy as well, so I wonder how you would like to approach that :)
The only way I could approve would be to pass a JSON string as a value.
--rules="{...}"
like;
--rules=@PSR2,class_keyword_remove,concat_space{"spacing": "none"},dir_constant
?
--rules='{"@PSR2": true, "class_keyword_remove": true, "concat_space": {"spacing": "none"}, "dir_constant": true}'
@keradus @SpacePossum JSON format values seems a perfect valid option to me, it would be perfect!
Hi, is this feature implemented ?
@ptcong no as far I know, it would be a great change to me if it gets implemented
feel free to collaborate ;)
JSON seems like complete overkill and is only practical for tools. The command-line should remain usable by humans. My counter-proposal would be to adopt a form similar to Rake, e.g.
--rules=array_syntax[syntax=short]
There is no reason to bloat the syntax with JSON-specific grammar: the only thing JSON provides that a simple syntax does not is a distinction between types. That distinction is not important because a fixer should cast its parameters to the expected type, assuming the user will always specify them as a string, since that's what the command line is.
Thanks @keradus works perfectly as:
php vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --rules='{"array_syntax": {"syntax": "short"}}' mypath
Too bad it's impractical to actually type JSON into the command line.
@Bilge if you don't like, make a PR for style as
--rules='blah,blah[key=value]'
@keradus i just have an idea that make easier to use rule param in cli. For example:
--rules='array_syntax.syntax=long,another.key1=value1,another.key2=value2'
It seems better than JSON, is it good ?
More possible syntaxes, more possible issues and misunderstanding how to provide CLI argument and more code doing the same to maintain.
Nice thing about reusing the format from file is... that we exactly reuse the code for parsing it. So we are sure that it will always work the same way.
If one don't wanna use predefined set but his own custom group of rules with some custom configuration I stronly advise to use config file.
The configuration file approach is the real maintenance burden and not without its own issues.
I think you don't understand the config file
Most helpful comment
--rules='{"@PSR2": true, "class_keyword_remove": true, "concat_space": {"spacing": "none"}, "dir_constant": true}'