From 9e5fec86804d9e5335c7ab04e8d00e4ebf501856 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 11 Aug 2004 07:02:34 +0000 Subject: "$foo or $foo = ..." can be written "$foo ||= ..." --- perl_checker.src/parser_helper.ml | 3 +++ perl_checker.src/test/suggest_better.t | 2 ++ 2 files changed, 5 insertions(+) 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 " or ... is the same as ..." | "and", e :: _ when is_always_true (un_parenthesize_full e) -> warn_rule " 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'" -- cgit v1.2.1