]> git.donarmstrong.com Git - perltidy.git/commitdiff
make formatting of 'class' more like 'package'
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 14 Mar 2023 00:21:01 +0000 (17:21 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 14 Mar 2023 00:21:01 +0000 (17:21 -0700)
This update makes any 'class' keyword be formatted as if it were
'package' as far as spaces and blank lines go (i.e., -blpb=n flag applies).
This also improves coding efficiency.

lib/Perl/Tidy/Formatter.pm
t/snippets/expect/rt145706.def
t/snippets/packing_list.txt
t/snippets27.t

index 7a8638e482515bbf7ab667c944faf2ac8c8b9fe0..2812d4d339e036a39b78e437d9d24af9190ccb83 100644 (file)
@@ -7695,7 +7695,7 @@ sub respace_tokens_inner_loop {
             }
 
             # Trim certain spaces in identifiers
-            if ( $type eq 'i' ) {
+            if ( $type eq 'i' && $token =~ /\s/ ) {
 
                 if ( $token =~ /$SUB_PATTERN/ ) {
 
@@ -7724,15 +7724,12 @@ sub respace_tokens_inner_loop {
 
                 # clean up spaces in package identifiers, like
                 #   "package        Bob::Dog;"
-                elsif ( substr( $token, 0, 7 ) eq 'package'
-                    && $token =~ /^package\s/ )
-                {
+                elsif ( $token =~ /^(package|class)\s/ ) {
                     $token =~ s/\s+/ /g;
                     $rtoken_vars->[_TOKEN_] = $token;
 
                     $self->[_ris_special_identifier_token_]->{$token} =
                       'package';
-
                 }
 
                 # trim identifiers of trailing blanks which can occur
index 28f3977c9527fa9434cefc352eaec4595596c859..343164abf5733cb6f2aca3ad8a885cf8abd92975 100644 (file)
@@ -1,8 +1,11 @@
 # some tests for default setting --use-feature=class, rt145706
 class Example::Subclass1 : isa(Example::Base) { ... }
+
 class Example::Subclass2 : isa(Example::Base 2.345) { ... }
+
 class Example::Subclass3 : isa(Example::Base) 1.345 { ... }
 field $y : param(the_y_value);
+
 class Pointer 2.0 {
     field $x : param;
     field $y : param;
index f53aef688a6640ee5675b30c4a24710f12d32359..b4a28e8424ce2049ebaaf0f8f347c683d5300fff 100644 (file)
 ../snippets27.t        olbxl.def
 ../snippets27.t        olbxl.olbxl1
 ../snippets28.t        olbxl.olbxl2
+../snippets28.t        recombine5.def
+../snippets28.t        recombine6.def
+../snippets28.t        recombine7.def
+../snippets28.t        recombine8.def
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets28.t        recombine5.def
-../snippets28.t        recombine6.def
-../snippets28.t        recombine7.def
-../snippets28.t        recombine8.def
index d23e446554a4a1aff90a57b6b1200626594353a3..f6c497d1a73222cf89f15a6df44aaf10a564b048 100644 (file)
@@ -925,9 +925,12 @@ foreach my $dir (
             expect => <<'#17...........',
 # some tests for default setting --use-feature=class, rt145706
 class Example::Subclass1 : isa(Example::Base) { ... }
+
 class Example::Subclass2 : isa(Example::Base 2.345) { ... }
+
 class Example::Subclass3 : isa(Example::Base) 1.345 { ... }
 field $y : param(the_y_value);
+
 class Pointer 2.0 {
     field $x : param;
     field $y : param;