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 | |
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')
-rw-r--r-- | perl_checker.src/parser_helper.ml | 10 | ||||
-rw-r--r-- | perl_checker.src/test/suggest_better.t | 4 |
2 files changed, 14 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) = diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t index 58a1308..caa3677 100644 --- a/perl_checker.src/test/suggest_better.t +++ b/perl_checker.src/test/suggest_better.t @@ -62,6 +62,10 @@ member($xxx, keys %h) you can replace "member($xxx, keys %yyy !($xxx =~ /.../) !($var =~ /.../) is better written $var !~ /.../ +!($xxx == 1) !($foo == $bar) is better written $foo != $bar + +!($xxx eq 'foo') !($foo eq $bar) is better written $foo ne $bar + foreach (@l) { use "push @l2, grep { ... } ..." instead of "foreach (...) { push @l2, $_ if ... }" push @l2, $_ if yyy($_); or sometimes "@l2 = grep { ... } ..." } |