Where is the repository “Standards” of PHP CodeSniffer with the sonar PHP plugin?

被刻印的时光 ゝ 提交于 2019-12-23 03:00:09

问题


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:

  1. Install PHP_Codesniffer (via Composer, Pear or plain from Github) [1]
  2. Set the path to PHP_Codesniffer inside SonarCube
  3. 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:


  1. Get the rules (PSR1, PSR2, or your own) from here: http://docs.codehaus.org/display/SONAR/PHP+Custom+Coding+Rules
  2. Copy and paste them as described here into the Codesniffer Plugin Custom Rules: http://docs.codehaus.org/display/SONAR/PHP+Custom+Coding+Rules
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!