diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-10-14 05:06:52 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-10-14 05:06:52 +0000 |
commit | 7ec17262cd6bbda5ec69753ff27ab5d4f7493c5c (patch) | |
tree | b2bcb95207c2725b62ca1e072d9984e9bcc5ba4e /perl_checker.src/parser_helper.ml | |
parent | 239f07fc8c33f6ebfcf5729b97f9db8b8b55e348 (diff) | |
download | perl-MDK-Common-7ec17262cd6bbda5ec69753ff27ab5d4f7493c5c.tar perl-MDK-Common-7ec17262cd6bbda5ec69753ff27ab5d4f7493c5c.tar.gz perl-MDK-Common-7ec17262cd6bbda5ec69753ff27ab5d4f7493c5c.tar.bz2 perl-MDK-Common-7ec17262cd6bbda5ec69753ff27ab5d4f7493c5c.tar.xz perl-MDK-Common-7ec17262cd6bbda5ec69753ff27ab5d4f7493c5c.zip |
suggest mkdir() instead of system("mkdir ...")
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r-- | perl_checker.src/parser_helper.ml | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index c317f98..b4afdaf 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -840,6 +840,22 @@ msgstr \"\" ) sorted_pot_strings ; close_out fd +let fake_string_from_String_l l = String.concat "$foo" (List.map fst l) +let fake_string_option_from_expr = function + | String(l, _) -> Some(fake_string_from_String_l l) + | Raw_string(s, _) -> Some s + | _ -> None + +let check_system_call = function + | "mkdir" :: l -> + let has_p = List.exists (str_begins_with "-p") l in + let has_m = List.exists (str_begins_with "-m") l in + if has_p && has_m then () + else if has_p then warn_rule "you can replace system(\"mkdir -p ...\") with mkdir_p(...)" + else if has_m then warn_rule "you can replace system(\"mkdir -m <mode> ...\") with mkdir(..., <mode>)" + else warn_rule "you can replace system(\"mkdir ...\") with mkdir(...)" + | _ -> () + let call_raw force_non_builtin_func (e, para) = let check_anonymous_block f = function | [ Anonymous_sub _ ; Deref (I_hash, _) ] -> @@ -946,12 +962,17 @@ let call_raw force_non_builtin_func (e, para) = | "system" -> (match un_parenthesize_full_l para with - | [ String(l, _) ] -> - if List.exists (fun (s, _) -> String.contains s '\'' || String.contains s '"') l && - not (List.exists (fun (s, _) -> List.exists (String.contains s) [ '<' ; '>' ; '&' ; ';']) l) then - warn_rule "instead of quoting parameters you should give a list of arguments" - | _ -> ()) - + | [ e ] -> + (match fake_string_option_from_expr e with + | Some s -> + if List.exists (String.contains s) [ '\'' ; char_quote ] && + not (List.exists (String.contains s) [ '<' ; '>' ; '&' ; ';']) then + warn_rule "instead of quoting parameters you should give a list of arguments"; + check_system_call (split_at ' ' s) + | None -> ()) + | l -> + let l' = filter_some_with fake_string_option_from_expr l in + check_system_call l') | _ -> () ); |