summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-10-13 08:43:40 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-10-13 08:43:40 +0000
commit9cd067a1f83fe7a8577e8d2113585a4af3eeab0e (patch)
tree10330609471650f0ff903eb3c17b1d8f72e1df52 /perl_checker.src
parent9f11e76a84d3fd1ebacbe0f5f1db801a014e236b (diff)
downloadperl_checker-9cd067a1f83fe7a8577e8d2113585a4af3eeab0e.tar
perl_checker-9cd067a1f83fe7a8577e8d2113585a4af3eeab0e.tar.gz
perl_checker-9cd067a1f83fe7a8577e8d2113585a4af3eeab0e.tar.bz2
perl_checker-9cd067a1f83fe7a8577e8d2113585a4af3eeab0e.tar.xz
perl_checker-9cd067a1f83fe7a8577e8d2113585a4af3eeab0e.zip
check $#l < 0
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser_helper.ml5
-rw-r--r--perl_checker.src/test/suggest_better.t2
2 files changed, 7 insertions, 0 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 67b454f..39a4590 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -1287,6 +1287,11 @@ let symops pri para_context return_context op_str left op right =
| Deref(I_array, _), List [] -> true (* allow @l == () and @l != () *)
| _ -> false)
in
+ if op_str <> "==" && op_str <> "!=" && para_context = M_float then
+ (match un_parenthesize_full left.any.expr with
+ | Call_op("last_array_index", _, _) -> warn_rule "change your expression to use @xxx instead of $#xxx"
+ | _ -> ());
+
if not skip_context_check then
(mcontext_check para_context left ; mcontext_check para_context right) ;
to_Call_op_ return_context pri op_str [prio_lo pri left; prio_lo_after pri right] left right
diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t
index ef3df66..9fc4f1c 100644
--- a/perl_checker.src/test/suggest_better.t
+++ b/perl_checker.src/test/suggest_better.t
@@ -60,6 +60,8 @@ $l[$#l] you can replace $#l with -1
$#l == 0 $#x == 0 is better written @x == 1
+$#l < 0 change your expression to use @xxx instead of $#xxx
+
$l[@l] = 1 "$a[@a] = ..." is better written "push @a, ..."
xxx(@_) replace xxx(@_) with &xxx