Skip to content

Commit

Permalink
Merge pull request #686 from oallain/feature/twigcs-exclude
Browse files Browse the repository at this point in the history
twigcs exclude subfolders
  • Loading branch information
veewee committed Mar 19, 2020
2 parents d1731bc + e1049f5 commit b835400
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/tasks/twigcs.md
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
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
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/',
]
];
}
}

0 comments on commit b835400

Please sign in to comment.