是否有针对PHP文档块的PHPCS标准? [英] Is there a PHPCS standard targeting PHP docblocks?

查看:129
本文介绍了是否有针对PHP文档块的PHPCS标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个PHPCS编码标准可以检查文档块中是否存在正确的注释(@param@return@throws等),包括它们之间的适当间距?

Is there a PHPCS coding standard that would check that proper annotations (@param, @return, @throws, etc.) are present in a docblock, including the proper spacing between them?

推荐答案

尝试运行以下命令,查看其是否产生所需的内容:

Try running the following command and see if it produces what you want:

phpcs /path/to/code --standard=Squiz --sniffs=Squiz.Commenting.FunctionComment,Squiz.Commenting.FunctionCommentThrowTag,Squiz.Commenting.ClassComment,Squiz.Commenting.FileComment,Squiz.Commenting.VariableComment

如果这样做,则可以创建自己的标准,其中仅包括这些嗅探以及您要检查的其他所有内容.为此,您可以创建一个ruleset.xml文件并将其用作标准文件.

If it does, you could create your own standard that just includes those sniffs, and anything else you want to check. You do this by creating a ruleset.xml file and using that as your standard.

例如,您可以创建一个名为mystandard.xml的文件,并包含以下内容:

For example, you could create a file called mystandard.xml and include the following content:

<?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>

然后您可以改为运行以下命令:

Then you can run this command instead:

phpcs /path/to/code --standard=/path/to/mystandard.xml

ruleset.xml文件中还可以执行其他操作.在此处查看文档: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated -规则集

There are other things you can do in a ruleset.xml file. See the docs here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset

这篇关于是否有针对PHP文档块的PHPCS标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