Closed MickeyKay closed 7 years ago
Yes, this feature exists. You can set config options and CLI arguments inside a ruleset/phpcs.xml file.
Some examples are here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
The phpcs.xml.dist file in the 3.0 branch (the standard PHPCS itself uses) also has some examples, including settings colours and default files to check (allowing you to just run phpcs
inside the root dir): https://github.com/squizlabs/PHP_CodeSniffer/blob/3.0/phpcs.xml.dist
The line you are probably after is: <arg name="colors" />
Let me know if you need any help.
Forgot to mention that as show_colors is both a config option and a CLI arg, it is better to specify the CLI arg (using the arg
tag) in the ruleset. But if you want to, you can also use the config
tag and it should do the same thing.
@gsherwood I tried this, and the arg
method works, however when I add the following to my phpcs.xml file, it has no effect:
<config name="colors" value="true" />
What am I missing?
What am I missing?
Sorry, I gave you the wrong info. You can't set config values to override CLI arguments. You only set those config values for sniff configs. The <arg>
tag is the way to go.
So, there's no way, for example, to update the installed_paths
in my ruleset.xml with something like the following?
<arg name="standard" value="vendor/wp-coding-standards/wpcs" />
Installed paths isn't something you set on the CLI, so you'd use:
<config name="installed_paths" value="/path/to/standard,/path/to/otherstandard" />
You're not overriding CLI values with that, so the value will be set and used during execution.
But that's also something you should typically set in your actual PHPCS config file, and not in a ruleset. Inside a ruleset, you would typically reference sniffs using relative paths. But it all depends on how much control you have over the standards you are importing.
Ahhh, fantastic. Thanks!
For anyone else who got here by looking for a way to enable colors in PHPCS; you can enable them using the --colors
option via the CLI
Installed paths isn't something you set on the CLI, so you'd use:
<config name="installed_paths" value="/path/to/standard,/path/to/otherstandard" />
You're not overriding CLI values with that, so the value will be set and used during execution.
But that's also something you should typically set in your actual PHPCS config file, and not in a ruleset. Inside a ruleset, you would typically reference sniffs using relative paths. But it all depends on how much control you have over the standards you are importing.
What if your path is relative not absolute? Where is it relative from?
What if your path is relative not absolute? Where is it relative from?
@Pi-George The ruleset.
Hi there,
First of all, fantastic project - I love it! Feature request (or perhaps it exists already and I just can't figure it out). . .
I would love to be able to specify config options like
show_colors
inside our phpcs.xml/ruleset.xml files, or elsewhere if that makes more sense. Reason being is that I'd like to be able to package up and share our rulesets within our org, however requiring config options to be specified via the command line at runtime feels like an unnecessary step. Is there currently a way to save these config options as actual config?Thanks!