GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Perl::Critic::Policy::CodeLayout::ProhibitIfIfSameLine(3) User Contributed Perl Documentation Perl::Critic::Policy::CodeLayout::ProhibitIfIfSameLine(3)

Perl::Critic::Policy::CodeLayout::ProhibitIfIfSameLine - don't put if after if on same line

This policy is part of the "Perl::Critic::Pulp" add-on. It asks you to not to write an "if" statement on the same line as a preceding "if".

    if ($x) {
      ...
    } if ($y) {       # bad
      ...
    }

    if ($x) {
      ...
    } elsif ($y) {    # was "elsif" intended ?
      ...
    }

The idea is that an "if" in the layout of an "elsif" may be either a mistake or will be confusing to a human reader. On that basis this policy is under the "bugs" theme and medium severity (see "POLICY THEMES" in Perl::Critic).

An "unless...if" is treated the same. Perl allows "unless ... elsif" and so the same potential confusion with an "elsif" layout arises.

    unless ($x) {
      ...
    } if ($y) {       # bad
      ...
    }

    unless ($x) {
      ...
    } elsif ($y) {    # maybe meant to be "elsif" like this ?
      ...
    }

Whether "unless ... elsif" is a good idea at all is another matter. Sometimes it suits a combination of conditions.

This policy only applies to a statement followed by a statement. An "if" as a statement modifier is not affected. It's usual to put that on the same line as the statement it modifies.

    do {
      ...
    } if ($x);        # ok, statement modifier

Two "if" statements written on the same line will trigger the policy.

    if(1){one;}   if(2){two;}      # bad

Perhaps there could be an exception or option when both statements are entirely on the one line, or some such, for code which is trying to be compact.

As always if you don't care about this then you can disable "ProhibitIfIfSameLine" from your .perlcriticrc (see "CONFIGURATION" in Perl::Critic),

    [-CodeLayout::ProhibitIfIfSameLine]

Perl::Critic::Pulp, Perl::Critic

Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse, Perl::Critic::Policy::ControlStructures::ProhibitUnlessBlocks

<http://user42.tuxfamily.org/perl-critic-pulp/index.html>

Copyright 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde

Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.

2021-02-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.