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 | 7f39fecd77b6af4ffa303ab4109fad4a0ceaf91a (patch) | |
tree | 4bb91ba6f717a89b40a50cef13ec9639db8d4ea9 /perl_checker.src/parser_helper.ml | |
parent | 4d71de6ae45fc48b361dbce0f782c5d57791248c (diff) | |
download | perl_checker-7f39fecd77b6af4ffa303ab4109fad4a0ceaf91a.tar perl_checker-7f39fecd77b6af4ffa303ab4109fad4a0ceaf91a.tar.gz perl_checker-7f39fecd77b6af4ffa303ab4109fad4a0ceaf91a.tar.bz2 perl_checker-7f39fecd77b6af4ffa303ab4109fad4a0ceaf91a.tar.xz perl_checker-7f39fecd77b6af4ffa303ab4109fad4a0ceaf91a.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) = |