diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-08-11 06:11:14 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-08-11 06:11:14 +0000 |
commit | b40f07af73c1fdc8a9ed985c1d8d98bb43ca1556 (patch) | |
tree | 0b236d088d01fa1ec184489e1aeea9e970685795 /perl_checker.src/parser_helper.ml | |
parent | f42f06705611801422e19c76e41a9b44dc37ecda (diff) | |
download | perl-MDK-Common-b40f07af73c1fdc8a9ed985c1d8d98bb43ca1556.tar perl-MDK-Common-b40f07af73c1fdc8a9ed985c1d8d98bb43ca1556.tar.gz perl-MDK-Common-b40f07af73c1fdc8a9ed985c1d8d98bb43ca1556.tar.bz2 perl-MDK-Common-b40f07af73c1fdc8a9ed985c1d8d98bb43ca1556.tar.xz perl-MDK-Common-b40f07af73c1fdc8a9ed985c1d8d98bb43ca1556.zip |
suggest better for !($foo == $bar) (same for eq, != and ne)
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r-- | perl_checker.src/parser_helper.ml | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 8a81bda..727f956 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -439,12 +439,22 @@ let check_scalar_subscripted esp = | Deref(I_scalar, Deref _) -> warn_rule "for complex dereferencing, use \"->\"" | _ -> () +let negatable_ops = collect (fun (a, b) -> [ a, b ; b, a ]) [ + "==", "!=" ; + "eq", "ne" ; +] + let check_negatable_expr esp = match un_parenthesize_full esp.any.expr with | Call_op("m//", var :: _, _) when not (is_var_dollar_ var) -> warn_rule "!($var =~ /.../) is better written $var !~ /.../" | Call_op("!m//", var :: _, _) when not (is_var_dollar_ var) -> warn_rule "!($var !~ /.../) is better written $var =~ /.../" + | Call_op(op, _, _) -> + (try + let neg_op = List.assoc op negatable_ops in + warn_rule (Printf.sprintf "!($foo %s $bar) is better written $foo %s $bar" op neg_op) + with Not_found -> ()) | _ -> () let check_ternary_paras(cond, a, b) = |