0

I am trying to integrate Sonar for code review and analysis . I am working in typo3, so I added the following rules in rules.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
    <rules>

    <rule key="TYPO3.Commenting.FunctionDocComment.TagIndenst"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>Tag comment incorrectly indented</name>
        <configKey>TAG_INDENT</configKey>
        <description>@category tag comment incorrectly indented</description>
    </rule>

    <rule
        key="TYPO3.Commenting.NoAuthorAnnotationInFunctionDocComment.AuthorAnnotation"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>NoAuthorAnnotationInFunctionDocComment</name>
        <configKey>TAG_INDENT</configKey>
        <description>@category tag comment incorrectly indented</description>
    </rule>



    <rule key="TYPO3.Commenting.ValidCommentIndent.ValidCommentIndent"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>ValidCommentIndent</name>
        <configKey>T_COMMENT</configKey>
        <description>@category tag comment incorrectly indented</description>
    </rule>

    <rule key="TYPO3.Commenting.ValidCommentLineLength.ValidCommentLineLength"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>ValidCommentLineLength</name>
        <configKey>T_COMMENT, T_DOC_COMMENT</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.Commenting.ValidCommentLineLength.ValidCommentLineLength"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>ValidCommentLineLength</name>
        <configKey>T_COMMENT, T_DOC_COMMENT</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.ControlStructures.AlignedBreakStatement.AlignedBreakStatement"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>AlignedBreakStatement</name>
        <configKey>T_BREAK,</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.ControlStructures.DisallowEachInLoopCondition.DisallowEachInLoopCondition"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>DisallowEachInLoopCondition</name>
        <configKey>T_WHILE,</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.ControlStructures.DisallowElseIfConstruct.DisallowElseIfConstruct"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>DisallowElseIfConstruct</name>
        <configKey>T_WHILE,</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.ControlStructures.ValidBreakStatementsInSwitches.ValidBreakStatementsInSwitches"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>ValidBreakStatementsInSwitches</name>
        <configKey>T_BREAK,</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.ControlStructures.ValidDefaultStatementsInSwitches.ValidDefaultStatementsInSwitches"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>ValidDefaultStatementsInSwitches</name>
        <configKey>T_SWITCH,</configKey>
        <description>@category</description>
    </rule>
    <rule key="TYPO3.Debug.DebugCode.DebugCode"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>DebugCode</name>
        <configKey>T_STRING, T_COMMENT,</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.Files.EncodingUtf8.EncodingUtf8"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>EncodingUtf8</name>
        <configKey>T_OPEN_TAG</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.Files.IncludingFile.IncludingFile"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>IncludingFile</name>
        <configKey>T_INCLUDE_ONCE, T_REQUIRE, T_INCLUDE</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.Files.LowercasedFilename.LowercasedFilename"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>LowercasedFilename</name>
        <configKey>T_OPEN_TAG</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.Files.OneClassPerFile.OneClassPerFile"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>OneClassPerFile</name>
        <configKey>T_CLASS</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.Files.OneInterfacePerFile.OneInterfacePerFile"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>OneInterfacePerFile</name>
        <configKey>T_INTERFACE</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.NamingConventions.ValidFunctionName.ValidFunctionName"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>ValidFunctionName</name>
        <configKey>T_FUNCTION</configKey>
        <description>@category</description>
    </rule>
    <rule key="TYPO3.NamingConventions.ValidVariableName.ValidVariableName"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>ValidVariableName</name>
        <configKey></configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.PHP.CharacterAfterPHPClosingTag.CharacterAfterPHPClosingTag"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>CharacterAfterPHPClosingTag</name>
        <configKey>T_CLOSE_TAG</configKey>
        <description>@category</description>
    </rule>

    <rule key="TYPO3.PHP.CharacterBeforePHPOpeningTag.CharacterBeforePHPOpeningTag"
        priority="MAJOR">
        <category name="Maintainability" />
        <name>CharacterBeforePHPOpeningTag</name>
        <configKey>T_OPEN_TAG</configKey>
        <description>@category</description>
    </rule>
</rules>

When the code analysis i am not able to get any kind of violations , Please help ???

Perception
  • 79,279
  • 19
  • 185
  • 195
Siva
  • 481
  • 7
  • 26

2 Answers2

0

I guess that you followed the guidelines that explain how to add new rules to Sonar rule repository: http://docs.codehaus.org/display/SONAR/Extending+PHP+Coding+Rules#ExtendingPHPCodingRules-ExtendingPHPCodesnifferRules

But you probably haven't added those new rules to the quality profile that you are using. This is why you get no violation. Have a look at this page to understand how to handle quality profiles in Sonar: http://docs.codehaus.org/display/SONAR/Quality+Profiles

  • @Fabric-Sonar Team: Yes i have only enabled those rules which added by mean . See what am trying is to develop a review system with sonar , Which can review typo3 projects . when i check this /opt/lampp/htdocs/test/.sonar/target/logs/codesniffer.xml there i can see the violations . But not in the dashboard .. – Siva Jan 18 '13 at 08:52
  • OK i have removed the same , and restarted sonar . But no violations for me . when i checked log its shows something like this 2013.01.18 14:47:14 INFO org.sonar.INFO Register rules [phppmd_rules/php] done: 129 ms 2013.01.18 14:47:14 INFO org.sonar.INFO Register rules [php_codesniffer_rules/php]... 2013.01.18 14:47:14 INFO org.sonar.INFO 607 rules – Siva Jan 18 '13 at 09:23
  • 1
    Have a look in the ".sonar/target/logs/codesniffer.xml" file and check errors that are returned to check if your "..." tags are correctly set. – Fabrice - SonarSource Team Jan 18 '13 at 09:28
  • :can yu please tell what is the configkey and how to set this . – Siva Jan 18 '13 at 09:36
  • @Fabric-Sonar Team: juz now i have modified rule.xml file and added only one rule in codesniffer.xml am getting the violation but not in dashboard LowercaseClassKeywords T_WHITESPACE @category tag comment incorrectly indented – Siva Jan 18 '13 at 09:57
  • 1
    IIRC, the value of the "key" attribute (in the "rules.xml" file) should be equal to the value of the "source" attribute that you'll find in the PhpCodesniffer report. – Fabrice - SonarSource Team Jan 18 '13 at 10:05
  • @Fabric-Sonar Team:in rules.xml a rule with configKey TYPO3.WhiteSpace.DisallowSpaceIndent.http://forge.typo3.org/projects/team-php_codesniffer/wiki/Whitespace#Indent-code in codesniffer.xml But shows nothing in front end . – Siva Jan 18 '13 at 10:49
0

The rules should be link this only

<rule key="TYPO3.Commenting.ValidCommentLineLength.ValidCommentLineLength"
            priority="MAJOR">
            <category name="Maintainability" />
            <name>TYPO3.Commenting.ValidCommentLineLength.ValidCommentLineLength</name>
            <Key>TYPO3.Commenting.ValidCommentLineLength</Key>
            <description>@category</description>
        </rule>

Also i have changed 'configKey' to 'Key'

The value of the "key" attribute (in the "rules.xml" file) should be equal to the value of the "source" attribute that you'll find in the PhpCodesniffer report.

Siva
  • 481
  • 7
  • 26