summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-08-11 06:19:55 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-08-11 06:19:55 +0000
commit2249c9577c00f8da88145876730a43f32a14f042 (patch)
tree7ea38e68d2a3096a081724f92c6e0d9f28f7a747 /perl_checker.src
parent737f4cd712fca5a307a77988ca70500b97ab360c (diff)
downloadperl_checker-2249c9577c00f8da88145876730a43f32a14f042.tar
perl_checker-2249c9577c00f8da88145876730a43f32a14f042.tar.gz
perl_checker-2249c9577c00f8da88145876730a43f32a14f042.tar.bz2
perl_checker-2249c9577c00f8da88145876730a43f32a14f042.tar.xz
perl_checker-2249c9577c00f8da88145876730a43f32a14f042.zip
"$a[@a] = ..." is better written "push @a, ..."
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser_helper.ml4
-rw-r--r--perl_checker.src/test/suggest_better.t2
2 files changed, 6 insertions, 0 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 727f956..42e14a9 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -683,6 +683,10 @@ let cook_call_op op para pos =
if Info.is_on_same_line_current pos then warn pos "no need to initialize variables, it's done by default" ;
call
+ | "=", [ Deref_with(I_array, I_scalar, id, Deref(I_array, id_)); _ ] when is_same_fromparser id id_ ->
+ warn_rule "\"$a[@a] = ...\" is better written \"push @a, ...\"" ;
+ call
+
| "=", [ Deref(I_star, String ([(sf1, List [])], _)); _ ] ->
warn_rule (sprintf "write *{'%s'} instead of *{\"%s\"}" sf1 sf1) ;
call
diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t
index caa3677..247fe6c 100644
--- a/perl_checker.src/test/suggest_better.t
+++ b/perl_checker.src/test/suggest_better.t
@@ -56,6 +56,8 @@ $l[$#l] you can replace $#l with -1
$#l == 0 $#x == 0 is better written @x == 1
+$l[@l] = 1 "$a[@a] = ..." is better written "push @a, ..."
+
xxx(@_) replace xxx(@_) with &xxx
member($xxx, keys %h) you can replace "member($xxx, keys %yyy)" with "exists $yyy{$xxx}"