Browse Source

DX: new config filename

Dariusz Ruminski 3 years ago
parent
commit
c704d13f56

+ 1 - 1
.gitignore

@@ -1,4 +1,4 @@
-/.php_cs
+/.php-cs-fixer.php
 /.phpunit.result.cache
 /.phpunit.result.cache
 /box.json
 /box.json
 /composer.lock
 /composer.lock

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

@@ -0,0 +1,63 @@
+<?php
+
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+$header = <<<'EOF'
+This file is part of PHP CS Fixer.
+
+(c) Fabien Potencier <fabien@symfony.com>
+    Dariusz Rumiński <dariusz.ruminski@gmail.com>
+
+This source file is subject to the MIT license that is bundled
+with this source code in the file LICENSE.
+EOF;
+
+$finder = PhpCsFixer\Finder::create()
+    ->exclude('tests/Fixtures')
+    ->in(__DIR__)
+    ->append([
+        __DIR__.'/dev-tools/doc.php',
+        __DIR__.'/php-cs-fixer',
+    ])
+;
+
+$config = new PhpCsFixer\Config();
+$config
+    ->setRiskyAllowed(true)
+    ->setRules([
+        '@PHP56Migration' => true,
+        '@PHPUnit75Migration:risky' => true,
+        '@PhpCsFixer' => true,
+        '@PhpCsFixer:risky' => true,
+        'header_comment' => ['header' => $header],
+        'list_syntax' => ['syntax' => 'long'],
+    ])
+    ->setFinder($finder)
+;
+
+// special handling of fabbot.io service if it's using too old PHP CS Fixer version
+if (false !== getenv('FABBOT_IO')) {
+    try {
+        PhpCsFixer\FixerFactory::create()
+            ->registerBuiltInFixers()
+            ->registerCustomFixers($config->getCustomFixers())
+            ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()))
+        ;
+    } catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
+        $config->setRules([]);
+    } catch (UnexpectedValueException $e) {
+        $config->setRules([]);
+    } catch (InvalidArgumentException $e) {
+        $config->setRules([]);
+    }
+}
+
+return $config;

+ 14 - 1
.php_cs.dist

@@ -1,5 +1,17 @@
 <?php
 <?php
 
 
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+// HARD copy of .php-cs-fixer.dist.php file for fabbot.io compatibility for PHP CS Fixer v2
+
 $header = <<<'EOF'
 $header = <<<'EOF'
 This file is part of PHP CS Fixer.
 This file is part of PHP CS Fixer.
 
 
@@ -39,7 +51,8 @@ if (false !== getenv('FABBOT_IO')) {
         PhpCsFixer\FixerFactory::create()
         PhpCsFixer\FixerFactory::create()
             ->registerBuiltInFixers()
             ->registerBuiltInFixers()
             ->registerCustomFixers($config->getCustomFixers())
             ->registerCustomFixers($config->getCustomFixers())
-            ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()));
+            ->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()))
+        ;
     } catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
     } catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
         $config->setRules([]);
         $config->setRules([]);
     } catch (UnexpectedValueException $e) {
     } catch (UnexpectedValueException $e) {

+ 2 - 2
ci-integration.sh

@@ -4,5 +4,5 @@ set -eu
 IFS='
 IFS='
 '
 '
 CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}")
 CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}")
-if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php_cs(\\.dist)?|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
-vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no ${EXTRA_ARGS}
+if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
+vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${EXTRA_ARGS}

+ 3 - 3
doc/config.rst

@@ -3,14 +3,14 @@ Config file
 ===========
 ===========
 
 
 Instead of using command line options to customize rules and rule sets, you can save the
 Instead of using command line options to customize rules and rule sets, you can save the
-project configuration in a ``.php_cs.dist`` file in the root directory of your project.
+project configuration in a ``.php-cs-fixer.dist.php`` file in the root directory of your project.
 The file must return an instance of `PhpCsFixer\\ConfigInterface <../src/ConfigInterface.php>`_
 The file must return an instance of `PhpCsFixer\\ConfigInterface <../src/ConfigInterface.php>`_
 which lets you configure the rules, the files and directories that
 which lets you configure the rules, the files and directories that
