【问题标题】:Sonar not showing violation using custom rules?声纳没有使用自定义规则显示违规?
【发布时间】:2013-01-18 20:46:55
【问题描述】:

我正在尝试集成 Sonar 以进行代码审查和分析。我在typo3中工作,所以我在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>

当代码分析我无法得到任何形式的违规时,请帮助???

【问题讨论】:

    标签: java php typo3 sonarqube codesniffer


    【解决方案1】:

    我猜您遵循了说明如何向 Sonar 规则存储库添加新规则的指南:http://docs.codehaus.org/display/SONAR/Extending+PHP+Coding+Rules#ExtendingPHPCodingRules-ExtendingPHPCodesnifferRules

    但您可能尚未将这些新规则添加到您正在使用的质量配置文件中。这就是为什么你没有违规。查看此页面以了解如何在 Sonar 中处理质量配置文件:http://docs.codehaus.org/display/SONAR/Quality+Profiles

    【讨论】:

    • @Fabric-Sonar Team:是的,我只启用了那些平均添加的规则。看看我正在尝试开发一个带有声纳的审查系统,它可以审查typo3项目。当我检查此 /opt/lampp/htdocs/test/.sonar/target/logs/codesniffer.xml 时,我可以看到违规行为。但不在仪表板中..
    • 好的,我已经删除了相同的,并重新启动了声纳。但对我来说没有违规行为。当我检查日志时,它显示类似这样的内容 2013.01.18 14:47:14 INFO org.sonar.INFO Register rules [phpppmd_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 规则
    • 查看“.sonar/target/logs/codesniffer.xml”文件并检查返回的错误以检查您的“...”标签是否正确正确设置。
    • IIRC,“key”属性的值(在“rules.xml”文件中)应该等于您将在 PhpCodesniffer 报告中找到的“source”属性的值。
    【解决方案2】:

    规则应该只链接这个

    <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>
    

    我还把 'configKey' 改成了 'Key'

    “key”属性的值(在“rules.xml”文件中)应该等于您将在 PhpCodesniffer 报告中找到的“source”属性的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2014-08-25
      相关资源
      最近更新 更多