问题
I have installed SonarQube™ and the PHP Plugin.
I want to add a new CodeSniffer rule, like it's indicated in http://docs.codehaus.org/display/SONAR/PHP+Custom+Coding+Rules.
However, I can't find the location of the "Standard" repository wich contains existing rules (PEAR, Squiz, Generic...). So I don't know where I have to add my new file corresponding to the xml rule I have defined in the sonar settings.
Maybe I've missed something but I looked in every folder in the PHP plugin and didn't find this "Standard" folder. I even extracted content from the .jar files of the plugin and even looked in the rest of my disk in case of the code sniffer repository were somewhere else.
Can you help me ?
Thanks.
回答1:
The standard folder belongs to PHP_CodeSniffer not to SonorCube. Its located inside the PHP_Codesniffer installation (which depends on how you installed PHP_CodeSniffer on your machine). If you found it the Standards folder is located under
PHP_CodeSniffer/CodeSniffer/Standards/
My guess is that you want execute a rule inside SonarCube. I don't know SonarCube but I am sure you need to configure the path to PHP_CodeSniffer somewhere. After done that its like it says in the docu:
<?xml version="1.0" encoding="UTF-8"?>
<rules>
<rule key="PEAR.Commenting.FileComment.TagIndent" priority="MAJOR">
<!-- name, configKey, description are mandatory -->
<name>Tag comment incorrectly indented</name>
<configKey>TAG_INDENT</configKey>
<description>@category tag comment incorrectly indented</description>
</rule>
<rule key="...>
...
</rule>
</rules>
With:
PEAR Commenting FileComment TagIndent
<standard_folder>.<sniff_subfolder>.<sniff_file_without_sniff_suffix>.<error_name>
The way to go is:
- Install PHP_Codesniffer (via Composer, Pear or plain from Github) [1]
- Set the path to PHP_Codesniffer inside SonarCube
- Configure the rules
[1] https://github.com/squizlabs/PHP_CodeSniffer
回答2:
I'm late but the latest Sonar uses its own Rule Engine now, so no more dependency on CodeSniffer. For me, it means I can no longer run my Symfony2 code standards checker on Sonar, sad...
回答3:
- Get the rules (PSR1, PSR2, or your own) from here: http://docs.codehaus.org/display/SONAR/PHP+Custom+Coding+Rules
- Copy and paste them as described here into the Codesniffer Plugin Custom Rules: http://docs.codehaus.org/display/SONAR/PHP+Custom+Coding+Rules
- Download and restore the profiles as described in 1
Works fine with SonarQube 4.1.1
来源:https://stackoverflow.com/questions/21579710/where-is-the-repository-standards-of-php-codesniffer-with-the-sonar-php-plugin