]> git.donarmstrong.com Git - perltidy.git/commitdiff
remove unwanted spaces in a package declaration
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 28 Nov 2020 14:21:25 +0000 (06:21 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 28 Nov 2020 14:21:25 +0000 (06:21 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 79ec3533a5bd32f7a698a97f3a76d074075e493a..8fe58fbb00a7e7a8f0bcd4c09d2a112ce9d3a3c2 100644 (file)
@@ -5397,6 +5397,13 @@ sub respace_tokens {
                     $rtoken_vars->[_TOKEN_] = $token;
                 }
 
+                # clean up spaces in package identifiers, like
+                #   "package        Bob::Dog;"
+                if ($token =~ /^package\s/) {
+                    $token =~ s/\s+/ /g;
+                    $rtoken_vars->[_TOKEN_] = $token;
+                }
+
                 # trim identifiers of trailing blanks which can occur
                 # under some unusual circumstances, such as if the
                 # identifier 'witch' has trailing blanks on input here:
@@ -10193,7 +10200,7 @@ EOM
                     }
 
                     # break before all package declarations
-                    elsif ( $leading_token =~ /^(package\s)/ ) {
+                    elsif ( substr( $leading_token, 0, 8 ) eq 'package ' ) {
                         $want_blank = $rOpts->{'blank-lines-before-packages'};
                     }
                 }
index 3d28fcf2c63fa16fb76d69a9ecf4b4530d49789a..1e83ebbb1c4c9e246d67f1ac9284028510bd3f6c 100644 (file)
@@ -2,6 +2,18 @@
 
 =over 4
 
+=item B<removed excess spaces in a package declaration>
+
+Testing revealed that for a line such as
+
+   package        Bob::Dog;
+
+which has extra spaces or even tabs after the keyword 'package', the
+extra spaces or tabs were not being removed.  This was fixed 28 Nov 2020.
+The line now formats to
+
+    package Bob::Dog;
+
 =item B<do not automatically delete closing side comments with --indent-only>
 
 For the parameter combination --indent-only and --closing-side-comments, old