diff options
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r-- | perl_checker.src/parser_helper.ml | 14 |
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" |