[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: dpkg perl critic code cleanup



Guillem Jover <guillem@debian.org> writes:

> I took notice again, after having done so in the past and long forgotten
> it, of the perlcritic analyzer from Russ' recent write ups, and have been
> going through the dpkg perl code, finding many things to fix or improve,
> but not everything it reports always seems sensible.

> I've been queueing those in my local tree, and will be pushing them once
> I reopen master for jessie, not too long from now.

> In any case, thanks Russ, wonderful rediscovery! :)

Oh, glad it was helpful!  In case it's of interest, attached are my
current perlcriticrc and perltidyrc files.  (perltidy is... awkward.
There are places where how it formats the code is clearly suboptimal, at
least to me, and despite initial appearances it doesn't have enough dials.
But I'm sticking with it so far.)

-- 
Russ Allbery (rra@debian.org)               <http://www.eyrie.org/~eagle/>

# -*- conf -*-
#
# Default configuration for perlcritic.  Be sure to copy this into the source
# for packages that run perlcritic tests automatically during the build for
# reproducible test results.
#
# This file has been updated to match perlcritic 1.118.
#
# The canonical version of this file is maintained in the rra-c-util package,
# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2011, 2012
#     The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

severity = 1
verbose  = %f:%l:%c: [%p] %m (%e, Severity: %s)\n

# Pod::Man and Pod::Text fixed this bug years ago.  I know, I maintain them.
[-Documentation::RequirePodLinksIncludeText]

# The POD sections Perl::Critic wants are incompatible with the POD template
# from perlpodstyle, which is what I use for my POD documentation.
[-Documentation::RequirePodSections]

# The default of 9 is too small and forces weird code contortions.
[InputOutput::RequireBriefOpen]
lines = 15

# This is correct 80% of the time, but it isn't correct for a lot of scripts
# inside packages, where maintaining $VERSION isn't worth the effort.
# Unfortunately, there's no way to override it, so it gets turned off
# globally.
[-Modules::RequireVersionVar]

# The default is a bit too aggressive.  I was unable to write an Apache access
# log regex with each major expression broken into a separate variable and fit
# the default limit of 40 characters.  (It's not clear how the variable names
# are counted, but they don't seem to be by number of characters in the
# variable reference.)
[RegularExpressions::ProhibitComplexRegexes]
max_characters = 80

# Nice idea, but it *utterly* confuses cperl-mode when used with braces, so
# it's more trouble than it's worth.
[-RegularExpressions::ProhibitEscapedMetacharacters]

# I generally don't want to require Readonly as a prerequisite for all my Perl
# modules.
[-ValuesAndExpressions::ProhibitConstantPragma]

# 100 is used for calculating percentages.  Making it a constant is just
# confusing.
#
# Literal 0777 means to use the umask for permissions when creating files.
# Using a constant for this just makes it more obscure.  0777 is 511 in
# decimal.
[ValuesAndExpressions::ProhibitMagicNumbers]
allowed_types  = Octal
allowed_values = 0 1 2 100 511

# Increase this to six digits so that I'm not told to add underscores to
# port numbers (which is just silly).
[ValuesAndExpressions::RequireNumberSeparators]
min_value = 100000

# Text::Wrap has a broken interface that requires use of package variables.
[Variables::ProhibitPackageVars]
add_packages = Text::Wrap

# use English was one of the worst ideas in the history of Perl.  It makes the
# code slightly more readable for amateurs at the cost of confusing
# experienced Perl programmers and sending people in futile quests for where
# these magical global variables are defined.
[-Variables::ProhibitPunctuationVars]
# -*- conf -*-
#
# Default options for perltidy for proper Perl code reformatting.

-bbao           # put line breaks before any operator
-ce             # cuddle braces around else
-l=79           # usually use 78, but don't want 79-long lines reformatted
-pt=2           # don't add extra whitespace around parentheses
-sbt=2          # ...or square brackets
-sfs            # no space before semicolon in for (not that I use this form)

Reply to: