logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Perl::Critic::Policy::Compatibility::ProhibitUnixDevNull - don't use explicit /dev/null

Description

       This policy is part of the "Perl::Critic::Pulp" add-on.  It ask you to not to use filename

           /dev/null

       explicitly, but instead "File::Spec->devnull()" for maximum portability across operating systems.

       This policy is under the "maintenance" theme (see "POLICY THEMES" in Perl::Critic) on the basis that even
       if you're on a Unix system now you never know where your code might travel in the future.

       "devnull()" is new in "File::Spec" version 0.8, so you should require that version (it's included in Perl
       5.6.0 and up).

       The checks for /dev/null are unsophisticated.  A violation is reported for any string "/dev/null",
       possibly with an "open" style mode part, and any "qw" containing "/dev/null".

           open my $fh, '< /dev/null';                    # bad
           do_something ("/dev/null");                    # bad
           foreach my $file (qw(/dev/null /etc/passwd))   # bad

       String comparisons are allowed because they're not uses of /dev/null as such but likely some sort of
       cross-platform check.

           if ($f eq '/dev/null') { ... }                 # ok
           return ($f ne '>/dev/null');                   # ok

       /dev/null as just part of a string is allowed, including things like backticks and "system".

           print "Flames to /dev/null please\n"           # ok
           system ('rmdir /foo/bar >/dev/null 2>&1');     # ok
           $hi = `echo hi </dev/null`;                    # ok

       Whether /dev/null is a good idea in such command strings depends what sort of shell you reach with that
       command and how much of Unix it might emulate on a non-Unix system.

   Disabling
       If you only ever use a system with /dev/null or if everything else you write is hopelessly wedded to Unix
       anyway then you can disable "ProhibitUnixDevNull" from your .perlcriticrc in the usual way (see
       "CONFIGURATION" in Perl::Critic),

           [-Compatibility::ProhibitUnixDevNull]

Home Page

Name

       Perl::Critic::Policy::Compatibility::ProhibitUnixDevNull - don't use explicit /dev/null

See Also

       Perl::Critic::Pulp, Perl::Critic, File::Spec

See Also