diff --git a/doc/tasks/git_blacklist.md b/doc/tasks/git_blacklist.md index ec22911c8..dd7704d81 100644 --- a/doc/tasks/git_blacklist.md +++ b/doc/tasks/git_blacklist.md @@ -15,6 +15,7 @@ grumphp: whitelist_patterns: [] triggered_by: ['php'] regexp_type: G + match_word: false ``` **keywords** @@ -49,3 +50,13 @@ You can overwrite this option to whatever filetype you want to validate! *Default: G* This option allows you to choose the type of regexp you want to use for patterns (can be G for POSIX basic, E for POSIX extended or P for Perl Compatible). + +**match_word** + +*Default: false* + +This option allows you to choose how the keywords is found. + +For instance let's say you have a keyword looking like `"dd("` by default this task would also find any +text before or after the keyword meaning this: `function add($someTask)` would still be considered invalid. +This configuration option allows you to get around that issue. diff --git a/src/Task/Git/Blacklist.php b/src/Task/Git/Blacklist.php index 4141ab212..f1239ebab 100644 --- a/src/Task/Git/Blacklist.php +++ b/src/Task/Git/Blacklist.php @@ -41,6 +41,7 @@ public static function getConfigurableOptions(): OptionsResolver 'whitelist_patterns' => [], 'triggered_by' => ['php'], 'regexp_type' => 'G', + 'match_word' => false ]); $resolver->addAllowedTypes('keywords', ['array']); @@ -49,6 +50,7 @@ public static function getConfigurableOptions(): OptionsResolver $resolver->addAllowedTypes('regexp_type', ['string']); $resolver->setAllowedValues('regexp_type', ['G', 'E', 'P']); + $resolver->addAllowedTypes('match_word', ['bool']); return $resolver; } @@ -81,6 +83,7 @@ public function run(ContextInterface $context): TaskResultInterface $arguments->add('-n'); $arguments->add('--break'); $arguments->add('--heading'); + $arguments->addOptionalArgument('--word-regexp', $config['match_word']); $arguments->addOptionalArgument('--color', $this->IO->isDecorated()); $arguments->addOptionalArgument('-%s', $config['regexp_type']); $arguments->addArgumentArrayWithSeparatedValue('-e', $config['keywords']); diff --git a/test/Unit/Task/Git/BlacklistTest.php b/test/Unit/Task/Git/BlacklistTest.php index 0764789e2..328054b11 100644 --- a/test/Unit/Task/Git/BlacklistTest.php +++ b/test/Unit/Task/Git/BlacklistTest.php @@ -40,6 +40,7 @@ public function provideConfigurableOptions(): iterable 'whitelist_patterns' => [], 'triggered_by' => ['php'], 'regexp_type' => 'G', + 'match_word' => false ] ]; } @@ -180,5 +181,29 @@ public function provideExternalTaskRuns(): iterable ], $this->mockProcess(1) ]; + + yield 'match_word' => [ + [ + 'keywords' => ['keyword'], + 'match_word' => true, + ], + $this->mockContext(RunContext::class, ['hello.php', 'hello2.php']), + 'git', + [ + 'grep', + '--cached', + '-n', + '--break', + '--heading', + '--word-regexp', + '--color', + '-G', + '-e', + 'keyword', + 'hello.php', + 'hello2.php', + ], + $this->mockProcess(1) + ]; } }