Perlcritic 配置 - 查找生成错误的策略的名称?
我正在尝试开始使用 Perlcritic,并且正在努力完善我自己的配置,忽略所有我不同意或认为不适合我的规则。
我知道我可以使用 .perlcrirticrc 文件来执行此操作,并且我可以使用该文件中的排除指令来排除我不同意的策略,但要做到这一点,我需要找到该策略的名称导致了我想抑制的错误。
我在任何地方都找不到 CPAN 文档中的策略列表,并且错误消息没有给出正在生成的策略的名称,因此我完全不知道应该如何生成我的策略排除列表。
如果有人可以向我指出一种将错误映射到策略的方法,或者只是向我指出核心中的策略列表,我将不胜感激!
I'm trying to get started using Perlcritic, and I'm working on refining my own configuration, leaving out all the rules I don't agree with or don't think are appropriate for me.
I know that I can do this using a .perlcrirticrc file, and that I can use the exclude directive in that file to exclude the policies I don't agree with, but to do that, I need to find the name of the policy that is causing the error I want to suppress.
I can't find a list of the policies in the documentation on CPAN anywhere, and the error messages do not give the name of the policy that is generating, so I'm at a total loss as to how I am supposed to generate my exclude list.
If anyone could point me to a way of mapping errors to policies, or even just point me to a list of the policies in core I'd be most grateful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
高度不直观的 --verbose 标志就是你想要的,根据 How do I make Perl::Critic 在其输出中显示违规策略?
The highly-unintuitive --verbose flag is what you want, according to How do I make Perl::Critic show the offending policy in its output?
在我工作的地方,我们有一个项目 perlcriticrc 文件,其中包含行
[%p]
在命令行上显示类似于--verbose 8
的策略。Where I work we have a project perlcriticrc file that contains the line
The
[%p]
shows the policy similar to--verbose 8
on the command line.也许
Perl::Critic::PolicySummary
。Perhaps
Perl::Critic::PolicySummary
.verbose
设置为 9 将显示策略名称:generatestats
脚本可以在 CPAN 通过 MANIFEST 链接显示策略名称的摘要。verbose
setting of 9 will show you the policy names:The
generatestats
script which can be found on CPAN via the MANIFEST link shows a summary of policy names.--exclude 和 --include 选项最适合在命令行中对策略集进行临时调整。要定义默认策略集,您应该在 .perlcriticrc 文件中单独启用/禁用它们。实际上非常简单:
现在 ~/.perlcriticrc 将包含所有策略及其默认配置参数,以及每个策略的作用的简要描述。通过在每个策略名称前添加“-”来禁用您不喜欢的策略,如下所示:
默认情况下,Perl::Critic 可以从您尚未明确禁用的任何策略中进行选择。因此,如果您只打算使用少数策略,并且不想遍历并禁用 97 个不同的策略,那么请考虑使用 --only 选项,该选项告诉 Perl::Critic 仅从以下策略中进行选择:您在 .perlcriticrc 中明确启用。
请记住,.perlcriticrc 文件仅定义 Perl::Critic 可以选择的默认策略。您始终可以通过覆盖命令行中的 --severity、--theme 或 --exclude 选项来选择这些策略的子集。
正如其他人指出的那样,--verbose 选项允许您配置每条消息显示的信息(包括策略名称等)。例如,如果您想查看“POLICY_NAME:LINE 上的 MESSAGE”,您可以执行以下操作:
The --exclude and --include options are best used for ad-hoc tweaking of your Policy set at the command line. To define your default set of Policies, you should individually enable/disable them in your .perlcriticrc file. It is actually quite easy:
Now ~/.perlcriticrc will contain all the Policies and their default configuration parameters, and a brief description of what each Policy does. Disable the ones you don't like by putting a '-' in front of the name of each policy, like this:
By default, Perl::Critic can choose from any Policy that you haven't explicitly disabled. So if you're only going to use a handful of Policies and you don't want to go through and disable 97 different Policies, then consider using the --only option, which tells Perl::Critic to only choose from the Policies that you explicitly enabled in your .perlcriticrc.
Remember, the .perlcriticrc file only defines the default Policies that Perl::Critic can choose from. You can always select a subset of those Policies by overriding the --severity, --theme, or --exclude options at the command line.
As others have pointed out, the --verbose option allows you to configure what information is displayed with each message (including the policy name, among other things). For example, if you wanted to see "POLICY_NAME: MESSAGE at LINE", you would do this:
询问 P::C::Policy 命名空间中模块的 CPAN 索引。这包括主要 P::C 发行版中未找到的策略。
Ask the CPAN index for modules in the P::C::Policy namespace. This includes policies not found in the main P::C distro.