Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

perlcritic and heredocs

by redtux (Sexton)
on Apr 15, 2020 at 11:17 UTC ( [id://11115557]=perlquestion: print w/replies, xml ) Need Help??

redtux has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks

I am running perlcritic against a perl app (perl, gtk, DBD::Pg so fairly complex)

Is there any way to tell perlcritic to IGNORE heredocs?.

I use heredocs exclusively for formatting sql stings to pass to the db server. However perlcritic complains within hereocs about at least

ProhibitMismatchedOperators (which are valid in sql strings, eg: =) ProhibitImplicitNewlines ProhibitHardTabs

## no critic doesn't assist as the only way to get it to work is globally, which removes the check from code that I want to check

thanks in advance

Replies are listed 'Best First'.
Re: perlcritic and heredocs
by Corion (Patriarch) on Apr 15, 2020 at 11:22 UTC

    Can you post a short example of source code (and the corresponding Perl::Critic configuration and invocation) to demonstrate the problem?

    I don't use Perl::Critic, but I imagine that it would understand what heredocs are...

      (my $lintags_inssql = <<~'SQLSTR') =~s/(?:^\t*|\n)/ /gmx; INSERT INTO linktags (filesrc, metadir, tagname, tagvalue, symlink +, filesref, dirtype,status) SELECT a.filesrc, a.metadir, tagname, tagvalue, ## This is line 4486 ## metadir||'/'||tagname||$1||tagvalue||$1 +||filenameparts[1]||'_'||array_to_string(linka[linkano-2:linkano-1] ## line 4486 ## ,'_')||filenameparts[2] symlink ,filesref,dirtype,'new' FROM (SELECT DISTINCT l.filesrc, c.metadir||'/0_meta' metadir, tag +name, tagvalue ,string_to_array(filesrc,$1)linka, cardinality(string_to_array(filesrc,$1)) linkano, regexp_matches(filesrc,'.*/(.*)(\..*)') filenameparts, filesref, dirtype FROM public.linktags l JOIN chkmeta c ON l.filesrc LIKE c.metadir||'%' WHERE (st +atus='new') ) a ON CONFLICT(symlink) DO UPDATE SET dirtype=EXCLUDED.dirtype SQLSTR

      perlcritic error

      Hard tabs used at line 4486, column 64. See page 20 of PBP. (Severity: 3)
      Literal line breaks in a string at line 4486, column 64. See pages 60,61 of PBP.
      (Severity: 3)

      perlcritic cmd

      sudo perlcritic --force -1 /usr/bin/use_videotagspg|grep -i -B2 'hard tabs'

      .perlcriticrc

      [TestingAndDebugging::ProhibitNoStrict] allow = refs
        I downloaded the code, removed the ## comments, included the standard boilerplate for scripts (shebang, strictures, warnings) and run freshly installed perlcritic on it:
        $ perlcritic --force -1 1.pl Code is not tidy at line 1, column 1. See page 33 of PBP. (Severity: + 1) No package-scoped "$VERSION" variable found at line 1, column 1. See +page 404 of PBP. (Severity: 2) Regular expression without "/s" flag at line 6, column 38. See pages +240,241 of PBP. (Severity: 2)

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Like choroba, I also can't reproduce those two policy warnings here either, with versions 1.134 and the latest 1.138. What version of Perl::Critic do you have installed? (perlcritic --version) And do you perhaps have any other Perl::Critic::* add-ons installed?

Re: perlcritic and heredocs
by haukex (Archbishop) on Apr 15, 2020 at 12:16 UTC

    I agree with Corion that you'll need to show the code that produces these issues - I haven't been able to reproduce ProhibitMismatchedOperators at all yet, I've only been able to reproduce ProhibitHardTabs inside q{}'s, not heredocs, and ProhibitImplicitNewlines explicitly states to use heredocs instead of multiline quoted strings.

    In other words, this produces ProhibitHardTabs and ProhibitImplicitNewlines policy warnings:

    my $foo = q{ if ($a == 'bar') { } SELECT foo FROM bar WHERE quz==3; };

    while this doesn't:

    my $foo = <<'END'; if ($a == 'bar') { } SELECT foo FROM bar WHERE quz==3; END

    Are you sure you're not using multi-line quoted strings instead of heredocs...?

      Just checked and there was a fix with indented heredocs post 1.32 (1.34)

      This seems to have solved the issue

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11115557]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-04-19 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found