Skip to content

Commit 12d335d

Browse files
committed
Add an option triggered_by to PHPLint.
1 parent ebc306c commit 12d335d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

doc/tasks/phplint.md

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ parameters:
99
phplint:
1010
exclude: []
1111
jobs: ~
12+
triggered_by: ['php']
1213
```
1314
**exclude**
1415
@@ -24,3 +25,9 @@ directories you wish to exclude, such as the vendor directory.
2425
The number of jobs you wish to use for parallel processing. If no number
2526
is given, it is left up to parallel-lint itself, which currently
2627
defaults to 10.
28+
29+
**trigered_by**
30+
31+
*Default: ['php']*
32+
33+
Any file extensions that you wish to be passed to the linter.

spec/GrumPHP/Task/PHPLintSpec.php

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function it_should_have_configurable_options()
3939
$options->shouldBeAnInstanceOf('Symfony\Component\OptionsResolver\OptionsResolver');
4040
$options->getDefinedOptions()->shouldContain('jobs');
4141
$options->getDefinedOptions()->shouldContain('exclude');
42+
$options->getDefinedOptions()->shouldContain('triggered_by');
4243
}
4344

4445
function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context)

src/GrumPHP/Task/PHPLint.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ public function getConfigurableOptions()
3131
$resolver->setDefaults(array(
3232
'jobs' => null,
3333
'exclude' => array(),
34+
'triggered_by' => array('php'),
3435
));
3536

3637
$resolver->setAllowedTypes('jobs', array('int', 'null'));
3738
$resolver->setAllowedTypes('exclude', 'array');
39+
$resolver->setAllowedTypes('triggered_by', 'array');
3840

3941
return $resolver;
4042
}
@@ -52,11 +54,8 @@ public function canRunInContext(ContextInterface $context)
5254
*/
5355
public function run(ContextInterface $context)
5456
{
55-
$fileNames = array_map(function (\SplFileInfo $file) {
56-
return $file->getPathname();
57-
}, iterator_to_array($context->getFiles()->extensions(array('php'))));
58-
5957
$config = $this->getConfiguration();
58+
$files = $context->getFiles()->extensions($config['triggered_by']);
6059

6160
$args = $this->processBuilder->createArgumentsForCommand('parallel-lint');
6261
$args->add('--no-colors');
@@ -65,7 +64,9 @@ public function run(ContextInterface $context)
6564
$args->add($config['jobs']);
6665
}
6766
$args->addArgumentArrayWithSeparatedValue('--exclude', $config['exclude']);
68-
$args->addArgumentArray('%s', $fileNames);
67+
$args->add('-e');
68+
$args->addOptionalCommaSeparatedArgument('%s', $config['triggered_by']);
69+
$args->addFiles($files);
6970

7071
$process = $this->processBuilder->buildProcess($args);
7172
$process->run();

0 commit comments

Comments
 (0)