Просмотр исходного кода

DX: enable `HeredocIndentationFixer` for the codebase (#7195)

Kuba Werłos 1 год назад
Родитель
Сommit
38728f554f

+ 0 - 1
.php-cs-fixer.dist.php

@@ -40,7 +40,6 @@ $config
         '@PhpCsFixer:risky' => true,
         'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']], // one should use PHPUnit built-in method instead
         'header_comment' => ['header' => $header],
-        'heredoc_indentation' => false, // TODO switch on when # of PR's is lower
         'modernize_strpos' => true, // needs PHP 8+ or polyfill
         'no_useless_concat_operator' => false, // TODO switch back on when the `src/Console/Application.php` no longer needs the concat
     ])

+ 0 - 1
.php-cs-fixer.php-highest.php

@@ -24,7 +24,6 @@ $config = require __DIR__.'/.php-cs-fixer.dist.php';
 $config->setRules(array_merge($config->getRules(), [
     '@PHP82Migration' => true,
     '@PHP80Migration:risky' => true,
-    'heredoc_indentation' => false,
 ]));
 
 return $config;

+ 65 - 65
src/Console/Command/FixCommand.php

@@ -82,110 +82,110 @@ final class FixCommand extends Command
     public function getHelp(): string
     {
         return <<<'EOF'
-The <info>%command.name%</info> command tries to fix as much coding standards
-problems as possible on a given file or files in a given directory and its subdirectories:
+            The <info>%command.name%</info> command tries to fix as much coding standards
+            problems as possible on a given file or files in a given directory and its subdirectories:
 
-    <info>$ php %command.full_name% /path/to/dir</info>
-    <info>$ php %command.full_name% /path/to/file</info>
+                <info>$ php %command.full_name% /path/to/dir</info>
+                <info>$ php %command.full_name% /path/to/file</info>
 
-By default <comment>--path-mode</comment> is set to `override`, which means, that if you specify the path to a file or a directory via
-command arguments, then the paths provided to a `Finder` in config file will be ignored. You can use <comment>--path-mode=intersection</comment>
-to merge paths from the config file and from the argument:
+            By default <comment>--path-mode</comment> is set to `override`, which means, that if you specify the path to a file or a directory via
+            command arguments, then the paths provided to a `Finder` in config file will be ignored. You can use <comment>--path-mode=intersection</comment>
+            to merge paths from the config file and from the argument:
 
-    <info>$ php %command.full_name% --path-mode=intersection /path/to/dir</info>
+                <info>$ php %command.full_name% --path-mode=intersection /path/to/dir</info>
 
-The <comment>--format</comment> option for the output format. Supported formats are `txt` (default one), `json`, `xml`, `checkstyle`, `junit` and `gitlab`.
+            The <comment>--format</comment> option for the output format. Supported formats are `txt` (default one), `json`, `xml`, `checkstyle`, `junit` and `gitlab`.
 
-NOTE: the output for the following formats are generated in accordance with schemas
+            NOTE: the output for the following formats are generated in accordance with schemas
 
-* `checkstyle` follows the common `"checkstyle" XML schema </doc/schemas/fix/checkstyle.xsd>`_
-* `gitlab` follows the `codeclimate JSON schema </doc/schemas/fix/codeclimate.json>`_
-* `json` follows the `own JSON schema </doc/schemas/fix/schema.json>`_
-* `junit` follows the `JUnit XML schema from Jenkins </doc/schemas/fix/junit-10.xsd>`_
-* `xml` follows the `own XML schema </doc/schemas/fix/xml.xsd>`_
+            * `checkstyle` follows the common `"checkstyle" XML schema </doc/schemas/fix/checkstyle.xsd>`_
+            * `gitlab` follows the `codeclimate JSON schema </doc/schemas/fix/codeclimate.json>`_
+            * `json` follows the `own JSON schema </doc/schemas/fix/schema.json>`_
+            * `junit` follows the `JUnit XML schema from Jenkins </doc/schemas/fix/junit-10.xsd>`_
+            * `xml` follows the `own XML schema </doc/schemas/fix/xml.xsd>`_
 
-The <comment>--quiet</comment> Do not output any message.
+            The <comment>--quiet</comment> Do not output any message.
 
-The <comment>--verbose</comment> option will show the applied rules. When using the `txt` format it will also display progress notifications.
+            The <comment>--verbose</comment> option will show the applied rules. When using the `txt` format it will also display progress notifications.
 
-NOTE: if there is an error like "errors reported during linting after fixing", you can use this to be even more verbose for debugging purpose
+            NOTE: if there is an error like "errors reported during linting after fixing", you can use this to be even more verbose for debugging purpose
 
-* `-v`: verbose
-* `-vv`: very verbose
-* `-vvv`: debug
+            * `-v`: verbose
+            * `-vv`: very verbose
+            * `-vvv`: debug
 
-The <comment>--rules</comment> option limits the rules to apply to the
-project:
+            The <comment>--rules</comment> option limits the rules to apply to the
+            project:
 
-EOF. /* @TODO: 4.0 - change to @PER */ <<<'EOF'
+            EOF. /* @TODO: 4.0 - change to @PER */ <<<'EOF'
 
-    <info>$ php %command.full_name% /path/to/project --rules=@PSR12</info>
+                <info>$ php %command.full_name% /path/to/project --rules=@PSR12</info>
 
-By default the PSR-12 rules are used.
+            By default the PSR-12 rules are used.
 
-The <comment>--rules</comment> option lets you choose the exact rules to
-apply (the rule names must be separated by a comma):
+            The <comment>--rules</comment> option lets you choose the exact rules to
+            apply (the rule names must be separated by a comma):
 
-    <info>$ php %command.full_name% /path/to/dir --rules=line_ending,full_opening_tag,indentation_type</info>
+                <info>$ php %command.full_name% /path/to/dir --rules=line_ending,full_opening_tag,indentation_type</info>
 
-You can also exclude the rules you don't want by placing a dash in front of the rule name, if this is more convenient,
-using <comment>-name_of_fixer</comment>:
+            You can also exclude the rules you don't want by placing a dash in front of the rule name, if this is more convenient,
+            using <comment>-name_of_fixer</comment>:
 
-    <info>$ php %command.full_name% /path/to/dir --rules=-full_opening_tag,-indentation_type</info>
+                <info>$ php %command.full_name% /path/to/dir --rules=-full_opening_tag,-indentation_type</info>
 
-When using combinations of exact and exclude rules, applying exact rules along with above excluded results:
+            When using combinations of exact and exclude rules, applying exact rules along with above excluded results:
 
-    <info>$ php %command.full_name% /path/to/project --rules=@Symfony,-@PSR1,-blank_line_before_statement,strict_comparison</info>
+                <info>$ php %command.full_name% /path/to/project --rules=@Symfony,-@PSR1,-blank_line_before_statement,strict_comparison</info>
 
-Complete configuration for rules can be supplied using a `json` formatted string.
+            Complete configuration for rules can be supplied using a `json` formatted string.
 
-    <info>$ php %command.full_name% /path/to/project --rules='{"concat_space": {"spacing": "none"}}'</info>
+                <info>$ php %command.full_name% /path/to/project --rules='{"concat_space": {"spacing": "none"}}'</info>
 
-The <comment>--dry-run</comment> flag will run the fixer without making changes to your files.
+            The <comment>--dry-run</comment> flag will run the fixer without making changes to your files.
 
-The <comment>--diff</comment> flag can be used to let the fixer output all the changes it makes.
+            The <comment>--diff</comment> flag can be used to let the fixer output all the changes it makes.
 
-The <comment>--allow-risky</comment> option (pass `yes` or `no`) allows you to set whether risky rules may run. Default value is taken from config file.
-A rule is considered risky if it could change code behaviour. By default no risky rules are run.
+            The <comment>--allow-risky</comment> option (pass `yes` or `no`) allows you to set whether risky rules may run. Default value is taken from config file.
+            A rule is considered risky if it could change code behaviour. By default no risky rules are run.
 
-The <comment>--stop-on-violation</comment> flag stops the execution upon first file that needs to be fixed.
+            The <comment>--stop-on-violation</comment> flag stops the execution upon first file that needs to be fixed.
 
-The <comment>--show-progress</comment> option allows you to choose the way process progress is rendered:
+            The <comment>--show-progress</comment> option allows you to choose the way process progress is rendered:
 
-* <comment>none</comment>: disables progress output;
-* <comment>dots</comment>: multiline progress output with number of files and percentage on each line.
+            * <comment>none</comment>: disables progress output;
+            * <comment>dots</comment>: multiline progress output with number of files and percentage on each line.
 
-If the option is not provided, it defaults to <comment>dots</comment> unless a config file that disables output is used, in which case it defaults to <comment>none</comment>. This option has no effect if the verbosity of the command is less than <comment>verbose</comment>.
+            If the option is not provided, it defaults to <comment>dots</comment> unless a config file that disables output is used, in which case it defaults to <comment>none</comment>. This option has no effect if the verbosity of the command is less than <comment>verbose</comment>.
 
-    <info>$ php %command.full_name% --verbose --show-progress=dots</info>
+                <info>$ php %command.full_name% --verbose --show-progress=dots</info>
 
-By using <command>--using-cache</command> option with `yes` or `no` you can set if the caching
-mechanism should be used.
+            By using <command>--using-cache</command> option with `yes` or `no` you can set if the caching
+            mechanism should be used.
 
-The command can also read from standard input, in which case it won't
-automatically fix anything:
+            The command can also read from standard input, in which case it won't
+            automatically fix anything:
 
-    <info>$ cat foo.php | php %command.full_name% --diff -</info>
+                <info>$ cat foo.php | php %command.full_name% --diff -</info>
 
-Finally, if you don't need BC kept on CLI level, you might use `PHP_CS_FIXER_FUTURE_MODE` to start using options that
-would be default in next MAJOR release and to forbid using deprecated configuration:
+            Finally, if you don't need BC kept on CLI level, you might use `PHP_CS_FIXER_FUTURE_MODE` to start using options that
+            would be default in next MAJOR release and to forbid using deprecated configuration:
 
-    <info>$ PHP_CS_FIXER_FUTURE_MODE=1 php %command.full_name% -v --diff</info>
+                <info>$ PHP_CS_FIXER_FUTURE_MODE=1 php %command.full_name% -v --diff</info>
 
-Exit code
----------
+            Exit code
+            ---------
 
-Exit code of the fix command is built using following bit flags:
+            Exit code of the fix command is built using following bit flags:
 
-*  0 - OK.
-*  1 - General error (or PHP minimal requirement not matched).
-*  4 - Some files have invalid syntax (only in dry-run mode).
-*  8 - Some files need fixing (only in dry-run mode).
-* 16 - Configuration error of the application.
-* 32 - Configuration error of a Fixer.
-* 64 - Exception raised within the application.
+            *  0 - OK.
+            *  1 - General error (or PHP minimal requirement not matched).
+            *  4 - Some files have invalid syntax (only in dry-run mode).
+            *  8 - Some files need fixing (only in dry-run mode).
+            * 16 - Configuration error of the application.
+            * 32 - Configuration error of a Fixer.
+            * 64 - Exception raised within the application.
 
-EOF;
+            EOF;
     }
 
     protected function configure(): void

