是否有一个PHPCS编码标准可以检查正确的注释(@param
、@return
、@throws
等)是否存在于文档块中,包括它们之间的适当间距?
发布于 2012-12-08 08:54:38
尝试运行以下命令,看看它是否会产生您想要的结果:
phpcs /path/to/code --standard=Squiz --sniffs=Squiz.Commenting.FunctionComment,Squiz.Commenting.FunctionCommentThrowTag,Squiz.Commenting.ClassComment,Squiz.Commenting.FileComment,Squiz.Commenting.VariableComment
如果是这样的话,你可以创建自己的标准,只包括这些嗅探,以及任何你想要检查的东西。为此,您可以创建一个ruleset.xml
文件并将其用作您的标准。
例如,您可以创建一个名为mystandard.xml
的文件,并包含以下内容:
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>My custom coding standard.</description>
<rule ref="Squiz.Commenting.FunctionComment" />
<rule ref="Squiz.Commenting.FunctionCommentThrowTag" />
<rule ref="Squiz.Commenting.ClassComment" />
<rule ref="Squiz.Commenting.FileComment" />
<rule ref="Squiz.Commenting.VariableComment" />
</ruleset>
然后,您可以改为运行此命令:
phpcs /path/to/code --standard=/path/to/mystandard.xml
您还可以在ruleset.xml
文件中执行其他操作。请参阅此处的文档:https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset
https://stackoverflow.com/questions/13767550
复制相似问题