summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-11-17 17:06:52 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-11-17 17:06:52 +0000
commit7d1cbb259c63a0cc56ba15433cdef208899e45e7 (patch)
treed4c6b5165f82b2b72a12c8d0a55593b06774519a /perl_checker.src
parentcab1e04c6458ab10cdb5ef03f125aee5668695ac (diff)
downloadperl-MDK-Common-7d1cbb259c63a0cc56ba15433cdef208899e45e7.tar
perl-MDK-Common-7d1cbb259c63a0cc56ba15433cdef208899e45e7.tar.gz
perl-MDK-Common-7d1cbb259c63a0cc56ba15433cdef208899e45e7.tar.bz2
perl-MDK-Common-7d1cbb259c63a0cc56ba15433cdef208899e45e7.tar.xz
perl-MDK-Common-7d1cbb259c63a0cc56ba15433cdef208899e45e7.zip
recognize a form of "find { ... } ..."
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser_helper.ml7
-rw-r--r--perl_checker.src/test/suggest_better.t7
2 files changed, 14 insertions, 0 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index d80de58..7c61f1b 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -743,6 +743,13 @@ let cook_call_op op para pos =
| Call_op("if infix", [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, Ident _) as l; _ ]) ] ; _ ], _) ->
let l = string_of_fromparser l in
warn_rule [Warn_suggest_functional] (sprintf "use \"push %s, map { ... ? ... : () } ...\" instead of \"foreach (...) { push %s, ... if ... }\"\n or sometimes \"%s = map { ... ? ... : () } ...\"\n or sometimes \"%s = map { if_(..., ...) } ...\"" l l l l)
+
+ | Call_op ("if", [ _; Block [ List [ Call_op("=", [Deref(I_scalar, _) as ret; Deref(I_scalar, Ident(None, "_", _)) ], _) ];
+ Semi_colon;
+ List [ Deref(I_func, Ident(None, "last", _)) ];
+ Semi_colon ] ], _) ->
+ warn_rule [Warn_suggest_functional; Warn_MDK_Common] (sprintf "use \"%s = find { ... } ...\"" (string_of_fromparser ret))
+
| List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, Ident _) as l; _ ]) ] ->
let l = string_of_fromparser l in
warn_rule [Warn_suggest_functional] (sprintf "use \"push %s, map { ... } ...\" instead of \"foreach (...) { push %s, ... }\"\n or sometimes \"%s = map { ... } ...\"" l l l)
diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t
index e98e64f..d76abeb 100644
--- a/perl_checker.src/test/suggest_better.t
+++ b/perl_checker.src/test/suggest_better.t
@@ -92,6 +92,13 @@ foreach (@l) { use "push @l2, map { ... ? ... : () } .
push @l2, yyy($_) if zzz($_); or sometimes "@l2 = map { ... ? ... : () } ..."
} or sometimes "@l2 = map { if_(..., ...) } ..."
+foreach (@l) { use "$xxx = find { ... } ..."
+ if (xxx($_)) {
+ $xxx = $_;
+ last;
+ }
+}
+
if (grep { xxx() } @l) {} in boolean context, use "any" instead of "grep"
$xxx = grep { xxx() } @l; you may use "find" instead of "grep"