diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-05-23 14:22:00 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-05-23 14:22:00 +0000 |
commit | ca7e6b9377f77b97bda625bd1655bae213d095a1 (patch) | |
tree | a12faaa919578b4eb3baf0a430d4fbb8c0a90b65 /perl_checker.src/parser_helper.ml | |
parent | cd5f0719c7562fed6f0c9c4f51f3b318ae9e5911 (diff) | |
download | perl_checker-ca7e6b9377f77b97bda625bd1655bae213d095a1.tar perl_checker-ca7e6b9377f77b97bda625bd1655bae213d095a1.tar.gz perl_checker-ca7e6b9377f77b97bda625bd1655bae213d095a1.tar.bz2 perl_checker-ca7e6b9377f77b97bda625bd1655bae213d095a1.tar.xz perl_checker-ca7e6b9377f77b97bda625bd1655bae213d095a1.zip |
suggest using the functional map instead of the imperative foreach when
possible
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r-- | perl_checker.src/parser_helper.ml | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 57d65e5..944713b 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -594,6 +594,18 @@ let cook_call_op op para pos = (match List.hd para with | List [ List _ ] -> warn_rule "remove the parentheses" | e -> if is_not_a_scalar e then warn_rule (sprintf "\"%s\" is only useful with a scalar" op)) + | "foreach" -> + (match para with + | [ _; Block [ Call_op("if infix", [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)) ; Deref(I_scalar, Ident(None, "_", _)) ]) ] ; _ ], _) ; Semi_colon ] ] -> + let l = string_of_Ident l in + warn_rule (sprintf "use \"push @%s, grep { ... } ...\" instead of \"foreach (...) { push @%s, $_ if ... }\"\n or sometimes \"@%s = grep { ... } ...\"" l l l) + | [ _; Block [ Call_op("if infix", [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)); _ ]) ] ; _ ], _) ; Semi_colon ] ] -> + let l = string_of_Ident l in + warn_rule (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) + | [ _; Block [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)); _ ]) ] ; Semi_colon ] ] -> + let l = string_of_Ident l in + warn_rule (sprintf "use \"push @%s, map { ... } ...\" instead of \"foreach (...) { push @%s, ... }\"\n or sometimes \"@%s = map { ... } ...\"" l l l) + | _ -> ()) | _ -> ()); let call = Call_op(op, para, raw_pos2pos pos) in match op, para with |