在 Perl 中应用编码标准是否有任何好的自动化框架? [英] Are there any good automated frameworks for applying coding standards in Perl?

查看:18
本文介绍了在 Perl 中应用编码标准是否有任何好的自动化框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的是 Perl::Critic

到目前为止,我的谷歌搜索多次尝试都没有结果.:-(

And my googling has resulted in no results on multiple attempts so far. :-(

这里有人有什么建议吗?

Does anyone have any recommendations here?

任何根据我们的编码标准配置 Perl::Critic 并在代码库上运行它的资源将不胜感激.

Any resources to configure Perl::Critic as per our coding standards and run it on code base would be appreciated.

推荐答案

在设置profile方面,你有没有尝试过perlcritic --profile-proto?这会将您安装的所有策略及其所有选项以及两者的描述(包括它们的默认值)以 perlcriticrc 格式发送到标准输出.保存并编辑以匹配您想要的内容.每当您升级 Perl::Critic 时,您可能希望再次运行此命令并与当前的 perlcriticrc 进行比较,以便您可以查看对现有策略的任何更改并选择任何新策略.

In terms of setting up a profile, have you tried perlcritic --profile-proto? This will emit to stdout all of your installed policies with all their options with descriptions of both, including their default values, in perlcriticrc format. Save and edit to match what you want. Whenever you upgrade Perl::Critic, you may want to run this command again and do a diff with your current perlcriticrc so you can see any changes to existing policies and pick up any new ones.

在定期运行 perlcritic 方面,设置一个 Test::Perl::Critic 与其他测试一起进行测试.这对新代码很有用.

In terms of running perlcritic regularly, set up a Test::Perl::Critic test along with the rest of your tests. This is good for new code.

对于您现有的代码,请使用 Test::Perl::Critic::改为渐进式.T::P::C::Progressive 在你第一次运行时会成功,但会保存违规次数;此后,如果任何计数上升,T::P::C::Progressive 将抱怨.需要注意的一件事是当您恢复源代码控制系统中的更改时.(您正在使用一个,不是吗?)假设我签入更改并运行测试,并且我的更改减少了 P::C 违规的数量.后来,事实证明我的更改很糟糕,所以我恢复到旧代码.由于计数减少,T::P::C::Progressive 测试将失败.此时最简单的做法是删除历史文件(默认位置 t/.perlcritic-history)并再次运行.它应该会重现您的旧计数,并且您可以编写新内容以再次降低它们.

For your existing code, use Test::Perl::Critic::Progressive instead. T::P::C::Progressive will succeed the first time you run it, but will save counts on the number of violations; thereafter, T::P::C::Progressive will complain if any of the counts go up. One thing to look out for is when you revert changes in your source control system. (You are using one, aren't you?) Say I check in a change and run tests and my changes reduce the number of P::C violations. Later, it turns out my change was bad, so I revert to the old code. The T::P::C::Progressive test will fail due to the reduced counts. The easiest thing to do at this point is to just delete the history file (default location t/.perlcritic-history) and run again. It should reproduce your old counts and you can write new stuff to bring them down again.

Perl::Critic 附带了许多策略,但也有许多策略的附加分布.看看 Task::Perl::CriticTask::Perl::Critic::IncludingOptionalDependencies.

Perl::Critic has a lot of policies that ship with it, but there are a bunch of add-on distributions of policies. Have a look at Task::Perl::Critic and Task::Perl::Critic::IncludingOptionalDependencies.

您不需要让一个 perlcriticrc 处理您的所有代码.为要测试的每组文件创建单独的 perlcriticrc 文件,然后为每个文件创建一个单独的测试.例如,在 http://perlcritic.tigris.org/source/browse/perlcritic/trunk/Perl-Critic/xt/author/.运行作者测试时,有一个测试运行 P::C 的所有代码,第二个测试仅在策略上应用附加规则,第三个测试批评 P::C 的测试.

You don't need to have a single perlcriticrc handle all your code. Create separate perlcriticrc files for each set of files you want to test and then a separate test that points to each one. For an example, have a look at the author tests for P::C itself at http://perlcritic.tigris.org/source/browse/perlcritic/trunk/Perl-Critic/xt/author/. When author tests are run, there's a test that runs over all the code of P::C, a second test that applies additional rules just on the policies, and a third one that criticizes P::C's tests.

我个人认为每个人都应该在残酷"的严重级别上运行,但淘汰他们不同意的政策.Perl::Critic 并不完全自律;即使是 P::C 开发人员也不同意康威所说的一切.查看 Perl::Critic 本身使用的 perlcriticrc 文件,并在 Perl::Critic 代码中搜索## nocritic"的实例;我现在数了 143 个.

I personally think that everyone should run at the "brutal" severity level, but knock out the policies that they don't agree with. Perl::Critic isn't entirely self compliant; even the P::C developers don't agree with everything Conway says. Look at the perlcriticrc files used on Perl::Critic itself and search the Perl::Critic code for instances of "## no critic"; I count 143 at present.

(是的,我是 Perl::Critic 开发人员之一.)

(Yes, I'm one of the Perl::Critic developers.)

这篇关于在 Perl 中应用编码标准是否有任何好的自动化框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