-need to be analyzed. You may also create ``.php_cs`` file, which is
+need to be analyzed. You may also create ``.php-cs-fixer.php`` file, which is
 the local configuration that will be used instead of the project configuration. It
 the local configuration that will be used instead of the project configuration. It
 is a good practice to add that file into your ``.gitignore`` file.
 is a good practice to add that file into your ``.gitignore`` file.
 With the ``--config`` option you can specify the path to the
 With the ``--config`` option you can specify the path to the
-``.php_cs`` file.
+``.php-cs-fixer.php`` file.
 
 
 The example below will add two rules to the default list of PSR2 set rules:
 The example below will add two rules to the default list of PSR2 set rules:
 
 

+ 2 - 2
doc/usage.rst

@@ -179,8 +179,8 @@ Then, add the following command to your CI:
     $ IFS='
     $ IFS='
     $ '
     $ '
     $ CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}")
     $ CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}")
-    $ if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php_cs(\\.dist)?|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
-    $ vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no ${EXTRA_ARGS}
+    $ if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
+    $ vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${EXTRA_ARGS}
 
 
 Where ``$COMMIT_RANGE`` is your range of commits, e.g. ``$TRAVIS_COMMIT_RANGE`` or ``HEAD~..HEAD``.
 Where ``$COMMIT_RANGE`` is your range of commits, e.g. ``$TRAVIS_COMMIT_RANGE`` or ``HEAD~..HEAD``.
 
 

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

@@ -100,7 +100,7 @@ final class FixCommand extends Command
                     new InputArgument('path', InputArgument::IS_ARRAY, 'The path.'),
                     new InputArgument('path', InputArgument::IS_ARRAY, 'The path.'),
                     new InputOption('path-mode', '', InputOption::VALUE_REQUIRED, 'Specify path mode (can be override or intersection).', 'override'),
                     new InputOption('path-mode', '', InputOption::VALUE_REQUIRED, 'Specify path mode (can be override or intersection).', 'override'),
                     new InputOption('allow-risky', '', InputOption::VALUE_REQUIRED, 'Are risky fixers allowed (can be yes or no).'),
                     new InputOption('allow-risky', '', InputOption::VALUE_REQUIRED, 'Are risky fixers allowed (can be yes or no).'),
-                    new InputOption('config', '', InputOption::VALUE_REQUIRED, 'The path to a .php_cs file.'),
+                    new InputOption('config', '', InputOption::VALUE_REQUIRED, 'The path to a .php-cs-fixer.php file.'),
                     new InputOption('dry-run', '', InputOption::VALUE_NONE, 'Only shows which files would have been modified.'),
                     new InputOption('dry-run', '', InputOption::VALUE_NONE, 'Only shows which files would have been modified.'),
                     new InputOption('rules', '', InputOption::VALUE_REQUIRED, 'The rules.'),
                     new InputOption('rules', '', InputOption::VALUE_REQUIRED, 'The rules.'),
                     new InputOption('using-cache', '', InputOption::VALUE_REQUIRED, 'Does cache should be used (can be yes or no).'),
                     new InputOption('using-cache', '', InputOption::VALUE_REQUIRED, 'Does cache should be used (can be yes or no).'),

+ 3 - 3
src/Console/Command/HelpCommand.php

@@ -167,14 +167,14 @@ Config file
 -----------
 -----------
 
 
 Instead of using command line options to customize the rule, you can save the
 Instead of using command line options to customize the rule, you can save the
-project configuration in a <comment>.php_cs.dist</comment> file in the root directory of your project.
+project configuration in a <comment>.php-cs-fixer.dist.php</comment> file in the root directory of your project.
 The file must return an instance of `PhpCsFixer\ConfigInterface` (<url>%%%CONFIG_INTERFACE_URL%%%</url>)
 The file must return an instance of `PhpCsFixer\ConfigInterface` (<url>%%%CONFIG_INTERFACE_URL%%%</url>)
 which lets you configure the rules, the files and directories that
 which lets you configure the rules, the files and directories that
-need to be analyzed. You may also create <comment>.php_cs</comment> file, which is
+need to be analyzed. You may also create <comment>.php-cs-fixer.php</comment> file, which is
 the local configuration that will be used instead of the project configuration. It
 the local configuration that will be used instead of the project configuration. It
 is a good practice to add that file into your <comment>.gitignore</comment> file.
 is a good practice to add that file into your <comment>.gitignore</comment> file.
 With the <comment>--config</comment> option you can specify the path to the
 With the <comment>--config</comment> option you can specify the path to the
