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

twigcs exclude subfolders #686

Merged
merged 4 commits into from
Mar 19, 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
7 changes: 7 additions & 0 deletions doc/tasks/twigcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parameters:
severity: 'warning'
ruleset: 'FriendsOfTwig\Twigcs\Ruleset\Official'
triggered_by: ['twig']
exclude: []
```

**path**
Expand All @@ -47,3 +48,9 @@ Ruleset used, default ruleset is based on [official one from twig](https://twig.
*Default: [twig]*

This option will specify which file extensions will trigger this task.

**exclude**

*Default: []*

This option will specify which relative subfolders or files will be exclude to this task.
6 changes: 6 additions & 0 deletions src/Task/TwigCs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public static function getConfigurableOptions(): OptionsResolver
'severity' => 'warning',
'ruleset' => 'FriendsOfTwig\Twigcs\Ruleset\Official',
'triggered_by' => ['twig'],
'exclude' => [],
]);

$resolver->addAllowedTypes('path', ['string']);
$resolver->addAllowedTypes('exclude', ['array']);
$resolver->addAllowedTypes('severity', ['string']);
$resolver->addAllowedTypes('ruleset', ['string']);
$resolver->addAllowedTypes('triggered_by', ['array']);
Expand Down Expand Up @@ -52,6 +54,10 @@ public function run(ContextInterface $context): TaskResultInterface
$arguments->addOptionalArgument('--ruleset=%s', $config['ruleset']);
$arguments->addOptionalArgument('--ansi', true);

// removes all NULL, FALSE and Empty Strings
$exclude = array_filter($config['exclude'], 'strlen');
$arguments->addArgumentArray('--exclude=%s', $exclude);

$process = $this->processBuilder->buildProcess($arguments);
$process->run();

Expand Down
17 changes: 17 additions & 0 deletions test/Unit/Task/TwigCsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function provideConfigurableOptions(): iterable
'severity' => 'warning',
'ruleset' => 'FriendsOfTwig\Twigcs\Ruleset\Official',
'triggered_by' => ['twig'],
'exclude' => [],
]
];
}
Expand Down Expand Up @@ -116,5 +117,21 @@ public function provideExternalTaskRuns(): iterable
'--ansi',
]
];

yield 'exclude' => [
[
'exclude' => ['src/', 'test/', null, '', false],
],
$this->mockContext(RunContext::class, ['hello.twig', 'hello2.twig']),
'twigcs',
[
'.',
'--severity=warning',
'--ruleset=FriendsOfTwig\Twigcs\Ruleset\Official',
'--ansi',
'--exclude=src/',
'--exclude=test/',
]
];
}
}