1 # best viewed via "perldoc TODO.pod"
5 =for stopwords LHS RHS REFACTORINGS FH SVN stopwords
9 Perl::Critic::TODO - Things for Perl::Critic developers to do
14 #######################################################################
15 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/TODO.pod $
16 # $Date: 2008-07-03 09:36:05 -0500 (Thu, 03 Jul 2008) $
17 # $Author: clonezone $
19 #######################################################################
24 Perl-Critic-More is a separate distribution for less-widely-accepted
25 policies. It contains its own TODO.pod.
32 =item * Report Safari sections in addition to book page numbers.
35 =item * Add --files-with-violations/-l and --files-without-violations/-L options to F<perlcritic>.
37 Just print out file names. I could have used this at work when combined with
40 gvim `perlcritic --single-policy QuotedWordLists -l`
43 =item * Add a file Behavior.
46 =item * Allow values of (at least) string-list Parameters to be specified in a file.
48 For the benefit of PodSpelling, etc.
51 =item * Enhance string-list Behavior to allow specification of delimiters.
53 For things like RequirePodSections.
56 =item * Add queries to --list option to F<perlcritic>.
58 List Policies based upon severity, theme, and (what I want this second)
61 =item * Add --prohibit-unrestricted-no-critic option to F<perlcritic>.
63 Requires C<## no critic> to take an argument:
65 ## no critic (SomePolicyPattern) # ok
68 Can't be done as a regular Policy because any line that violated it would disable it.
71 =item * Support for C<#line 123 "filename"> directives.
73 For code generators and template languages that allow inline Perl code.
75 Yes, somebody has an in-house templating system where they've written a custom
76 test module that extracts the perl code from a template and critiques it.
78 Actually, this would be useful for programs: Module::Build "fixes" shebang
79 lines so that there's the bit about invoking perl if the program is attempted
80 to be run by a Bourne shell, which throws the line numbers off when using
81 Test::P::C on the contents of a C<blib> directory.
84 =item * Enhance statistics.
95 =item * Detect 5.10 source and enable stuff for that.
97 For example, treat C<say> as equivalent to C<print>.
100 =item * Support a means of failing if a Policy isn't installed.
102 For example, the self compliance test now depends upon a Policy in the More
105 Something like using a "+" sign in front of the Policy name in its
106 configuration block, analogous to the "-" sign used for disabling a policy,
107 e.g. "C<[+Example::Policy]>".
113 =head1 BUGS/LIMITATIONS
117 =item * NamingConventions::ProhibitAmbiguousNames
119 Don't allow compound names with forbidden words, like "last_record".
120 Allow forbidden words in RHS of variable declarations
122 Also, we should make it easeir to add (or delete) words from the
126 =item * Subroutines::ProtectPrivateSubs
128 Doesn't forbid C<< $pkg->_foo() >> because it can't tell the
129 difference between that and C<< $self->_foo() >>
132 =item * ErrorHandling::RequireCarping
134 This should not complain about using C<warn> or C<die> if it's not in a
135 function, or if it's in main::.
137 Also, should allow C<die> when it is obvious that the "message" is a reference.
140 =item * RegularExpressions::ProhibitCaptureWithoutTest
142 Allow this construct:
145 next unless /(....)/;
151 Right now, P::C thinks that the C<$1> isn't legal to use because it's
152 "outside" of the match. The thing is, we can only get to the C<if>
153 if the regex matched.
154 while ( $str =~ /(expression)/ )
157 =item * CodeLayout::ProhibitParensWithBuiltins
159 Some builtin functions (particularly those that take a variable number of
160 scalar arguments) should probably get parentheses. This policy should be
161 enhanced to allow the user to specify a list of builtins that are expempt
165 =item * ValuesAndExpressions::ProhibitCommaSeparatedStatements
167 Needs to check for C<scalar( something, something )>.
170 =item * Variables::ProhibitPunctuationVars
172 Needs to look inside strings. RT #35970.
175 =item * TestingAndDebugging::RequireUseWarnings
177 Check for -w on the shbang line.
180 =item * Change formatting in Violation to eliminate double periods.
186 =head1 OTHER PBP POLICIES THAT SEEM FEASIBLE TO IMPLEMENT
190 =item * Modules::RequireUseVersion [405-406]
192 =item * Modules::RequireThreePartVersion [405-406]
194 =item * RegularExpressions::RequireDotMatchAnything [240-241]
199 =head1 NON-PBP POLICIES WANTED
203 =item * Documentation::RequireModuleAbstract
205 Require a C<=head1 NAME> POD section with content that matches
206 C<\A \s* [\w:]+ \s+ - \s+ \S>. The single hyphen is the important bit. Also,
207 must be a single line.
209 =item * Expressions::RequireFatCommasInHashConstructors
211 =item * ErrorHandling::RequireLocalizingEvalErrorInDESTROY
213 Prevent C<$@> from being cleared unexpectedly by DESTROY methods.
218 die "Died in Foo::DESTROY()";
224 my $foo = Foo->new();
228 print $@; # "Died in Foo::DESTROY()", not "Died in eval.".
230 See L<http://use.perl.org/~Ovid/journal/36767>.
232 =item * Expressions::ProhibitDecimalWithBitwiseOperator
234 =item * Expressions::ProhibitStringsWithBitwiseOperator
237 =item * InputOutput::ProhibitMagicDiamond
239 Steal the idea from L<B::Lint>.
242 =item * TBD::AllProgramsNeedShebangs
244 Anything that is a program should have a shebang line. This includes .t files.
247 =item * BuiltInFunctions::RequireConstantSprintfFormat
250 =item * BuiltInFunctions::RequireConstantUnpackFormat
252 L<http://diotalevi.isa-geek.net/~josh/yapc-lint/slides/slide5.html>
255 =item * Miscellanea::ProhibitObnoxiousComments
257 Forbid excessive hash marks e.g. "#### This is a loud comment ####".
258 Make the obnoxious pattern configurable
261 =item * ValuesAndExpressions::RequireNotOperator
263 Require the use of "not" instead of "!", except when this would contradict
264 ProhibitMixedBooleanOperators. This may be better suited for
268 =item * Modules::RequireExplicitImporting
270 Require every C<use> statement to have an explicit import list. You could
271 still get around this by calling C<import> directly.
274 =item * Modules::ForbidImporting
276 Require every C<use> to have an explicitly empty import list. This is for
277 folks who like to see fully-qualified function names. Should probably provide
278 a list of exempt modules (like FindBin);
281 =item * ControlStructures::ProhibitIncludeViaDo
283 Forbid C<do "foo.pl">. Not sure about this policy name.
286 =item * Variables::ProhibitUseVars
288 Disallow C<use vars qw(...)> and require C<our $foo> instead. This
289 contradicts Miscellanea::Prohibit5006isms. Maybe verify C<use 5.6>
290 before applying this policy. Low severity.
293 =item * VariablesAndExpressions::ProhibitQuotedHashKeys
295 Forbid quotes around hash keys, unless they are really needed. This
296 is against what Damian says. Suggested by Adam Kennedy. Low
300 =item * CodeLayout::ProhibitFunctionalNew
302 Good: C<< Foo::Bar->new >>, Bad: C<< new Foo::Bar >>
305 =item * RegularExpressions::ProhibitSWSWSW
307 Require C<split> instead of C<m/\s*\w*\s*\w*\s*/>. From MJD's Red Flags.
310 =item * VariablesAndExpressions::RequireConstantVersion (low severity)
313 =item * VariablesAndExpressions::ProhibitComplexVersion (medium severity)
315 L<http://rt.cpan.org/Ticket/Display.html?id=20439>
318 =item * Documentation::RequireSynopsis
321 =item * Documentation::RequireLicense
323 These are simplified versions of Documentation::RequirePodSections.
326 =item * Documentation::RequireValidSynopsis
328 The Synopsis section must be all indented and must be syntactically valid Perl
329 (as validated by PPI).
332 =item * Documentation::ProhibitEmptySections
334 Any C<=headN> and C<=over> sections must not be empty. This helps catch
335 boilerplate (althought Test::Pod should catch empty C<=over> blocks).
337 On the other hand, C<=item ...> sections can be empty, since the item label is
341 =item * Miscellaneous::ProhibitBoilerplate
343 Complain about copy-and-paste code or docs from h2xs, Module::Starter::*,
346 Here's a non-PPI implementation:
347 L<http://search.cpan.org/src/JJORE/Carp-Clan-5.8/t/04boilerplate.t>
350 =item * BuiltinFunctions::ProhibitExtraneousScalarCall
352 Recommend that C<if (scalar @array)> be rewritten as C<if (@array)>.
355 =item * RegularExpressions::ProhibitMixedDelimiters
360 =item * RegularExpressions::ProhibitScalarAsRegexp
362 Ban naked srtings as regexps, like:
364 print 1 if $str =~ $regexp;
366 Instead, it should be:
368 print 1 if $str =~ m/$regexp/;
372 print 1 if $str =~ m/$regexp/xms;
375 =item * ValuesAndExpressions::RequireInterpolatedStringyEval
377 Ensure that the argument to a stringy eval is not a constant string. That's
378 just wasteful. Real world examples include:
380 eval 'use Optional::Module';
382 which is better written as
384 eval { require Optional::Module; Optional::Module->import };
386 for performance gains and compile-time syntax checking.
389 =item * RegularExpressions::ProhibitUnnecessaryEscapes
391 Complain if user puts a backslash escape in front of non-special characters. For example:
395 Make exceptions for C<\">, C<\'> and C<\`> since those are often inserted to
396 workaround bugs in syntax highlighting.
398 Note that this is different inside character classes, where only C<^>, C<]>
399 and C<-> need to be escaped, I think. Caret only needs to be escaped at the
400 beginning, and dash does NOT need to be escaped at the beginning and end. See
404 =item * Steal ideas from L<Dunce::Files>.
406 Can someone expand this entry, please?
408 =item * ControlStructures::ProhibitAssigmentInConditional
410 =item * ValuesAndExpressions::RequireConstantBeforeEquals
412 =item * ValuesAndExpressions::RequireConstantBeforeOperator
414 L<http://use.perl.org/~stu42j/journal/36412>
416 Just about everyone has been bitten by C<if ($x = 10) { ... }> when they meant
417 to use C<==>. A safer style is C<10 == $x> because omitting the second C<=>
418 yields a noisy compile-time failure instead of silent runtime error.
420 ProhibitAssigmentInConditional complains if the condition of a while, until,
421 if or unless is solely an assignment. If it's anything more complex (like
422 C<if (($x=10)){}> or C<while ($x=$y=$z){}>), there is no warning.
424 RequireConstantBeforeEquals complains if the left side of an C<==> is a
425 variable while the right side is a constant.
427 RequireConstantBeforeOperator complains if the left side of any comparison
428 operator (C<==>, C<eq>, C<<>, etc) is a variable while the right side is a
432 =item * InputOutput::ProhibitUTF8IOLayer
434 http://www.perlfoundation.org/perl5/index.cgi?the_utf8_perlio_layer
436 =item * BuiltinFunctions::ProhibitExit(?:InModules)?
438 Forbid C<exit()> in files that lack a shebang. Inspired by
439 L<http://use.perl.org/~Ovid/journal/36746> and an analgous checker in
445 =head1 REFACTORINGS and ENHANCEMENTS
449 =item * Create constants for the PPI location array elements.
452 =item * MOVE THE LINE-DISABLING INTO P::C::Document
454 All the code that deals with finding all the '##no critic' comments and noting
455 which policies are disabled at each line seems like it would be better placed
456 in Perl::Critic::Document. P::C::Document could then provide methods to
457 indicate if a policy is disabled at a particular line. So the basic algorithm
458 in Perl::Critic might look something like this:
460 foreach $element (@PPI_ELEMENTS) {
461 foreach $policy (@POLICIES) {
462 $line = $element->location->[0];
463 next if $doc->policy_is_disabled_at_line( $policy, $line );
464 push @violations, $policy->violates( $elem, $doc );
469 =item * Some means of detecting "runnaway" C<##no critic>
471 Elliot was talking to a couple of users at ETech and one of their major
472 concerns was that they were using C<##no critic> and forgetting to do a
473 C<##use critic> after the problematic section. Perhaps an option to
474 F<perlcritic> to scan for such things is in order.
477 =item * Change API to use named parameters
479 Most of the methods on the public classes use named parameters for passing
480 arguments. I'd like to extend that pattern to include all object-methods.
481 Static methods can still use positional parameters.
484 =item * Enhance P::C::critique() to accept files, directories, or code strings
486 Just like F<bin/perlcritic> does now.
489 =item * Add C<-cache> flag to F<bin/perlcritic>
491 If enabled, this turns on L<PPI::Cache>:
494 my $cache_path = "/tmp/test-perl-critic-cache-$ENV{USER}";
495 mkdir $cache_path, oct 700 if (! -d $cache_path);
496 PPI::Cache->import(path => $cache_path);
498 This cachedir should perhaps include the PPI version number! At least
499 until PPI incorporates its own version number in the cache.
501 (see F<t/40_criticize.t> for a more robust implementation)
504 =item * Use hash-lookup instead of C<List::MoreUtils::any> function.
506 In several places, Perl::Critic uses C<List::MoreUtils::any> to see if
507 a string is a member of a list. Instead, I suggest using a named
508 subroutine that does a hash-lookup like this:
510 my %logical_ops = hashify( qw( ! || && ||= &&= and or not ) );
511 sub is_logical_op { return exists $logical_ops{ $_[0] }; }
516 =item * Allow color output to work through a pipe.
518 http://rt.cpan.org/Ticket/Display.html?id=30140
520 F<ack> now supports this.
527 We're waiting on the following bugs to get fixed in a CPAN release of PPI:
532 =item PPI::Token::descendant_of()
534 Exists in svn. Replace _descendant_of() in RequireCheckingReturnValueOfEval
535 with that, once it is released, because it's faster and native.
539 PPI does not preserve newlines. That makes
540 CodeLayout::RequireConsistentNewlines impossible to implement under PPI. For
541 now, it's implemented by pulling the source out of the file and skipping PPI.
543 It's unlikely that PPI will support mixde newlines anytime soon.
548 ValuesAndExpressions::ProhibitMismatchedOperators has two workarounds
549 for PPI bugs with parsing operators. Many of these bugs have been
550 fixed in PPI, so it would be good to check if those workarounds are
556 Not strictly a bug -- the PPI Regexp classes have a dearth of accessor methods
557 as of v1.118, meaning that we have to do messy digging into internals. I
558 wrote Perl::Critic:Utils::PPIRegexp to encapsulate this messiness, but it
559 would be nicer to have an official interface in PPI.
566 ##############################################################################
569 # cperl-indent-level: 4
571 # indent-tabs-mode: nil
572 # c-indentation-style: bsd
574 # ex: set ts=8 sts=4 sw=4 tw=78 ft=pod expandtab shiftround :