从 Perl Critic 中排除 RequireRcsKeywords 的正确方法是什么?

发布于 2025-01-03 08:22:57 字数 1402 浏览 0 评论 0原文

我试图在单个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

人生百味 2025-01-10 08:22:57

您可以在命令行上使用 --include--exclude.perlcriticrc 文件添加一次性调整。

$ perlcritic --exclude RcsKeywords -1 --verbose 8 critictest.pl
[Modules::RequireVersionVar] No package-scoped "$VERSION" variable found at line 1, column 1.  (Severity: 2)
[InputOutput::RequireCheckedSyscalls] Return value of flagged function ignored - print at line 4, column 1.  (Severity: 1)

You can add one-off adjustments to your .perlcriticrc file with --include and --exclude on the command line.

$ perlcritic --exclude RcsKeywords -1 --verbose 8 critictest.pl
[Modules::RequireVersionVar] No package-scoped "$VERSION" variable found at line 1, column 1.  (Severity: 2)
[InputOutput::RequireCheckedSyscalls] Return value of flagged function ignored - print at line 4, column 1.  (Severity: 1)
殤城〤 2025-01-10 08:22:57

您可以将 shebang 和“no comment”注释都放在第一行。像这样:

#!/usr/bin/perl -- ## no critic RequireRcsKeywords

You can put both the shebang and the "no critic" annotation on the first line. Like this:

#!/usr/bin/perl -- ## no critic RequireRcsKeywords
我很坚强 2025-01-10 08:22:57

请注意,违规行为发生在文件的第 1 行。如果我删除您的第一行,我不会遇到 RCS 违规。我怀疑此策略适用于整个文件,并且只有在文件的第一行出现 no comment pragma 时才可以忽略。

另请注意,它告诉您它忽略了您的编译指示:

[Miscellanea::ProhibitUselessNoCritic] Useless '## no critic' annotation at line 2, column 1.  (Severity: 2)

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 the no critic pragma appears on the first line of your file.

Note also that it is telling you it is ignoring your pragma:

[Miscellanea::ProhibitUselessNoCritic] Useless '## no critic' annotation at line 2, column 1.  (Severity: 2)
软的没边 2025-01-10 08:22:57

黑客可能会使用以下第一行:

#!/usr/bin/perl -F## no critic (Miscellanea::RequireRcsKeywords)

文档< /a> 表示 -F 标志本身不会执行任何操作,因此它应该是无害的。

A hack might be to use the following first line:

#!/usr/bin/perl -F## no critic (Miscellanea::RequireRcsKeywords)

The documentation says the -F flag doesn't do anything by itself so it should be harmless.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文