summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-08-11 07:02:34 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-08-11 07:02:34 +0000
commit9e5fec86804d9e5335c7ab04e8d00e4ebf501856 (patch)
treed4ddbf5a6bed2a14f41d039f2dce704490fde7f8
parentd52c40bc0a59a2827a75d5b38a3c78662b362a27 (diff)
downloadperl-MDK-Common-9e5fec86804d9e5335c7ab04e8d00e4ebf501856.tar
perl-MDK-Common-9e5fec86804d9e5335c7ab04e8d00e4ebf501856.tar.gz
perl-MDK-Common-9e5fec86804d9e5335c7ab04e8d00e4ebf501856.tar.bz2
perl-MDK-Common-9e5fec86804d9e5335c7ab04e8d00e4ebf501856.tar.xz
perl-MDK-Common-9e5fec86804d9e5335c7ab04e8d00e4ebf501856.zip
"$foo or $foo = ..." can be written "$foo ||= ..."
-rw-r--r--perl_checker.src/parser_helper.ml3
-rw-r--r--perl_checker.src/test/suggest_better.t2
2 files changed, 5 insertions, 0 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 6075c93..a673f6d 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -697,6 +697,9 @@ let cook_call_op op para pos =
| "or", e :: _ when is_always_false (un_parenthesize_full e) -> warn_rule "<constant> or ... is the same as ..."
| "and", e :: _ when is_always_true (un_parenthesize_full e) -> warn_rule "<constant> and ... is the same as ..."
+ | "or", [ List [ Deref(I_scalar, id) ]; List [ Call_op("=", [ Deref(I_scalar, id_); _], _) ] ] when is_same_fromparser id id_ ->
+ warn_rule "\"$foo or $foo = ...\" can be written \"$foo ||= ...\""
+
| _ -> ());
match op, para with
diff --git a/perl_checker.src/test/suggest_better.t b/perl_checker.src/test/suggest_better.t
index 8d8cb37..be238a2 100644
--- a/perl_checker.src/test/suggest_better.t
+++ b/perl_checker.src/test/suggest_better.t
@@ -38,6 +38,8 @@ $o = xxx() if !$o; "$foo = ... if !$foo" can be written "$
$o = xxx() unless $o; "$foo = ... unless $foo" can be written "$foo ||= ..."
+$o or $o = xxx(); "$foo or $foo = ..." can be written "$foo ||= ..."
+
$_ =~ s/xxx/yyy/ "$_ =~ s/regexp/.../" can be written "s/regexp/.../"
$xxx =~ /^yyy$/ "... =~ /^yyy$/" is better written "... eq 'yyy'"