summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-12-04 13:16:15 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-12-04 13:16:15 +0000
commitaafa35726b096f3e3b4967c0692a9abaee130ba1 (patch)
tree18981f3fe185ff36c8db663adf6bd49961b50b1c /perl_checker.src/parser_helper.ml
parent701155c3ec847cb0cb7ee5ed5a4d56945fe21ab3 (diff)
downloadperl_checker-aafa35726b096f3e3b4967c0692a9abaee130ba1.tar
perl_checker-aafa35726b096f3e3b4967c0692a9abaee130ba1.tar.gz
perl_checker-aafa35726b096f3e3b4967c0692a9abaee130ba1.tar.bz2
perl_checker-aafa35726b096f3e3b4967c0692a9abaee130ba1.tar.xz
perl_checker-aafa35726b096f3e3b4967c0692a9abaee130ba1.zip
- warn use of "cond ? list : ()" (use if_(cond, list) instead)
- adapt MDK::Common::* to this (using @{[]} instead of () to avoid the warning)
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml14
1 files changed, 13 insertions, 1 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 1e03f0e..00b121d 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -15,7 +15,10 @@ let is_var_dollar_ = function
| Deref(I_scalar, Ident(None, "_", _)) -> true
| _ -> false
let is_var_number_match = function
- | Deref(I_scalar, Ident(None, s, _)) -> String.length s = 1 && char_is_number s.[0]
+ | Deref(I_scalar, Ident(None, s, _)) -> String.length s = 1 && s.[0] <> '0' && char_is_number s.[0]
+ | _ -> false
+let is_call = function
+ | Call _ -> true
| _ -> false
let is_parenthesized = function
@@ -279,6 +282,15 @@ let check_arrow_needed ((_, e), _) ter =
| Deref_with _ -> warn (sndsnd ter) "the arrow \"->\" is unneeded"
| _ -> ()
+let check_ternary_para ((_, e), _) =
+ match e with
+ | List [] -> warn_rule "you may use if_() here\n beware that the short-circuit semantic of ?: is not kept\n if you want to keep the short-circuit behaviour, replace () with @{[]} and there will be no warning anymore"
+ | _ -> ()
+
+let check_ternary_paras ((_, e1), _ as ter1) ((_, e2), _ as ter2) =
+ if not (is_call e1) then check_ternary_para ter2;
+ if not (is_call e2) then check_ternary_para ter1
+
let check_unneeded_var_dollar_ ((_, e), (_, pos)) =
if is_var_dollar_ e then warn pos "\"$_ =~ /regexp/\" can be written \"/regexp/\"" else
if is_var_number_match e then warn pos "do not use the result of a match (eg: $1) to match another pattern"