diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-01-16 13:31:19 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-01-16 13:31:19 +0000 |
commit | 7b7cbbf359ea3a53062adebb5edc8c2dd29ca6fc (patch) | |
tree | 3fb0aa82746542684f35459e2d8cbaa8f4ede1cc /perl_checker.src | |
parent | e969a4d57c50899544bb7c508180e02bd681bca5 (diff) | |
download | perl-MDK-Common-7b7cbbf359ea3a53062adebb5edc8c2dd29ca6fc.tar perl-MDK-Common-7b7cbbf359ea3a53062adebb5edc8c2dd29ca6fc.tar.gz perl-MDK-Common-7b7cbbf359ea3a53062adebb5edc8c2dd29ca6fc.tar.bz2 perl-MDK-Common-7b7cbbf359ea3a53062adebb5edc8c2dd29ca6fc.tar.xz perl-MDK-Common-7b7cbbf359ea3a53062adebb5edc8c2dd29ca6fc.zip |
- perl_checker:
- check occurences of "$foo ? $foo : $bar"
- disallow "fq::f args" when args is not parenthesized
Diffstat (limited to 'perl_checker.src')
-rw-r--r-- | perl_checker.src/parser.mly | 2 | ||||
-rw-r--r-- | perl_checker.src/parser_helper.ml | 10 | ||||
-rw-r--r-- | perl_checker.src/parser_helper.mli | 14 |
3 files changed, 20 insertions, 6 deletions
diff --git a/perl_checker.src/parser.mly b/perl_checker.src/parser.mly index 84655eb..47aebfe 100644 --- a/perl_checker.src/parser.mly +++ b/perl_checker.src/parser.mly @@ -288,7 +288,7 @@ term: /* function_calls */ | func parenthesized {sp_0($2); (P_tok, call_func true (fst $1, sndfst $2)), sp_pos_range $1 $2} /* &foo(@args) */ -| word argexpr {check_parenthesized_first_argexpr (string_of_Ident (fst $1)) $2; (P_call_no_paren, call(Deref(I_func, fst $1), sndfst $2)), sp_pos_range $1 $2} /* foo $a, $b */ +| word argexpr {check_parenthesized_first_argexpr_with_Ident (fst $1) $2; (P_call_no_paren, call(Deref(I_func, fst $1), sndfst $2)), sp_pos_range $1 $2} /* foo $a, $b */ | word_paren parenthesized {sp_0($2); (P_tok, call(Deref(I_func, fst $1), sndfst $2)), sp_pos_range $1 $2} /* foo(@args) */ | word BRACKET lines BRACKET_END listexpr %prec LSTOP {sp_n($2); check_block_sub $3 $4; ((if sndfst $5 = [] then P_tok else P_call_no_paren), call(Deref(I_func, fst $1), anonymous_sub $3 :: sndfst $5)), sp_pos_range $1 $5} /* map { foo } @bar */ | word BRACKET BRACKET expr BRACKET_END BRACKET_END listexpr %prec LSTOP {sp_n($2); sp_p($3); sp_p($4); sp_p($5); sp_p($6); ((if sndfst $7 = [] then P_tok else P_call_no_paren), call(Deref(I_func, fst $1), anonymous_sub([ Ref(I_hash, sndfst $4) ], snd $4) :: sndfst $7)), sp_pos_range $1 $7} /* map { { foo } } @bar */ diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index d04e79f..e1633fb 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -265,6 +265,15 @@ let check_parenthesized_first_argexpr word ((_, e), (_, (start, _)) as ex) = if word = "time" then die_rule "please use time() instead of time"; sp_p(ex) +let check_parenthesized_first_argexpr_with_Ident ident ((_, e), _ as ex) = + (match ident with + | Ident(Some _, _, _) -> + (match e with + | [e] when is_parenthesized e -> () + | _ -> warn_rule "use parentheses around argument (otherwise it might cause syntax errors if the package is \"require\"d and not \"use\"d") + | _ -> ()); + check_parenthesized_first_argexpr (string_of_Ident ident) ex + let check_hash_subscript ((_, e), (_, pos)) = let can_be_raw_string = function | "" | "x" | "y" -> false (* special case for {'y'} otherwise the emacs mode goes wild, special case for {'x'} to have the same as {'y'} (since they usually go together) *) @@ -308,6 +317,7 @@ let check_ternary_paras(cond, a, b) = in if dont_need_short_circuit a || is_same_fromparser cond a then check_ternary_para b; if dont_need_short_circuit b || is_same_fromparser cond b then check_ternary_para a; + if is_same_fromparser cond a && dont_need_short_circuit b then warn_rule "you can replace \"$foo ? $foo : $bar\" with \"$foo || $bar\""; [ cond; a; b ] let check_unneeded_var_dollar_ ((_, e), (_, pos)) = diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli index d1aba18..faf5c45 100644 --- a/perl_checker.src/parser_helper.mli +++ b/perl_checker.src/parser_helper.mli @@ -1,7 +1,4 @@ val bpos : int * int -val pot_strings : (string * string list) list ref -val pot_strings_and_file : (string, string) Hashtbl.t -val po_comments : string list ref val raw_pos2pos : 'a * 'b -> string * 'a * 'b val pos_range : 'a * ('b * (int * int)) -> 'c * ('d * (int * int)) -> string * int * int @@ -60,6 +57,9 @@ val check_word_alone : Types.fromparser * 'a -> Types.fromparser val check_parenthesized_first_argexpr : string -> ('a * Types.fromparser list) * (Types.spaces * (int * 'b)) -> unit +val check_parenthesized_first_argexpr_with_Ident : + Types.fromparser -> + ('a * Types.fromparser list) * (Types.spaces * (int * 'b)) -> unit val check_hash_subscript : ('a * Types.fromparser) * ('b * (int * int)) -> unit val check_arrow_needed : @@ -129,6 +129,12 @@ val to_Call_op_ : 'b * (int * int) -> ('a * Types.fromparser) * ('b * (int * int)) val followed_by_comma : ('a * Types.fromparser list) * 'b -> bool * 'c -> Types.fromparser list +val pot_strings : (string * string list) list ref +val pot_strings_and_file : (string, string) Hashtbl.t +val po_comments : string list ref +val po_comment : string * 'a -> unit +val check_format_a_la_printf : string -> int -> unit +val generate_pot : string -> unit val call_func : bool -> Types.fromparser * Types.fromparser list -> Types.fromparser val call : Types.fromparser * Types.fromparser list -> Types.fromparser @@ -165,5 +171,3 @@ val from_PATTERN_SUBST : ((string * ((int * int) * 'a) list) list * (string * ((int * int) * 'a) list) list * string) * ('b * (int * int)) -> Types.fromparser list -val po_comment : string * 'a -> unit -val generate_pot : string -> unit |