-<comment>.php_cs</comment> file.
+<comment>.php-cs-fixer.php</comment> file.
 
 
 The example below will add two rules to the default list of PSR2 set rules:
 The example below will add two rules to the default list of PSR2 set rules:
 
 

+ 19 - 4
src/Console/ConfigurationResolver.php

@@ -227,6 +227,17 @@ final class ConfigurationResolver
                     continue;
                     continue;
                 }
                 }
 
 
+                $configFileBasename = basename($configFile);
+                $deprecatedConfigs = [
+                    '.php_cs' => '.php-cs-fixer.php',
+                    '.php_cs.dist' => '.php-cs-fixer.dist.php',
+                ];
+
+                if (isset($deprecatedConfigs[$configFileBasename])) {
+                    $message = "Configuration file `{$configFileBasename}` is deprecated, rename to `{$deprecatedConfigs[$configFileBasename]}`.";
+                    Utils::triggerDeprecation($message, InvalidConfigurationException::class);
+                }
+
                 $config = self::separatedContextLessInclude($configFile);
                 $config = self::separatedContextLessInclude($configFile);
 
 
                 // verify that the config has an instance of Config
                 // verify that the config has an instance of Config
@@ -605,13 +616,17 @@ final class ConfigurationResolver
         }
         }
 
 
         $candidates = [
         $candidates = [
-            $configDir.\DIRECTORY_SEPARATOR.'.php_cs',
-            $configDir.\DIRECTORY_SEPARATOR.'.php_cs.dist',
+            $configDir.\DIRECTORY_SEPARATOR.'.php-cs-fixer.php',
+            $configDir.\DIRECTORY_SEPARATOR.'.php-cs-fixer.dist.php',
+            $configDir.\DIRECTORY_SEPARATOR.'.php_cs', // old v2 config, present here only to throw nice error message later
+            $configDir.\DIRECTORY_SEPARATOR.'.php_cs.dist', // old v2 config, present here only to throw nice error message later
         ];
         ];
 
 
         if ($configDir !== $this->cwd) {
         if ($configDir !== $this->cwd) {
-            $candidates[] = $this->cwd.\DIRECTORY_SEPARATOR.'.php_cs';
-            $candidates[] = $this->cwd.\DIRECTORY_SEPARATOR.'.php_cs.dist';
+            $candidates[] = $this->cwd.\DIRECTORY_SEPARATOR.'.php-cs-fixer.php';
+            $candidates[] = $this->cwd.\DIRECTORY_SEPARATOR.'.php-cs-fixer.dist.php';
+            $candidates[] = $this->cwd.\DIRECTORY_SEPARATOR.'.php_cs'; // old v2 config, present here only to throw nice error message later
+            $candidates[] = $this->cwd.\DIRECTORY_SEPARATOR.'.php_cs.dist'; // old v2 config, present here only to throw nice error message later
         }
         }
 
 
         return $candidates;
         return $candidates;

+ 2 - 2
tests/AutoReview/ProjectFixerConfigurationTest.php

@@ -51,7 +51,7 @@ final class ProjectFixerConfigurationTest extends TestCase
     {
     {
         $rules = $rulesSorted = array_keys($this->loadConfig()->getRules());
         $rules = $rulesSorted = array_keys($this->loadConfig()->getRules());
         sort($rulesSorted);
         sort($rulesSorted);
-        static::assertSame($rulesSorted, $rules, 'Please sort the "rules" in `.php_cs.dist` of this project.');
+        static::assertSame($rulesSorted, $rules, 'Please sort the "rules" in `.php-cs-fixer.dist.php` of this project.');
     }
     }
 
 
     /**
     /**
@@ -59,6 +59,6 @@ final class ProjectFixerConfigurationTest extends TestCase
      */
      */
     private function loadConfig()
     private function loadConfig()
     {
     {
-        return require __DIR__.'/../../.php_cs.dist';
+        return require __DIR__.'/../../.php-cs-fixer.dist.php';
     }
     }
 }
 }

Some files were not shown because too many files changed in this diff