我TestMyClass.php在同一个文件中有两个类定义(单元测试类),并且PHP Code Sniffer抱怨每个类必须自己在一个文件中.我怎么能压制这个警告?
class MyClassImpl implements MyInterface
{
// ...
}
class MyClassTest extends \PHPUnit_Framework_TestCase
{
// ...
}
Run Code Online (Sandbox Code Playgroud) 我现在花了2个多小时试图弄清楚如何要求{与方法声明在同一行,而不是默认要求是下一行.我怎么能这样做?我已经将PSR2标准复制到一个名为PSR2的新文件夹,以便根据自己的喜好对其进行修改.所以我正在研究的基础基本上是我想要修改的PSR2标准.
我已经尝试过ruleset.xml,我试图在代码中直接修改它而没有成功.
<rule ref="PEAR.Classes.ClassDeclaration">
<properties>
<property name="eolChar" value="{"/>
</properties>
</rule>
<rule ref="PSR2R.Classes.ClassDeclaration">
<properties>
<property name="eolChar" value="{"/>
</properties>
</rule>
Run Code Online (Sandbox Code Playgroud)
我已经发现这是错的.EOL由phpcs设置.但我无法弄清楚我是否可以通过规则配置一个值.
到目前为止,这对我来说很好用(搞愚蠢的空间!):
<?xml version="1.0"?>
<ruleset name="PSR2R">
<description>PSR2 with tabs instead of spaces.</description>
<arg name="tab-width" value="4"/>
<rule ref="PSR2">
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
</rule>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
</ruleset>
Run Code Online (Sandbox Code Playgroud)
但我想补充上面的规则.
PHPCS正在检查我在PhpStorm上的JS文件,
我需要禁用此功能
我在文件中添加了这一行,phpcs.xml.dist但没有运气
<exclude-pattern>*\.(inc|css|js)</exclude-pattern>
Run Code Online (Sandbox Code Playgroud) 我想将 PHP CodeSniffer 添加到 VScode。
在 VScode 中我收到错误'phpcs: Referenced sniff "WordPress-Core" does not exist'
但是,当我在终端中运行以下命令时:
phpcs --standard="WordPress-Core" dropdowns.php
PHP CodeSniffer 按预期工作,并显示以下终端输出:
--------------------------------------------------------------------------------
FOUND 34 ERRORS AND 17 WARNINGS AFFECTING 51 LINES
--------------------------------------------------------------------------------
15 | WARNING | [x] Array double arrow not aligned correctly; expected 10
| | space(s) between "'id'" and double arrow, but found 1.
17 | WARNING | [x] Array double arrow not aligned correctly; expected 4
| | space(s) between "'taxonomy'" and double arrow, but found …Run Code Online (Sandbox Code Playgroud) 我在 VS Code 中使用 PHPCS 和 PHPCBF 进行 WordPress 开发。
(按照https://github.com/tommcfarlin/phpcs-wpcs-vscode中提到的说明)
虽然 PHPCBF 按照 WPCS 格式化代码,但我仍然觉得代码看起来非常丑陋,尤其是当 PHP 文档中存在 Html 标签时。
当我使用 Intelephense 格式化 Php 代码时,代码看起来赏心悦目,包括正确缩进的 Html 标签。使用 Intelephense 的代价是代码不再符合 WPCS。有一个选项可以将 WordPress 作为存根包含在 Intelephense 中,但这仅用于包含 WordPress 特定功能,与格式无关。
使用 Intelephense 格式化时遇到的一些问题是:
<?php
// this is a blank line inserted by Intelephense which is causing error no.2 provided in summary above
/**
* This is a sample file
*
* @package something.
* something something
* something something
*/ …Run Code Online (Sandbox Code Playgroud) 不知道这对这里还是SuperUser是一个更好的问题。如果它属于那里,请随意移动。
我正在使用php-cs-fixer,并且对缩进有一个独特的要求-我需要两个空格而不是四个空格。有没有办法更改此设置?
请注意,我正在使用atom-beautifier运行php-cs-fixer,因此从那里开始,任何解决方案都应该是理想的。
在问之前,我也在Google上花费了数小时来搜索答案,在phpcs中我遇到了这个错误“未指定PHP版本”,但是我在Google上找不到答案,最终我碰到了这个“ PHP版本5” ”清除了错误,但由于PHP 5已过时,我感到困惑,因为我使用的是PHP 7.2.10。
如果有人能对此有所启发,我将非常感谢,非常感谢。
编辑:我刚刚在顶部添加了@行,它打破了“ PHP版本5”,因为它说“未指定PHP版本”。
设想
有时,我想运行 PHPCS,但让它忽略一个规则,在本例中是 Camel Case Method Name 规则。
我知道我可以创建一个新的规则集,它从另一个规则集继承所有规则集,并排除一个规则集,但如果可能的话,我想从命令行执行此操作。
题
运行时phpcs --standard=PSR2 --extentions=php src/,有没有办法从这次运行的标准中排除单个规则?
我了解如何使用 xml 配置 phpcs,但找不到如何禁用某些嗅探。这是我当前的配置(甚至不知道这是否正确):
\n\n<?xml version="1.0" encoding="UTF-8"?>\n<ruleset name="custom" \n xmlns="http://pmd.sf.net/ruleset/1.0.0" \n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">\n <rule ref="rulesets/codesize.xml"/>\n <rule ref="rulesets/controversial.xml/Superglobals"/>\n <rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>\n <rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>\n <rule ref="rulesets/design.xml"/>\n <rule ref="rulesets/naming.xml/ShortMethodName"/>\n <rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>\n <rule ref="rulesets/naming.xml/ConstantNamingConventions"/>\n <rule ref="rulesets/naming.xml/BooleanGetMethodName">\n <properties>\n <property name="checkParameterizedMethods" value="true"/>\n </properties>\n </rule>\n <rule ref="rulesets/unusedcode.xml"/>\n\n <arg name="tab-width" value="2"/>\n <rule ref="Generic.WhiteSpace.ScopeIndent">\n <properties>\n <property name="indent" value="2"/>\n </properties>\n </rule>\n\n <rule ref="Generic.Files.LineLength">\n <properties>\n <property name="lineLimit" value="140"/>\n <property name="absoluteLineLimit" value="0"/>\n </properties>\n </rule>\n</ruleset>\nRun Code Online (Sandbox Code Playgroud)\n\n我想禁用这些:
\n\n[phpcs] @copyright tag must contain a year and the name of the …我正在尝试设置 PHPCS 插件,但到目前为止我只收到此错误:
phpcs:发生未知错误。请验证 /home/[user]/Documents/offprojects/vet_direct/vetsdirectapp/vendor/bin/phpcs --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity= 5 --stdin-path=/home/[user]/Documents/offprojects/vet_direct/vetsdirectapp/app/Http/Controllers/JobController.php - 返回有效的 json 对象。
我按照插件页面的安装指南在全局和项目中安装了 PHPCS。此外,终端中的命令显示此错误:
zsh: command not found: phpcs
Run Code Online (Sandbox Code Playgroud)
知道这里出了什么问题吗?
phpcs ×10
php ×7
wordpress ×2
atom-editor ×1
codesniffer ×1
intelephense ×1
javascript ×1
phpstorm ×1
phpunit ×1
rules ×1