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
commita69658dc4995acef787592b9c50539d7fc2c29c5 (patch)
tree93c36a02d5f020eb57450ca6c30dfeb37b9d30f1 /perl_checker.src
parentdbfca0b9ffbacfb1fba06e58e515afd072f925ea (diff)
downloadperl-MDK-Common-a69658dc4995acef787592b9c50539d7fc2c29c5.tar
perl-MDK-Common-a69658dc4995acef787592b9c50539d7fc2c29c5.tar.gz
perl-MDK-Common-a69658dc4995acef787592b9c50539d7fc2c29c5.tar.bz2
perl-MDK-Common-a69658dc4995acef787592b9c50539d7fc2c29c5.tar.xz
perl-MDK-Common-a69658dc4995acef787592b9c50539d7fc2c29c5.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