【问题标题】:Disable checkstyle validation for specific variables禁用特定变量的 checkstyle 验证
【发布时间】:2011-06-02 08:36:33
【问题描述】:

我在一个使用 checkstyle 来验证代码的 PHP 项目中工作。我对使用 simplexml 读取 XML 的部分代码有疑问,XML 全部为大写,例如:

$response = simplexml_load_string($xml);
$code = $response->CODE; // checkstyle won't validate this because it is in uppercase

这段代码给了我警告,因为变量名是大写的(变量必须是驼峰式)。因此,代码中有很多警告。

问题是:我可以禁用检查特定变量或整个代码区域吗?怎么样?

非常感谢。

【问题讨论】:

    标签: php simplexml checkstyle


    【解决方案1】:

    我不知道如何使用 checkstyle 来做到这一点,但 PHPCS 也可以创建 reports in CheckStyle format。因此,如果您不固定使用 Checkstyle,则可以切换。使用 PHPCS 你可以add pseudo annotations into the code to skip checking,例如

    // @codingStandardsIgnoreFile
    

    或者只是代码的一部分

    $response = simplexml_load_string($xml);
    // @codingStandardsIgnoreStart
    $code = $response->CODE;
    // @codingStandardsIgnoreEnd
    echo $code->asXml();
    

    还要检查 http://phpqatools.orghttp://jenkins-php.org/ 以获取其他 QA 工具。

    【讨论】:

    • 非常感谢您的回复!我做了一些测试,效果很好,最后我们要切换到 PHPCS。
    猜你喜欢
    • 2014-01-25
    • 1970-01-01
    • 2015-11-25
    • 2023-04-02
    • 1970-01-01
    • 2011-04-30
    • 2019-06-04
    • 1970-01-01
    • 2018-04-19
    相关资源
    最近更新 更多