代码之家  ›  专栏  ›  技术社区  ›  Julian

为什么CodeSniffer不排除--ignore指定的文件夹?

  •  6
  • Julian  · 技术社区  · 12 年前

    我使用Jenkins(Hudson)CI,每天晚上都使用许多用于重新移植的工具来分析代码,包括用于Checkstyle报告的Codesniffer。 我不想忽视 ./framework/* 目录,但它坚持包括它,不管我如何努力 --ignore 参数

    该报告创建和解析成功,但对我们来说没有任何用处,因为该框架中存在大量违反梨编码标准的行为。

    代码嗅探器是从我的Ant构建脚本中调用的,如下所示:

    <target name="phpcs-ci" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
     <exec executable="phpcs" dir="${basedir}" output="${basedir}/build/logs/checkstyle.xml" failonerror="off">
      <arg line="--report=checkstyle --standard=${basedir}/build/phpcs.xml --extensions=php  --ignore=*/framework/* ${basedir}" />
     </exec>
    </target>
    

    我试过了 --ignore=framework , --ignore=framework/ ,和上面一行中的那个,都来自我在网上找到的例子。

    我还试着为每个论点使用不同的行( using < arg value"..." /> ),但无济于事。

    有什么想法吗? 非常感谢:)

    编辑: --ignore参数现在是:

    --ignore=${basedir}/framework/
    

    …尽管如此,框架文件夹仍被包括在内。有没有人有一个有效的PhpCodeSniffer配置,带有--ignore参数,有效?

    在这里交叉手指

    4 回复  |  直到 12 年前
        1
  •  8
  •   Nick    12 年前

    我在詹金斯身上也遇到了同样的问题,上面的回答在一定程度上帮助了我。这就是我现在拥有的(并在我的系统上工作)。

    如果您的系统如下所示:

    /
    /build.xml
    /foo
    /foo/bar
    

    这是我的build.xml中的内容

      <target name="phpcs" description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
    <exec executable="phpcs">
      <arg value="--standard=${basedir}/build/phpcs.xml" />
      <arg value="--ignore=foo/bar" />
      <arg path="${basedir}" />
    </exec>
    

    诀窍是不要使用${basedir}并丢失目录的尾部斜杠。

    我希望它能有所帮助

        2
  •  5
  •   markdwhite    12 年前

    也可以将这些排除项放在build/phpcs.xml中。

    排除js/facebook-dir中所有文件的示例,js/jquery*的通配符匹配和指定的文件名。

    <exclude-pattern>lib/facebook</exclude-pattern>
    <exclude-pattern>js/jquery*</exclude-pattern>
    <exclude-pattern>lib/Postmark.php</exclude-pattern>
    
        3
  •  3
  •   cweiske agentofuser    12 年前

    使用 * 将不起作用,因为外壳将展开它们。

    根据您的版本php_codesniffer,您必须传递要忽略的目录的完整路径(旧版本),或者传递构建目录的相对路径以使忽略生效(从php_codesiniffer 1.3.6版本开始):

    摘录自 Changelog 以下为:

    • 忽略模式现在根据正在检查的目录检查文件的相对路径
        4
  •  1
  •   Julian    12 年前

    感谢您的投入。我最后就这样解决了

        <target name="phpcs-ci" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
         <exec executable="phpcs" failonerror="off">
          <arg line="-v --report-checkstyle=${basedir}/build/logs/checkstyle.xml --standard=${basedir}/build/phpcs.xml --extensions=php --ignore=extensions,library ./protected" />
         </exec>
        </target>
    

    作品