diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-10-13 07:34:40 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-10-13 07:34:40 +0000 |
commit | 5c78d720a642ca89af3b201897158c9fe694c0ba (patch) | |
tree | 6e5b79988300afcab4b3066dcbbb1753bf939949 | |
parent | dec8c49d8e46c8454d58c0dc8a84bfd49367b89d (diff) | |
download | perl-MDK-Common-5c78d720a642ca89af3b201897158c9fe694c0ba.tar perl-MDK-Common-5c78d720a642ca89af3b201897158c9fe694c0ba.tar.gz perl-MDK-Common-5c78d720a642ca89af3b201897158c9fe694c0ba.tar.bz2 perl-MDK-Common-5c78d720a642ca89af3b201897158c9fe694c0ba.tar.xz perl-MDK-Common-5c78d720a642ca89af3b201897158c9fe694c0ba.zip |
you can replace "any { $_ eq ... } @l" with "member(..., @l)"
-rw-r--r-- | perl_checker.src/parser_helper.ml | 10 | ||||
-rw-r--r-- | perl_checker.src/test/suggest_better.t | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 858dd80..40120ee 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -891,9 +891,17 @@ let call_raw force_non_builtin_func (e, para) = warn_rule "you can replace \"grep { member($_, ...) } @l\" with \"intersection([ @l ], [ ... ])\"" | _ -> check_anonymous_block f para) + | "any" -> + (match para with + [Anonymous_sub (None, Block + [ List [ Call_op("eq", [Deref(I_scalar, Ident(None, "_", _)); _ ], _) ] ], + _); _ ] -> + warn_rule "you can replace \"any { $_ eq ... } @l\" with \"member(..., @l)\"" + | _ -> check_anonymous_block f para) + | "grep_index" | "map_index" | "partition" | "uniq_" | "find" - | "any" | "every" + | "every" | "find_index" | "each_index" -> check_anonymous_block f para diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t index d3af927..ef3df66 100644 --- a/perl_checker.src/test/suggest_better.t +++ b/perl_checker.src/test/suggest_better.t @@ -74,6 +74,8 @@ member($xxx, keys %h) you can replace "member($xxx, keys %yyy grep { !member($_, qw(a b c)) } @l you can replace "grep { !member($_, ...) } @l" with "difference2([ @l ], [ ... ])" +any { $_ eq 'foo' } @l you can replace "any { $_ eq ... } @l" with "member(..., @l)" + foreach (@l) { use "push @l2, grep { ... } ..." instead of "foreach (...) { push @l2, $_ if ... }" push @l2, $_ if yyy($_); or sometimes "@l2 = grep { ... } ..." } |