diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-04-01 15:47:31 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-04-01 15:47:31 +0000 |
commit | 9cbab8aa086051a00a05a8fdfaf58a0e7fe0c418 (patch) | |
tree | 310f5a6b45cb513624b0270438cb382fa95e33b8 /perl_checker.src | |
parent | e8d753659e1cf367aefc22c34babef895ea6c529 (diff) | |
download | perl-MDK-Common-9cbab8aa086051a00a05a8fdfaf58a0e7fe0c418.tar perl-MDK-Common-9cbab8aa086051a00a05a8fdfaf58a0e7fe0c418.tar.gz perl-MDK-Common-9cbab8aa086051a00a05a8fdfaf58a0e7fe0c418.tar.bz2 perl-MDK-Common-9cbab8aa086051a00a05a8fdfaf58a0e7fe0c418.tar.xz perl-MDK-Common-9cbab8aa086051a00a05a8fdfaf58a0e7fe0c418.zip |
- $foo =~ /^dhcp$/ is better written $foo eq 'dhcp'
- warn "grep(&f, ...)", use "grep { f } ..." instead
Diffstat (limited to 'perl_checker.src')
-rw-r--r-- | perl_checker.src/parser.mly | 4 | ||||
-rw-r--r-- | perl_checker.src/parser_helper.ml | 13 | ||||
-rw-r--r-- | perl_checker.src/parser_helper.mli | 1 |
3 files changed, 14 insertions, 4 deletions
diff --git a/perl_checker.src/parser.mly b/perl_checker.src/parser.mly index ecdc4da..86856ec 100644 --- a/perl_checker.src/parser.mly +++ b/perl_checker.src/parser.mly @@ -220,8 +220,8 @@ term: | term OR_TIGHT BRACKET expr BRACKET_END {sp_p($3); sp_p($4); sp_p($5); call_op_(op_p P_tight_or "||" $2, $3, [prio_lo P_assign $1; Ref(I_hash, sndfst $4)]) (sp_pos_range $1 $5)} -| term PATTERN_MATCH PATTERN {sp_n($2); sp_p($3); check_unneeded_var_dollar_ ($1); to_Call_op_(P_expr, "m//", sndfst $1 :: from_PATTERN $3) (sp_pos_range $1 $3)} -| term PATTERN_MATCH_NOT PATTERN {sp_n($2); sp_p($3); check_unneeded_var_dollar_not($1); to_Call_op_(P_expr, "!m//", sndfst $1 :: from_PATTERN $3) (sp_pos_range $1 $3)} +| term PATTERN_MATCH PATTERN {sp_n($2); sp_p($3); check_unneeded_var_dollar_ ($1); let pattern = from_PATTERN $3 in check_simple_pattern pattern ; to_Call_op_(P_expr, "m//", sndfst $1 :: pattern) (sp_pos_range $1 $3)} +| term PATTERN_MATCH_NOT PATTERN {sp_n($2); sp_p($3); check_unneeded_var_dollar_not($1); let pattern = from_PATTERN $3 in check_simple_pattern pattern ; to_Call_op_(P_expr, "!m//", sndfst $1 :: pattern) (sp_pos_range $1 $3)} | term PATTERN_MATCH PATTERN_SUBST {sp_n($2); sp_p($3); check_unneeded_var_dollar_s ($1); to_Call_op_(P_expr, "s///", sndfst $1 :: from_PATTERN_SUBST $3) (sp_pos_range $1 $3)} | term PATTERN_MATCH_NOT PATTERN_SUBST {die_with_rawpos (sndsnd $2) "use =~ instead of !~ and negate the return value"} diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 1f2a1c3..daaad87 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -422,6 +422,15 @@ let check_block_ref (l, (_, (_, end_)) as ter_lines) (_, (space, _) as ter_BRACK let check_my_our_paren (((comma_closed, _), _), _) = if not comma_closed then die_rule "syntax error" +let check_simple_pattern = function + | [ String([ st, List [] ], _); Raw_string("", _) ] -> + if String.length st > 2 && + st.[0] = '^' && st.[String.length st - 1] = '$' then + let st = skip_n_char_ 1 1 st in + if string_forall_with char_is_alphanumerical_ 0 st then + warn_rule (sprintf "\"... =~ /^%s$/\" is better written \"... eq %s\"" st st) + | _ -> () + let rec only_one (l, (spaces, pos)) = match l with | [List l'] -> only_one (l', (spaces, pos)) @@ -677,10 +686,10 @@ let call_func is_a_func (e, para) = Some(Call_op("qr//", pattern, pos) :: l) | _ -> None) - | "map" -> + | "map" | "grep" -> (match para with | Anonymous_sub _ :: _ -> () - | _ -> warn_rule "always use \"map\" with a block (eg: map { ... } @list)"); + | _ -> warn_rule (sprintf "always use \"%s\" with a block (eg: map { ... } @list)" f)); None | _ -> None diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli index 691efdc..82bd947 100644 --- a/perl_checker.src/parser_helper.mli +++ b/perl_checker.src/parser_helper.mli @@ -95,6 +95,7 @@ val check_block_ref : Types.fromparser list * (Types.spaces * (int * int)) -> 'a * (Types.spaces * (int * 'b)) -> unit val check_my_our_paren : ((bool * 'a) * 'b) * 'c -> unit +val check_simple_pattern : Types.fromparser list -> unit val only_one : Types.fromparser list * ('a * (int * int)) -> Types.fromparser val only_one_array_ref : Types.fromparser list * ('a * (int * int)) -> Types.fromparser |