summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-08-12 04:46:01 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-08-12 04:46:01 +0000
commitc927e68bfd5e070d666642de786a971b9f0330e9 (patch)
tree012c5276c3678c50f0a02b43a4deba27081b5df5
parent230f4ddd8cbac8d2be387810de58248900004243 (diff)
downloadperl_checker-c927e68bfd5e070d666642de786a971b9f0330e9.tar
perl_checker-c927e68bfd5e070d666642de786a971b9f0330e9.tar.gz
perl_checker-c927e68bfd5e070d666642de786a971b9f0330e9.tar.bz2
perl_checker-c927e68bfd5e070d666642de786a971b9f0330e9.tar.xz
perl_checker-c927e68bfd5e070d666642de786a971b9f0330e9.zip
you can replace "grep { !member($_, ...) } @l" with "difference2([ @l ], [ ... ])"
-rw-r--r--perl_checker.src/parser_helper.ml9
-rw-r--r--perl_checker.src/test/suggest_better.t2
2 files changed, 10 insertions, 1 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 3700f2f..8d238ed 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -883,7 +883,14 @@ let call_raw force_non_builtin_func (e, para) =
warn_rule "you can replace \"map { if_(..., $_) }\" with \"grep { ... }\""
| _ -> check_anonymous_block f para)
- | "grep"
+ | "grep" ->
+ (match para with
+ | [ Anonymous_sub(None, Block [ List [ Call_op("not", [ Call(Deref(I_func, Ident(None, "member", _)), [ List(Deref(I_scalar, Ident(None, "_", _)) :: _) ]) ], _) ] ], _); _ ] ->
+ warn_rule "you can replace \"grep { !member($_, ...) } @l\" with \"difference2([ @l ], [ ... ])\""
+ | [ Anonymous_sub(None, Block [ List [ Call(Deref(I_func, Ident(None, "member", _)), [ List(Deref(I_scalar, Ident(None, "_", _)) :: _) ]) ] ], _); _ ] ->
+ warn_rule "you can replace \"grep { member($_, ...) } @l\" with \"intersection([ @l ], [ ... ])\""
+ | _ -> check_anonymous_block f para)
+
| "grep_index" | "map_index" | "partition" | "uniq_"
| "find"
| "any" | "every"
diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t
index be238a2..d3af927 100644
--- a/perl_checker.src/test/suggest_better.t
+++ b/perl_checker.src/test/suggest_better.t
@@ -72,6 +72,8 @@ member($xxx, keys %h) you can replace "member($xxx, keys %yyy
!($xxx eq 'foo') !($foo eq $bar) is better written $foo ne $bar
+grep { !member($_, qw(a b c)) } @l you can replace "grep { !member($_, ...) } @l" with "difference2([ @l ], [ ... ])"
+
foreach (@l) { use "push @l2, grep { ... } ..." instead of "foreach (...) { push @l2, $_ if ... }"
push @l2, $_ if yyy($_); or sometimes "@l2 = grep { ... } ..."
}