+ 5 - 5
src/Console/Command/SelfUpdateCommand.php

@@ -68,13 +68,13 @@ final class SelfUpdateCommand extends Command
             ->setDescription('Update php-cs-fixer.phar to the latest stable version.')
             ->setHelp(
                 <<<'EOT'
-The <info>%command.name%</info> command replace your php-cs-fixer.phar by the
-latest version released on:
-<comment>https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases</comment>
+                    The <info>%command.name%</info> command replace your php-cs-fixer.phar by the
+                    latest version released on:
+                    <comment>https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases</comment>
 
-<info>$ php php-cs-fixer.phar %command.name%</info>
+                    <info>$ php php-cs-fixer.phar %command.name%</info>
 
-EOT
+                    EOT
             )
         ;
     }

+ 37 - 37
src/Documentation/FixerDocumentGenerator.php

@@ -64,11 +64,11 @@ final class FixerDocumentGenerator
             $doc .= <<<RST
 
 
-Description
------------
+                Description
+                -----------
 
-{$description}
-RST;
+                {$description}
+                RST;
         }
 
         $deprecationDescription = '';
@@ -76,9 +76,9 @@ RST;
         if ($fixer instanceof DeprecatedFixerInterface) {
             $deprecationDescription = <<<'RST'
 
-This rule is deprecated and will be removed on next major version
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-RST;
+                This rule is deprecated and will be removed on next major version
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+                RST;
             $alternatives = $fixer->getSuccessorsNames();
 
             if (0 !== \count($alternatives)) {
@@ -96,11 +96,11 @@ RST;
             $riskyDescriptionRaw = RstUtils::toRst($riskyDescriptionRaw, 0);
             $riskyDescription = <<<RST
 
-Using this rule is risky
-~~~~~~~~~~~~~~~~~~~~~~~~
+                Using this rule is risky
+                ~~~~~~~~~~~~~~~~~~~~~~~~
 
-{$riskyDescriptionRaw}
-RST;
+                {$riskyDescriptionRaw}
+                RST;
         }
 
         if ('' !== $deprecationDescription || '' !== $riskyDescription) {
@@ -123,9 +123,9 @@ RST;
             $doc .= <<<'RST'
 
 
-Configuration
--------------
-RST;
+                Configuration
+                -------------
+                RST;
 
             $configurationDefinition = $fixer->getConfigurationDefinition();
 
@@ -181,9 +181,9 @@ RST;
             $doc .= <<<'RST'
 
 
-Examples
---------
-RST;
+                Examples
+                --------
+                RST;
 
             foreach ($samples as $index => $sample) {
                 $title = sprintf('Example #%d', $index + 1);
@@ -220,11 +220,11 @@ RST;
             $doc .= <<<RST
 
 
-Rule sets
----------
+                Rule sets
+                ---------
 
-The rule is part of the following rule set{$plural}:\n\n
-RST;
+                The rule is part of the following rule set{$plural}:\n\n
+                RST;
 
             foreach ($ruleSetConfigs as $set => $config) {
                 $ruleSetPath = $this->locator->getRuleSetsDocumentationFilePath($set);
@@ -235,8 +235,8 @@ RST;
                     : '';
 
                 $doc .= <<<RST
-- `{$set} <./../../ruleSets{$ruleSetPath}>`_{$configInfo}\n
-RST;
+                    - `{$set} <./../../ruleSets{$ruleSetPath}>`_{$configInfo}\n
+                    RST;
             }
         }
 
@@ -257,10 +257,10 @@ RST;
         usort($fixers, static fn (FixerInterface $a, FixerInterface $b): int => strcmp(\get_class($a), \get_class($b)));
 
         $documentation = <<<'RST'
-=======================
-List of Available Rules
-=======================
-RST;
+            =======================
+            List of Available Rules
+            =======================
+            RST;
 
         $currentGroup = null;
 
@@ -295,10 +295,10 @@ RST;
 
             $documentation .= <<<RST
 
-- `{$fixer->getName()} <{$path}>`_{$attributes}
+                - `{$fixer->getName()} <{$path}>`_{$attributes}
 
-  {$summary}
-RST;
+                  {$summary}
+                RST;
         }
 
         return "{$documentation}\n";
@@ -319,10 +319,10 @@ RST;
 
             $error = <<<RST
 
-.. error::
-   Cannot generate diff for code sample #{$sampleNumber} of rule {$ruleName}:
-   the sample is not suitable for current version of PHP (%s).
-RST;
+                .. error::
+                   Cannot generate diff for code sample #{$sampleNumber} of rule {$ruleName}:
+                   the sample is not suitable for current version of PHP (%s).
+                RST;
 
             return sprintf($error, PHP_VERSION);
         }
