Changeset 7818

Show
Ignore:
Timestamp:
09/10/09 02:28:20 (12 months ago)
Author:
Sewi
Message:

Adding some beginner error checks (ticket #52 and other sources)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Document/Perl/Beginner.pm

    r7807 r7818  
    7474                } 
    7575        } 
     76 
    7677        if ( $text =~ /use\s+warning\s*;/ ) { 
    7778                $self->{error} = "You need to write use warnings (with an s at the end) and not use warning."; 
    7879                return; 
    7980        } 
     81 
    8082        if ( $text =~ /map[\s\t\r\n]*\{.+?\}[\s\t\r\n]*\(.+?\)[\s\t\r\n]*\,/ ) { 
    8183                $self->{error} = "map (),x uses x also as list value for map."; 
     
    8688        if ( $text =~ /package DB[\;\:]/ ) { 
    8789                $self->{error} = "This file uses the DB-namespace which is used by the Perl Debugger."; 
     90                return; 
     91        } 
     92 
     93        if ( $text =~ /\=[\s\t\r\n]*chomp\b/ ) { 
     94                $self->{error} = "chomp doesn't return the chomped value, it modifies the variable given as argument."; 
     95                return; 
     96        } 
     97 
     98        if ( $text =~ /map[\s\t\r\n]*\{[\s\t\r\n]*(\$_[\s\t\r\n]*\=\~[\s\t\r\n]*)?s\// ) { 
     99                $self->{error} = "Substitute (s///) doesn't return the changed value even if map."; 
     100                return; 
     101        } 
     102 
     103        if ( $text =~ /\(\<\@\w+\>\)/ ) { 
     104                $self->{error} = "(<\@Foo>) is Perl6 syntax and usually not valid in Perl5: %s"; 
     105                return; 
     106        } 
     107 
     108        if ( $text =~ /if[\s\t\r\n]*\(?[\$\s\t\r\n\w]+\=[\s\t\r\n\$\w]/ ) { 
     109                $self->{error} = "A single = in a if-condition is usually a typo, use == or eq to compare."; 
     110                return; 
     111        } 
     112 
     113        if ( $text =~ /open[\s\t\r\n]*\(?\$?\w+[\s\t\r\n]*(\,.+?)?\,?([\"\'])[^\2]+?\|[^\2]+?\2/ ) { 
     114                $self->{error} = "Using a | char in open without a | at the beginning or end is usually a typo."; 
     115                return; 
     116        } 
     117 
     118        if ( $text =~ /open[\s\t\r\n]*\(?\$?\w+[\s\t\r\n]*\,(.+?\,)?([\"\'])\|[^\2]+?\|\2/ ) { 
     119                $self->{error} = "You can't use open to pipe to and from a command at the same time."; 
    88120                return; 
    89121        }