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 | 6c54f75abe67ba12f3374b6cac02b04248d8189b (patch) | |
tree | 8ccd5cc7ec633f87a46bce1254e1e86160b461d4 /perl_checker.src | |
parent | 26be6f3a623b133c7ff87c907e7a5fb012119960 (diff) | |
download | perl-MDK-Common-6c54f75abe67ba12f3374b6cac02b04248d8189b.tar perl-MDK-Common-6c54f75abe67ba12f3374b6cac02b04248d8189b.tar.gz perl-MDK-Common-6c54f75abe67ba12f3374b6cac02b04248d8189b.tar.bz2 perl-MDK-Common-6c54f75abe67ba12f3374b6cac02b04248d8189b.tar.xz perl-MDK-Common-6c54f75abe67ba12f3374b6cac02b04248d8189b.zip |
suggest using the functional map instead of the imperative foreach when
possible
Diffstat (limited to 'perl_checker.src')
-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 |