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 excluded directories #81

Merged
merged 2 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ twigcs /path/to/views --severity warning # Allow notices

With the example above, notices are still displayed but not altering the exit code.

You can also exclude subfolders of path like this :

```bash
twigcs /path/to/views --exclude vendor
```

Tips : You can use multiple _exclude_ parameters.

### Continuous Integration

Twigcs can be used with your favorite CI server. The command itself will return a consistent exit code telling
Expand Down
4 changes: 3 additions & 1 deletion src/Console/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function configure()
$this
->setName('lint')
->addArgument('paths', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'The path to scan for twig files.', ['.'])
->addOption('exclude', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Excluded folder of path.', [])
->addOption('severity', 's', InputOption::VALUE_REQUIRED, 'The maximum allowed error level.', 'warning')
->addOption('reporter', 'r', InputOption::VALUE_REQUIRED, 'The reporter to use.', 'console')
->addOption('ruleset', null, InputOption::VALUE_REQUIRED, 'Ruleset class to use', Official::class)
Expand All @@ -32,14 +33,15 @@ public function execute(InputInterface $input, OutputInterface $output)
$limit = $this->getSeverityLimit($input);

$paths = $input->getArgument('paths');
$exclude = $input->getOption('exclude');

$files = [];
foreach ($paths as $path) {
if (is_file($path)) {
$files[] = new \SplFileInfo($path);
} else {
$finder = new Finder();
$found = iterator_to_array($finder->in($path)->name('*.twig'));
$found = iterator_to_array($finder->in($path)->exclude($exclude)->name('*.twig'));
if (!empty($found)) {
$files = array_merge($files, $found);
}
Expand Down