diff --git a/src/Action/Action.php b/src/Action/Action.php index ce682b0..6db1086 100644 --- a/src/Action/Action.php +++ b/src/Action/Action.php @@ -45,4 +45,17 @@ private function isEnabled(ActionConfig $action): bool { return $action->getOptions()->get('enabled', true); } + + public function getChangedFiles(Config\Action $action, Repository $repository): array + { + $excludedFiles = $action->getOptions()->get('excluded_files'); + $extensions = $action->getOptions()->get('extensions', ['php', 'twig']); + + $changedFiles = []; + foreach ($extensions as $extension) { + $changedFiles = [...$changedFiles, ...$repository->getIndexOperator()->getStagedFilesOfType($extension)]; + } + + return array_diff($changedFiles, $excludedFiles); + } } diff --git a/src/Action/CheckForTabs.php b/src/Action/CheckForTabs.php new file mode 100644 index 0000000..c9669c9 --- /dev/null +++ b/src/Action/CheckForTabs.php @@ -0,0 +1,43 @@ +getChangedFiles($action, $repository); + if (empty($files)) { + return; + } + + $arguments = array_merge( + [ + 'grep', + '$\t', + ], + $files + ); + + $process = new Process($arguments); + + $process->run(); + $process->wait(); + + if ($process->getOutput()) { + $io->writeError("{$process->getOutput()}"); + $this->throwError($action, $io); + } + } +} diff --git a/src/Action/CheckForWhiteSpaceAtEOL.php b/src/Action/CheckForWhiteSpaceAtEOL.php new file mode 100644 index 0000000..92c2458 --- /dev/null +++ b/src/Action/CheckForWhiteSpaceAtEOL.php @@ -0,0 +1,43 @@ +getChangedFiles($action, $repository); + if (empty($files)) { + return; + } + + $arguments = array_merge( + [ + 'grep', + '[[:blank:]]$', + ], + $files + ); + + $process = new Process($arguments); + + $process->run(); + $process->wait(); + + if ($process->getOutput()) { + $io->writeError("{$process->getOutput()}"); + $this->throwError($action, $io); + } + } +}