@@ -349,9 +349,9 @@ RST;
 
         return <<<RST
 
-.. code-block:: diff
+            .. code-block:: diff
 
-   {$diff}
-RST;
+               {$diff}
+            RST;
     }
 }

+ 4 - 4
src/Documentation/ListDocumentGenerator.php

@@ -48,11 +48,11 @@ final class ListDocumentGenerator
         );
 
         $documentation = <<<'RST'
-=======================
-List of Available Rules
-=======================
+            =======================
+            List of Available Rules
+            =======================
 
-RST;
+            RST;
         foreach ($fixers as $fixer) {
             $name = $fixer->getName();
             $definition = $fixer->getDefinition();

+ 4 - 4
src/Documentation/RuleSetDocumentationGenerator.php

@@ -101,10 +101,10 @@ final class RuleSetDocumentationGenerator
     public function generateRuleSetsDocumentationIndex(array $setDefinitions): string
     {
         $documentation = <<<'RST'
-===========================
-List of Available Rule sets
-===========================
-RST;
+            ===========================
+            List of Available Rule sets
+            ===========================
+            RST;
         foreach ($setDefinitions as $name => $path) {
             $path = substr($path, strrpos($path, '/'));
             $documentation .= "\n- `{$name} <.{$path}>`_";

+ 4 - 4
src/Fixer/Alias/BacktickToShellExecFixer.php

@@ -39,11 +39,11 @@ final class BacktickToShellExecFixer extends AbstractFixer
             [
                 new CodeSample(
                     <<<'EOT'
-<?php
-$plain = `ls -lah`;
-$withVar = `ls -lah $var1 ${var2} {$var3} {$var4[0]} {$var5->call()}`;
+                        <?php
+                        $plain = `ls -lah`;
+                        $withVar = `ls -lah $var1 ${var2} {$var3} {$var4[0]} {$var5->call()}`;
 
-EOT
+                        EOT
                 ),
             ],
             'Conversion is done only when it is non risky, so when special chars like single-quotes, double-quotes and backticks are not used inside the command.'

+ 11 - 11
src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php

@@ -34,21 +34,21 @@ final class MultilineCommentOpeningClosingFixer extends AbstractFixer
             [
                 new CodeSample(
                     <<<'EOT'
-<?php
+                        <?php
 
-/******
- * Multiline comment with arbitrary asterisks count
- ******/
+                        /******
+                         * Multiline comment with arbitrary asterisks count
+                         ******/
 
-/**\
- * Multiline comment that seems a DocBlock
- */
+                        /**\
+                         * Multiline comment that seems a DocBlock
+                         */
 
-/**
- * DocBlock with arbitrary asterisk count at the end
- **/
+                        /**
+                         * DocBlock with arbitrary asterisk count at the end
+                         **/
 
-EOT
+                        EOT
                 ),
             ]
         );

+ 9 - 9
src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php

@@ -64,15 +64,15 @@ final class TrailingCommaInMultilineFixer extends AbstractFixer implements Confi
                 new CodeSample("<?php\narray(\n    1,\n    2\n);\n"),
                 new VersionSpecificCodeSample(
                     <<<'SAMPLE'
-<?php
-    $x = [
-        'foo',
-        <<<EOD
-            bar
-            EOD
-    ];
-
-SAMPLE
+                        <?php
+                            $x = [
+                                'foo',
+                                <<<EOD
+                                    bar
+                                    EOD
+                            ];
+
+                        SAMPLE
                     ,
                     new VersionSpecification(7_03_00),
                     ['after_heredoc' => true]

Некоторые файлы не были показаны из-за большого количества измененных файлов