diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-12-15 16:17:52 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-12-15 16:17:52 +0000 |
commit | 52ddcb98ce7d42f5518ad12ffe93587df53e7c3e (patch) | |
tree | feaf939497722f42fd10cf4fedbb22e393ad8ec6 /perl_checker.src/parser_helper.ml | |
parent | bb5c34dc562de5e8381b80f80e47163a573e92da (diff) | |
download | perl_checker-52ddcb98ce7d42f5518ad12ffe93587df53e7c3e.tar perl_checker-52ddcb98ce7d42f5518ad12ffe93587df53e7c3e.tar.gz perl_checker-52ddcb98ce7d42f5518ad12ffe93587df53e7c3e.tar.bz2 perl_checker-52ddcb98ce7d42f5518ad12ffe93587df53e7c3e.tar.xz perl_checker-52ddcb98ce7d42f5518ad12ffe93587df53e7c3e.zip |
check what is on the left side of "xxx =~ s///"
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r-- | perl_checker.src/parser_helper.ml | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 74fad21..13191a5 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -63,6 +63,7 @@ let is_a_scalar = function | Num _ | Raw_string _ | String _ -> true + | My_our(_, [ context, _ ], _) | Deref_with(_, context, _, _) | Deref(context, _) -> is_scalar_context context | _ -> false @@ -439,8 +440,13 @@ let check_unneeded_var_dollar_not esp = if is_var_dollar_ esp.any.expr then warn esp.pos "\"$_ !~ /regexp/\" can be written \"!/regexp/\"" else if is_var_number_match esp.any.expr then warn esp.pos "do not use the result of a match (eg: $1) to match another pattern" let check_unneeded_var_dollar_s esp = - if is_var_dollar_ esp.any.expr then warn esp.pos "\"$_ =~ s/regexp/.../\" can be written \"s/regexp/.../\"" else - if is_var_number_match esp.any.expr then die_with_rawpos esp.pos "do not modify the result of a match (eg: $1)" + let expr = esp.any.expr in + if is_var_dollar_ expr then warn esp.pos "\"$_ =~ s/regexp/.../\" can be written \"s/regexp/.../\"" else + if is_var_number_match expr then die_with_rawpos esp.pos "do not modify the result of a match (eg: $1)" else + let expr = match expr with + | List [List [Call_op("=", [ expr; _], _)]] -> expr (* check $xx in ($xx = ...) =~ ... *) + | _ -> expr in + if is_a_string expr || not (is_a_scalar expr) then warn esp.pos "you can only use s/// on a variable" let check_my esp = if esp.any <> "my" then die_rule "syntax error" let check_foreach esp = if esp.any = "for" then warn esp.pos "write \"foreach\" instead of \"for\"" |