【问题标题】:PHP_CodeSniffer - Show Sniff that failedPHP_CodeSniffer - 显示失败的嗅探
【发布时间】:2012-11-23 17:06:47
【问题描述】:

PHP_CodeSniffer 中是否有设置来显示失败的嗅探?我正在将输出与我们的编码标准进行比较,并且逐个使用很难破译哪个测试失败,看看我们可能想要忽略哪个。

如果有一种简单的方法来显示故障嗅探,那么我可以更轻松快捷地完成配置。

【问题讨论】:

    标签: php configuration codesniffer


    【解决方案1】:

    您可以使用 -s 命令行参数来显示错误消息的来源。

    $ phpcs temp.php -s       
    
    FILE: /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/temp.php
    --------------------------------------------------------------------------------
    FOUND 4 ERROR(S) AFFECTING 2 LINE(S)
    --------------------------------------------------------------------------------
     2 | ERROR | Missing file doc comment (PEAR.Commenting.FileComment.Missing)
     2 | ERROR | Missing class doc comment (PEAR.Commenting.ClassComment.Missing)
     2 | ERROR | Opening brace of a class must be on the line after the definition
       |       | (PEAR.Classes.ClassDeclaration.OpenBraceNewLine)
     3 | ERROR | Missing function doc comment
       |       | (PEAR.Commenting.FunctionComment.Missing)
    --------------------------------------------------------------------------------
    
    Time: 0 seconds, Memory: 4.50Mb
    

    您还可以使用源报告显示所有失败的嗅探列表。

    $ phpcs temp.php --report=source
    
    PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
    --------------------------------------------------------------------------------
    STANDARD  CATEGORY            SNIFF                                        COUNT
    --------------------------------------------------------------------------------
    PEAR      Commenting          File comment missing                         1
    PEAR      Commenting          Class comment missing                        1
    PEAR      Classes             Class declaration open brace new line        1
    PEAR      Commenting          Function comment missing                     1
    --------------------------------------------------------------------------------
    A TOTAL OF 4 SNIFF VIOLATION(S) WERE FOUND IN 4 SOURCE(S)
    --------------------------------------------------------------------------------
    
    Time: 0 seconds, Memory: 4.75Mb
    
    $ phpcs temp.php --report=source -s
    
    PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
    --------------------------------------------------------------------------------
    SOURCE                                                                     COUNT
    --------------------------------------------------------------------------------
    PEAR.Commenting.FileComment.Missing                                        1
    PEAR.Commenting.ClassComment.Missing                                       1
    PEAR.Classes.ClassDeclaration.OpenBraceNewLine                             1
    PEAR.Commenting.FunctionComment.Missing                                    1
    --------------------------------------------------------------------------------
    A TOTAL OF 4 SNIFF VIOLATION(S) WERE FOUND IN 4 SOURCE(S)
    --------------------------------------------------------------------------------
    
    Time: 0 seconds, Memory: 4.75Mb
    

    【讨论】:

    • 有什么办法同时拥有这两种选择?我喜欢 -s 向我展示因错误而失败的嗅探,然后 --report=source 的摘要视图有利于整体覆盖。但是,能够同时看到两者会很好。
    • 您可以根据需要打印 2 份报告,也可以打印任意数量的报告。如果需要,您还可以将不同的报告打印到不同的输出文件。对于我给出的示例,要显示两个报告,您可以使用以下命令:phpcs temp.php -s --report=full --report=source
    • 谢谢。这两个报告的第二个选项正是我想要的。如果这是一个正常的答案,那么我可以再次投票。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 2010-10-18
    • 2015-04-09
    • 1970-01-01
    相关资源
    最近更新 更多