扩展 phpcodesniffer 以根据错误代码过滤报告
我正在尝试扩展 PHPCodeSniffer。我想要实现的是使用错误代码过滤报告。
为了解释这一点,可以说我有一条错误消息,例如“错误代码:630,函数不兼容”
当我从命令行运行 PHPCS 时,我应该能够传递参数“错误代码”,以便根据它。(仅显示错误代码的结果,例如 630)
例如
$ phpcs --standard=mystanderd /path/to/code/myfile.php --errorcode=603
,输出将是
FILE: /path/to/code/myfile.php
--------------------------------------------------------------------------------
FOUND 4 ERROR(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
2 | ERROR | 603 | function is not compatible
20 | ERROR | 603 | function is not compatible
51 | ERROR | 603 | function is not compatible
88 | ERROR | 603 | function is not compatible
--------------------------------------------------------------------------------
实现它的最佳方法是什么?据我所知,我们只能根据严重性进行过滤,因为它有内置的支持。
我想避免修改 PHPCodeSniffer 的核心。我想做的是编写一个包装器脚本,它将接受来自 CLI 的参数并执行 PHPCS 捕获 o/p 并在抛出到控制台之前对其进行操作。但是,我认为这不是最好的解决方案。
I am trying to extend PHPCodeSniffer.What I am trying to achive is to filter the report using error codes.
To explain this lets say I have an error message like "error code : 630 , function is not compatible"
When I run PHPCS from command line , I shoudl be able to pass an argument "error code" so that the report is filtered based on it.(only show result for error code say 630)
e.g.
$ phpcs --standard=mystanderd /path/to/code/myfile.php --errorcode=603
and output will be
FILE: /path/to/code/myfile.php
--------------------------------------------------------------------------------
FOUND 4 ERROR(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
2 | ERROR | 603 | function is not compatible
20 | ERROR | 603 | function is not compatible
51 | ERROR | 603 | function is not compatible
88 | ERROR | 603 | function is not compatible
--------------------------------------------------------------------------------
what is the best way to achive it ? as far as what I have understood we can filter only based on seviority as it have inbuilt support.
I would like to avoid modifying the core of PHPCodeSniffer
. What I am thinking to do is to write a wrapper script which will accept the argument from CLI and execute PHPCS the capture the o/p and manipulate it before throwing out to the console.However, I don't think it is a best solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想到了一个利用 grep 和 wc 的 bash 脚本。
a bash script utilising grep and wc comes to mind.
您还可以使用这样的 PHP 脚本(假设这称为 my_wrapper.php):
当这样调用时:
使用这样的 cs_out.txt:
生成如下输出:
Making the keys of the $legal_codes array可通过命令行指定my_wrapper.php 的参数留给读者作为练习。
You could also use a PHP script like this (let's say this is called my_wrapper.php):
Which when called like this:
With cs_out.txt like this:
Produces output like this:
Making the keys of the $legal_codes array specifiable via command line parameter to my_wrapper.php is left as an exercise for the reader.