summaryrefslogtreecommitdiffstats
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
commitc0e7b9c7d3dd295f2d432c096508fcffbcbbc837 (patch)
tree122a51746bc0a80a3f8c59079b6bc601a65a7bd5
parent87bc1a8e7cb91e78fcaec2a6f8a554500a4dc6c6 (diff)
downloadperl_checker-c0e7b9c7d3dd295f2d432c096508fcffbcbbc837.tar
perl_checker-c0e7b9c7d3dd295f2d432c096508fcffbcbbc837.tar.gz
perl_checker-c0e7b9c7d3dd295f2d432c096508fcffbcbbc837.tar.bz2
perl_checker-c0e7b9c7d3dd295f2d432c096508fcffbcbbc837.tar.xz
perl_checker-c0e7b9c7d3dd295f2d432c096508fcffbcbbc837.zip
recognize a form of "find { ... } ..."
-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"