【问题标题】:PHPCS cannot be set to PSR2 by defaultPHPCS默认不能设置为PSR2
【发布时间】:2019-01-14 05:12:04
【问题描述】:

我正在尝试将 PHPCS 设置为默认使用 PSR2 运行,而不必在每次运行时都指定它。

我用phpcs --config-set standard PSR2 设置了默认值,当我检查配置时,它似乎已设置:

$ phpcs --config-show
Using config file: /usr/bin/CodeSniffer.conf

standard: PSR2

当我实际在文件上运行它时,它作为 PEAR 运行:

$ phpcs -v transarray.php 
Registering sniffs in the PEAR standard... DONE (28 sniffs registered)
Creating file list... DONE (1 files in queue)
Changing into directory /root
Processing transarray.php [PHP => 136 tokens in 26 lines]... DONE in 2ms  (11 errors, 0 warnings)
...

如果我运行 phpcs --standard=PSR2 ... 它可以正常工作,但我宁愿不必在每次运行时都包含它。

报告的代码错误符合使用的标准。

【问题讨论】:

    标签: phpcs


    【解决方案1】:

    根据documentation,您必须使用default_standard 作为配置键。所以命令必须是:

    phpcs --config-set default_standard PSR2

    【讨论】:

    • 您已获得您的用户名!我无法相信错过这一点的人数。非常感谢。我大约有 10 种方法可以解决这个问题,并且一直在查看源代码以找出答案。我觉得自己很笨,但既然我已经经历了这么多,我可能可以为 PHPCS 贡献一些其他的修复。
    • 谢谢!很高兴能提供帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 2015-02-02
    • 2018-04-21
    • 2015-04-25
    • 2015-02-13
    相关资源
    最近更新 更多