Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add match_word option to git blacklist task #804

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/tasks/git_blacklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ grumphp:
whitelist_patterns: []
triggered_by: ['php']
regexp_type: G
match_word: false
```

**keywords**
Expand Down Expand Up @@ -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.
3 changes: 3 additions & 0 deletions src/Task/Git/Blacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function getConfigurableOptions(): OptionsResolver
'whitelist_patterns' => [],
'triggered_by' => ['php'],
'regexp_type' => 'G',
'match_word' => false
]);

$resolver->addAllowedTypes('keywords', ['array']);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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']);
Expand Down
25 changes: 25 additions & 0 deletions test/Unit/Task/Git/BlacklistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function provideConfigurableOptions(): iterable
'whitelist_patterns' => [],
'triggered_by' => ['php'],
'regexp_type' => 'G',
'match_word' => false
]
];
}
Expand Down Expand Up @@ -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)
];
}
}