从 Perl Critic 中排除 RequireRcsKeywords 的正确方法是什么?
我试图在单个 Perl 脚本中排除 Perl Critic 的 RequireRcsKeywords 检查。我不想更改 .perlcriticrc 中的默认策略,因此我在源代码顶部添加了“无批评者”行。尽管有这样的变化,Perl Critic 仍然抱怨缺少 RCS 关键字。
这是我的测试用例(critictest.pl):
#!/usr/bin/perl
## no critic (RequireRcsKeywords)
use warnings;
use strict;
print "Hello, World.\n";
当我执行 perlcritic -1 --verbose 8ritictest.pl
时,我得到以下输出:
[Miscellanea::RequireRcsKeywords] RCS keywords $Id$ not found at line 1, column 1. (Severity: 2)
[Miscellanea::RequireRcsKeywords] RCS keywords $Revision$, $HeadURL$, $Date$ not found at line 1, column 1. (Severity: 2)
[Miscellanea::RequireRcsKeywords] RCS keywords $Revision$, $Source$, $Date$ not found at line 1, column 1. (Severity: 2)
[Modules::RequireVersionVar] No package-scoped "$VERSION" variable found at line 1, column 1. (Severity: 2)
[Miscellanea::ProhibitUselessNoCritic] Useless '## no critic' annotation at line 2, column 1. (Severity: 2)
[InputOutput::RequireCheckedSyscalls] Return value of flagged function ignored - print at line 5, column 1. (Severity: 1)
我知道 Perl Critic 正在工作,因为如果我添加 ## no Criteria (RequireCheckedSyscalls)
那么输出中的错误就会消失。我还尝试添加 `## no comment (Miscellanea::RequireRcsKeywords)
但这并没有引起任何变化。告诉 Perl Critic 忽略我的文件中的 RequireRcsKeywords 策略而不必使用外部策略文件的正确方法是什么?
编辑:我正在使用 Perl 5.10.1、Perl Critic 1.108 和 Debian 6.0.3。
I'm trying to exclude checks of Perl Critic's RequireRcsKeywords in a single Perl script. I don't want to change my default policy in .perlcriticrc so I added a "no critic" line to the top of the source. Despite that change, Perl Critic still complains about the lack of RCS keywords.
Here is my test case (critictest.pl):
#!/usr/bin/perl
## no critic (RequireRcsKeywords)
use warnings;
use strict;
print "Hello, World.\n";
When I execute perlcritic -1 --verbose 8 critictest.pl
I get the following output:
[Miscellanea::RequireRcsKeywords] RCS keywords $Id$ not found at line 1, column 1. (Severity: 2)
[Miscellanea::RequireRcsKeywords] RCS keywords $Revision$, $HeadURL$, $Date$ not found at line 1, column 1. (Severity: 2)
[Miscellanea::RequireRcsKeywords] RCS keywords $Revision$, $Source$, $Date$ not found at line 1, column 1. (Severity: 2)
[Modules::RequireVersionVar] No package-scoped "$VERSION" variable found at line 1, column 1. (Severity: 2)
[Miscellanea::ProhibitUselessNoCritic] Useless '## no critic' annotation at line 2, column 1. (Severity: 2)
[InputOutput::RequireCheckedSyscalls] Return value of flagged function ignored - print at line 5, column 1. (Severity: 1)
I know that Perl Critic is working because if I add ## no critic (RequireCheckedSyscalls)
then that error in the output goes away. I also tried adding `## no critic (Miscellanea::RequireRcsKeywords)
but that didn't cause any change. What is the correct way to tell Perl Critic to ignore the RequireRcsKeywords policy in my file without having to use an external policy file?
EDIT: I'm using Perl 5.10.1, Perl Critic 1.108, and Debian 6.0.3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在命令行上使用
--include
和--exclude
向.perlcriticrc
文件添加一次性调整。You can add one-off adjustments to your
.perlcriticrc
file with--include
and--exclude
on the command line.您可以将 shebang 和“no comment”注释都放在第一行。像这样:
You can put both the shebang and the "no critic" annotation on the first line. Like this:
请注意,违规行为发生在文件的第 1 行。如果我删除您的第一行,我不会遇到
RCS
违规。我怀疑此策略适用于整个文件,并且只有在文件的第一行出现no comment
pragma 时才可以忽略。另请注意,它告诉您它忽略了您的编译指示:
Notice that the violation occurs on Line 1 of your file. If I delete your first line, I do not get the
RCS
violation. I suspect that this policy applies to the entire file and can only be ignored if theno critic
pragma appears on the first line of your file.Note also that it is telling you it is ignoring your pragma:
黑客可能会使用以下第一行:
文档< /a> 表示 -F 标志本身不会执行任何操作,因此它应该是无害的。
A hack might be to use the following first line:
The documentation says the -F flag doesn't do anything by itself so it should be harmless.