Php_codesniffer: Is it possible to set configurations (phpcs --config-set) also in phpcs.xml

Created on 21 Aug 2018  路  2Comments  路  Source: squizlabs/PHP_CodeSniffer

The Wiki on GitHub suggests that I can make phpcs not account for warnings in the process' exit code. This is suggested with

$ phpcs --config-set ignore_warnings_on_exit 1

However, this makes a change in myproject/vendor/squizlabs/php_codesniffer/CodeSniffer.conf. This file is not under source control and will not be shared by the team, and (if I understand correctly) the preferred way to write configurations is phpcs.xml.

Is it possible to make this and similar other configurations in phpcs.xml? If so, apologies if I missed to see where in the docs this has been written down.

This discussion is indirectly related to https://github.com/squizlabs/PHP_CodeSniffer/issues/2062

Question

Most helpful comment

Based on your question, I'd say you have a couple of options:

  1. You can use --runtime-set ... instead. This will ignore the warnings for the exit code _for that particular run only_ and no changes are made to the CodeSniffer.conf file.
    Exit codes are generally only used by CI processes and such to determine whether to pass/fail a build, so you would only have that addition in the command you have in, for instance, your .travis.yml script - which is under version control -.
  2. If you use Composer, you could add a shortcode command in the scripts section of the composer.json file with the precise command you want your team to use. The team could then call, for instance, composer check-cs and be assured everyone will use the same command-line parameters and as composer.json is (or at least should be) under version control, that side of things is covered too.
  3. You can actually also set config variables in your [.]phpcs.xml[.dist] file:
    xml <config name="ignore_warnings_on_exit" value="1"/>
    See: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
  4. Lastly, if you actually wanted to ignore warnings completely, not just for the exit code, but also in the reports, there is the -n option. And yes, that can also be set in the custom ruleset.

Does this help ?

All 2 comments

Based on your question, I'd say you have a couple of options:

  1. You can use --runtime-set ... instead. This will ignore the warnings for the exit code _for that particular run only_ and no changes are made to the CodeSniffer.conf file.
    Exit codes are generally only used by CI processes and such to determine whether to pass/fail a build, so you would only have that addition in the command you have in, for instance, your .travis.yml script - which is under version control -.
  2. If you use Composer, you could add a shortcode command in the scripts section of the composer.json file with the precise command you want your team to use. The team could then call, for instance, composer check-cs and be assured everyone will use the same command-line parameters and as composer.json is (or at least should be) under version control, that side of things is covered too.
  3. You can actually also set config variables in your [.]phpcs.xml[.dist] file:
    xml <config name="ignore_warnings_on_exit" value="1"/>
    See: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
  4. Lastly, if you actually wanted to ignore warnings completely, not just for the exit code, but also in the reports, there is the -n option. And yes, that can also be set in the custom ruleset.

Does this help ?

Thanks! Both --runtime-set plus CI, and <config name="ignore_warnings_on_exit" value="1"/> can achieve what I was looking for.

I found the --runtime-set option earlier with just phpcs -h, but <config/> wasn't as obvious to me.

Was this page helpful?
0 / 5 - 0 ratings