From 9a4b72a011db84ce1997977bebd75030226e7edf Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 10 Apr 2003 11:06:16 +0000 Subject: warn when using a regexp terminated with .* or .*$ (which is useless) --- perl_checker.src/parser_helper.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'perl_checker.src') diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index d5869ec..fc84b93 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -778,7 +778,15 @@ let to_String parse strict (l, (_, pos)) = String(l', raw_pos2pos pos) let from_PATTERN parse ((s, opts), (_, pos)) = - [ String(parse_interpolated parse s, raw_pos2pos pos) ; + let re = parse_interpolated parse s in + (match List.rev re with + | (s, List []) :: _ -> + if str_ends_with s ".*" then + warn_rule (sprintf "you can remove \"%s\" at the end of your regexp" ".*") + else if str_ends_with s ".*$" then + warn_rule (sprintf "you can remove \"%s\" at the end of your regexp" ".*$") + | _ -> ()); + [ String(re, raw_pos2pos pos) ; Raw_string(opts, raw_pos2pos pos) ] let from_PATTERN_SUBST parse ((s1, s2, opts), (_, pos)) = [ String(parse_interpolated parse s1, raw_pos2pos pos) ; -- cgit v1.2.1