From: Steve Hancock Date: Tue, 14 Mar 2023 00:21:01 +0000 (-0700) Subject: make formatting of 'class' more like 'package' X-Git-Tag: 20230309.02~13 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=246ac573bc73f699146e07e45ad9b764fc330077;p=perltidy.git make formatting of 'class' more like 'package' 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. --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7a8638e4..2812d4d3 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 diff --git a/t/snippets/expect/rt145706.def b/t/snippets/expect/rt145706.def index 28f3977c..343164ab 100644 --- a/t/snippets/expect/rt145706.def +++ b/t/snippets/expect/rt145706.def @@ -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; diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index f53aef68..b4a28e84 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -385,6 +385,10 @@ ../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 @@ -525,7 +529,3 @@ ../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 diff --git a/t/snippets27.t b/t/snippets27.t index d23e4465..f6c497d1 100644 --- a/t/snippets27.t +++ b/t/snippets27.t @@ -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;