What is the correct way to exclude RequireRcsKeywords from Perl Critic?

I am trying to exclude Perl Critic RequireRcsKeywords checks in one Perl script. I do not want to change my default policy in .perlcriticrc, so I added the โ€œno criticismโ€ line to the top of the source. Despite this 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 works, because if I add ## no critic (RequireCheckedSyscalls) , then this error in the output will disappear. I also tried adding `## no critic (Miscellanea::RequireRcsKeywords) , but this did not cause any changes. What is the correct way to tell Perl Critic to ignore the RequireRcsKeywords policy in my file without using an external policy file?

EDIT: I am using Perl 5.10.1, Perl Critic 1.108 and Debian 6.0.3.

+6
source share
4 answers

At the .perlcriticrc command line, .perlcriticrc can add one-time settings to --include and --exclude .

 $ 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) 
+4
source

Note that the violation occurs on line 1 of your file. If I delete your first line, I do not get an RCS violation. I suspect that this policy applies to the entire file and can only be ignored if the pragma no critic appears on the first line of your file.

Notice also that he tells you that he is ignoring your pragma:

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

You can add the annotation "shebang" and "no crit" to the first line. Like this:

 #!/usr/bin/perl -- ## no critic RequireRcsKeywords 
+2
source

The following line can be used for hacking:

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

The documentation says that the -F flag does nothing on its own, so it should be harmless.

0
source

Source: https://habr.com/ru/post/907868/


All Articles