Grinnz / Perl-Critic-Community

Perl::Critic::Community - Community-inspired Perl::Critic policies
https://metacpan.org/pod/Perl::Critic::Community
Other
8 stars 10 forks source link

Freenode::BarewordFileHandles dies on `open(CHECK, '/foo');` #33

Open petdance opened 5 years ago

petdance commented 5 years ago

Prompted by https://www.reddit.com/r/perl/comments/c4lhaq/and_most_damning_of_all_the_resulting_code_was/erx5hno/

The punchline is, of course, the 100 kB file keeper in http://www.ibiblio.org/pub/Linux/search/keeper-1.54.tar.gz. The code is so eyewateringly bad, it crashes Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles. esr made a career out of bashing Perl, always blaming the language, never his own lack of skill.

$ cat minimal
#!/usr/bin/perl

open(CHECK, '/foo');
$ perlcritic minimal -s InputOutput::ProhibitBarewordFileHandles
Fatal error while critiquing "minimal": Not an ARRAY reference at /var/perl5.20.3/lib/site_perl/5.20.3/Perl/Critic/Policy/InputOutput/ProhibitBarewordFileHandles.pm line 35.

$ perlcritic minimal -s Freenode::BarewordFileHandles
Fatal error while critiquing "minimal": Not an ARRAY reference at /var/perl5.20.3/lib/site_perl/5.20.3/Perl/Critic/Policy/Freenode/BarewordFilehandles.pm line 47.

See also https://github.com/Perl-Critic/Perl-Critic/issues/878

Grinnz commented 5 years ago
> ppi_dumper minimal 
PPI::Document
  PPI::Token::Comment   '#!/usr/bin/perl\n'
  PPI::Token::Whitespace        '\n'
  PPI::Statement
    PPI::Token::Word    'open'
    PPI::Structure::List        ( ... )
      PPI::Statement::Scheduled
        PPI::Token::Word        'CHECK'
        PPI::Token::Operator    ','
        PPI::Token::Whitespace          ' '
        PPI::Token::Quote::Single       ''/foo''
    PPI::Token::Structure       ';'
  PPI::Token::Whitespace        '\n'

I believe this is because CHECK is triggering PPI to think it's a CHECK {} block... the Statement object in the middle of the expression is then confusing parse_arg_list.

petdance commented 5 years ago

If you get this fixed, please make a note of it on the corresponding Perl::Critic policy, too.

Grinnz commented 2 months ago

This may be fixed by https://github.com/Perl-Critic/PPI/pull/247