Skip to content

Commit

Permalink
Merge pull request #1049 from mrbase/deprecate-null-whitelist-patterns
Browse files Browse the repository at this point in the history
Added deprecation to whitelist_patterns with null value
  • Loading branch information
veewee authored Oct 6, 2022
2 parents f40b44a + 1d04f79 commit 33449e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/Task/ESLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -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']);
Expand All @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion test/Unit/Task/ESLintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -207,4 +207,11 @@ public function provideExternalTaskRuns(): iterable
]
];
}

/**
* @test
*/
public function it_triggers_deprecation_on_null() {
self::assertTrue(ESLint::getConfigurableOptions()->isDeprecated('whitelist_patterns'));
}
}

0 comments on commit 33449e8

Please sign in to comment.