summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-10-13 08:47:26 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-10-13 08:47:26 +0000
commite48b0376e4f1e2a423fc847a07c80eb6d4a86c66 (patch)
tree0d41ecc9223c9351f65b9433ad234a42f70f497f
parent9cd067a1f83fe7a8577e8d2113585a4af3eeab0e (diff)
downloadperl_checker-e48b0376e4f1e2a423fc847a07c80eb6d4a86c66.tar
perl_checker-e48b0376e4f1e2a423fc847a07c80eb6d4a86c66.tar.gz
perl_checker-e48b0376e4f1e2a423fc847a07c80eb6d4a86c66.tar.bz2
perl_checker-e48b0376e4f1e2a423fc847a07c80eb6d4a86c66.tar.xz
perl_checker-e48b0376e4f1e2a423fc847a07c80eb6d4a86c66.zip
$#x == -1 is better written @x == 0
-rw-r--r--perl_checker.src/parser_helper.ml7
-rw-r--r--perl_checker.src/test/suggest_better.t2
2 files changed, 7 insertions, 2 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 39a4590..306fc3f 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -702,8 +702,11 @@ let cook_call_op op para pos =
| "||=", e :: _
| "&&=", e :: _ -> if is_not_a_scalar e then warn_rule (sprintf "\"%s\" is only useful with a scalar" op)
- | "==", [Call_op("last_array_index", _, _); Num("0", _)] ->
- warn_rule "$#x == 0 is better written @x == 1"
+ | "==", [Call_op("last_array_index", _, _); Num(n, _)] ->
+ warn_rule (sprintf "$#x == %s is better written @x == %d" n (1 + int_of_string n))
+ | "==", [Call_op("last_array_index", _, _); Call_op("- unary", [Num (n, _)], _)] ->
+ warn_rule (sprintf "$#x == -%s is better written @x == %d" n (1 - int_of_string n))
+
| "||", e :: _ when is_always_true e -> warn_rule "<constant> || ... is the same as <constant>"
| "&&", e :: _ when is_always_false e -> warn_rule "<constant> && ... is the same as <constant>"
diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t
index 9fc4f1c..4b8d2d5 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 == -1 $#x == -1 is better written @x == 0
+
$#l < 0 change your expression to use @xxx instead of $#xxx
$l[@l] = 1 "$a[@a] = ..." is better written "push @a, ..."