summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-04-01 15:47:31 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-04-01 15:47:31 +0000
commit44507928a9fb23e2efda52771b4f22cef38cab09 (patch)
treebf815471950b8ab18f8e8bdd4e03e13a71b56f0c /perl_checker.src/parser_helper.ml
parent84f4abd64f2f6d1e5afae404d01a8abf36becc01 (diff)
downloadperl_checker-44507928a9fb23e2efda52771b4f22cef38cab09.tar
perl_checker-44507928a9fb23e2efda52771b4f22cef38cab09.tar.gz
perl_checker-44507928a9fb23e2efda52771b4f22cef38cab09.tar.bz2
perl_checker-44507928a9fb23e2efda52771b4f22cef38cab09.tar.xz
perl_checker-44507928a9fb23e2efda52771b4f22cef38cab09.zip
- $foo =~ /^dhcp$/ is better written $foo eq 'dhcp'
- warn "grep(&f, ...)", use "grep { f } ..." instead
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml13
1 files changed, 11 insertions, 2 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 1f2a1c3..daaad87 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -422,6 +422,15 @@ let check_block_ref (l, (_, (_, end_)) as ter_lines) (_, (space, _) as ter_BRACK
let check_my_our_paren (((comma_closed, _), _), _) =
if not comma_closed then die_rule "syntax error"
+let check_simple_pattern = function
+ | [ String([ st, List [] ], _); Raw_string("", _) ] ->
+ if String.length st > 2 &&
+ st.[0] = '^' && st.[String.length st - 1] = '$' then
+ let st = skip_n_char_ 1 1 st in
+ if string_forall_with char_is_alphanumerical_ 0 st then
+ warn_rule (sprintf "\"... =~ /^%s$/\" is better written \"... eq %s\"" st st)
+ | _ -> ()
+
let rec only_one (l, (spaces, pos)) =
match l with
| [List l'] -> only_one (l', (spaces, pos))
@@ -677,10 +686,10 @@ let call_func is_a_func (e, para) =
Some(Call_op("qr//", pattern, pos) :: l)
| _ -> None)
- | "map" ->
+ | "map" | "grep" ->
(match para with
| Anonymous_sub _ :: _ -> ()
- | _ -> warn_rule "always use \"map\" with a block (eg: map { ... } @list)");
+ | _ -> warn_rule (sprintf "always use \"%s\" with a block (eg: map { ... } @list)" f));
None
| _ -> None