我开始使用 Eclipse 的 PHP Code Sniffer 扩展(Kepler SR1 Build id:20130919-0819),但我遇到了可用性问题。由于代码嗅探器在 eclipse 上的工作方式,它用与 PHP 编码错误的文件相同的图标标记有错误的文件。警告也是如此。
我的问题是,由于我正在处理的代码库中的一些问题,我们确实有很多变量(我无法更改)不是驼峰格式,而是有一个下划线。因此,eclipse 报告项目中的几乎每个页面都有问题。您可以查看分配的图像以获取示例。
所以,我的问题是,如何禁用对此 SNIFF 的检查(变量不在有效的驼峰式大小写中)?
最佳答案
您可以创建自己的 ruleset.xml 并且不包括您想要的嗅探,但包括其他的。
<?xml version="1.0"?>
<ruleset name="My Standards">
<description>My Coding Standards enforcement rule set for PHP_CodeSniffer</description>
<rule ref="PSR2.Classes.PropertyDeclaration" />
<rule ref="PSR2.ControlStructures.ElseIfDeclaration" />
<rule ref="PSR2.Files.EndFileNewline" />
<rule ref="PSR2.Methods.MethodDeclaration" />
<rule ref="PSR2.Namespaces.NamespaceDeclaration" />
<rule ref="PSR2.Namespaces.UseDeclaration" />
<rule ref="Squiz.Arrays.ArrayBracketSpacing" />
<rule ref="Squiz.Arrays.ArrayDeclaration" />
<rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops" />
<!-- Removing Sniffs from Generic as we do not want these -->
<rule ref="Generic">
<exclude name="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
<exclude name="Generic.Commenting.Fixme" />
<exclude name="Generic.Commenting.Todo" />
<exclude name="Generic.Files.EndFileNoNewline" />
<exclude name="Generic.Files.LineEndings" />
<exclude name="Generic.Files.LineLength" />
<exclude name="Generic.Files.OneClassPerFile" />
<exclude name="Generic.Files.OneInterfacePerFile" />
<exclude name="Generic.Formatting.NoSpaceAfterCast" />
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />
<exclude name="Generic.NamingConventions.CamelCapsFunctionName" />
<exclude name="Generic.PHP.ClosingPHPTag" />
<exclude name="Generic.PHP.LowerCaseConstant" />
<exclude name="Generic.VersionControl.SubversionProperties" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
<exclude name="Generic.WhiteSpace.DisallowTabIndent" />
<exclude name="Generic.Files.LowercasedFilename" />
</rule>
</ruleset>
关于eclipse - 如何忽略 Eclipse 上 PHP Code Sniffer 的一些验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552976/