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
commit670835bee947e095d54f0bd15e53f6e98e48c26f (patch)
tree0853ab9d7dc1d57167443446b9811d2ad6c71a11
parent5c2d0f2e92f7e340f80c8a448ac8183383a0b01f (diff)
downloadperl_checker-670835bee947e095d54f0bd15e53f6e98e48c26f.tar
perl_checker-670835bee947e095d54f0bd15e53f6e98e48c26f.tar.gz
perl_checker-670835bee947e095d54f0bd15e53f6e98e48c26f.tar.bz2
perl_checker-670835bee947e095d54f0bd15e53f6e98e48c26f.tar.xz
perl_checker-670835bee947e095d54f0bd15e53f6e98e48c26f.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'"