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 ignore patterns for File size task #485

Merged
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
13 changes: 12 additions & 1 deletion doc/tasks/file_size.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ parameters:
tasks:
file_size:
max_size: 10M
ignore_patterns: []
```

**max_size**

*Default: 10M*

Defines the maximum size. The target value may use magnitudes of kilobytes (k, ki), megabytes (m, mi), or gigabytes (g, gi). Those suffixed with an i use the appropriate 2**n version in accordance with the IEC standard.
Defines the maximum size. The target value may use magnitudes of kilobytes (k, ki),
megabytes (m, mi), or gigabytes (g, gi). Those suffixed with an i use the appropriate 2**n version
in accordance with the IEC standard.


**ignore_patterns**

*Default: []*

This is a list of patterns that will be ignored. With this option you can skip files.
Leave this option blank to run analysis for all files.
2 changes: 2 additions & 0 deletions spec/Task/FileSizeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function it_should_have_configurable_options()
$options = $this->getConfigurableOptions();
$options->shouldBeAnInstanceOf(OptionsResolver::class);
$options->getDefinedOptions()->shouldContain('max_size');
$options->getDefinedOptions()->shouldContain('ignore_patterns');
}

function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context)
Expand Down Expand Up @@ -78,6 +79,7 @@ function it_throws_exception_if_the_process_fails(RunContext $context, FilesColl
{
$filesCollection->count()->willReturn(1);
$filesCollection->ignoreSymlinks()->willReturn($filesCollection);
$filesCollection->notPaths([])->willReturn($filesCollection);
$filesCollection->size('>10M')->willReturn(new FilesCollection([
new SplFileInfo('src/Collection/TaskResultCollection.php', 'src/Collection', 'TaskResultCollection.php'),
]));
Expand Down
3 changes: 3 additions & 0 deletions src/Task/FileSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public function getConfigurableOptions()
$resolver = new OptionsResolver();
$resolver->setDefaults([
'max_size' => '10M',
'ignore_patterns' => [],
]);

$resolver->addAllowedTypes('max_size', ['string', 'integer']);
$resolver->addAllowedTypes('ignore_patterns', ['array']);

return $resolver;
}
Expand Down Expand Up @@ -83,6 +85,7 @@ public function run(ContextInterface $context)
$maxSize = $config['max_size'];
$files = $context->getFiles()
->ignoreSymlinks()
->notPaths($config['ignore_patterns'])
->size(sprintf('>%s', $maxSize));

if ($files->count() > 0) {
Expand Down