diff --git a/src/Task/ESLint.php b/src/Task/ESLint.php index df136178..0a37c12c 100644 --- a/src/Task/ESLint.php +++ b/src/Task/ESLint.php @@ -11,6 +11,7 @@ use GrumPHP\Task\Context\ContextInterface; use GrumPHP\Task\Context\GitPreCommitContext; use GrumPHP\Task\Context\RunContext; +use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Process\Process; @@ -23,8 +24,8 @@ public static function getConfigurableOptions(): OptionsResolver // Task config options 'bin' => null, 'triggered_by' => ['js', 'jsx', 'ts', 'tsx', 'vue'], - 'whitelist_patterns' => null, - + 'whitelist_patterns' => [], + // ESLint native config options 'config' => null, 'ignore_path' => null, @@ -39,7 +40,7 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('bin', ['null', 'string']); $resolver->addAllowedTypes('whitelist_patterns', ['null', 'array']); $resolver->addAllowedTypes('triggered_by', ['array']); - + // ESLint native config options $resolver->addAllowedTypes('config', ['null', 'string']); $resolver->addAllowedTypes('ignore_path', ['null', 'string']); @@ -49,6 +50,19 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('no_eslintrc', ['bool']); $resolver->addAllowedTypes('quiet', ['bool']); + $resolver->setDeprecated( + 'whitelist_patterns', + 'phpro/grumphp', + '1.14', + function (Options $options, $value): string { + if (null === $value) { + return 'Parsing "null" to option "whitelist_patterns" is deprecated, pass an array instead.'; + } + + return ''; + } + ); + return $resolver; } diff --git a/test/Unit/Task/ESLintTest.php b/test/Unit/Task/ESLintTest.php index 43531ed8..d2dc775d 100644 --- a/test/Unit/Task/ESLintTest.php +++ b/test/Unit/Task/ESLintTest.php @@ -29,7 +29,7 @@ public function provideConfigurableOptions(): iterable // Task config options 'bin' => null, 'triggered_by' => ['js', 'jsx', 'ts', 'tsx', 'vue'], - 'whitelist_patterns' => null, + 'whitelist_patterns' => [], // ESLint native config options 'config' => null, @@ -207,4 +207,11 @@ public function provideExternalTaskRuns(): iterable ] ]; } + + /** + * @test + */ + public function it_triggers_deprecation_on_null() { + self::assertTrue(ESLint::getConfigurableOptions()->isDeprecated('whitelist_patterns')); + } }