【问题标题】:Perl::Critic: Code before warnings are enabled when using -wPerl::Critic:使用 -w 时启用警告之前的代码
【发布时间】:2014-11-27 14:00:10
【问题描述】:

我从 perl::critic 得到 Code before warnings are enabled,即使我在 shebang 中指定了 -w

#!/usr/bin/perl -w

我真的不想遍历并替换所有实例。有什么我可以做的。此外,我确实希望 perl::critic 确保所有 perl 都启用了警告。

【问题讨论】:

  • perl -i~ -pe 's|#!/usr/bin/perl\K -w|\n\nuse warnings;|' *pl

标签: perl perl-critic


【解决方案1】:

你说perlcritic 没有做你想做的事,而是你想让它做你想做的事。因此,您需要修改perlcritic,或者更具体地说,修改Perl:: Critic:: Policy:: TestingAndDebugging:: RequireUseWarnings。让您的更改被接受应该没有问题,因为缺少 shebang 解析在文档中被列为错误。


编辑文件可能更简单。机械地这样做是非常微不足道的。假设你已经使用use strict;

find -type f \( -name '*.pl' -o -name '*.pm' \) ! -name '*~' -exec \
   perl -i~ -0777pe's/^(\s*)use strict\b.*\n\K/${1}use warnings;\n/mg' {} +

【讨论】:

    猜你喜欢
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 2013-04-27
    • 2022-10-05
    • 1970-01-01
    • 2014-07-18
    • 2014-10-27
    • 1970-01-01
    相关资源
    最近更新 更多