diff --git a/app/Support/PhpCodeSniffer.php b/app/Support/PhpCodeSniffer.php index 7e033de..3f901d7 100644 --- a/app/Support/PhpCodeSniffer.php +++ b/app/Support/PhpCodeSniffer.php @@ -14,16 +14,30 @@ public function lint(): int { $this->heading('Linting using PHP_CodeSniffer'); - return $this->process('runPHPCS', $this->getPaths()); + if (! $this->hasCustomConfig()) { + if (empty($paths = $this->getPaths())) { + return 0; + } + } + + return $this->process('runPHPCS', $paths ?? []); } public function fix(): int { $this->heading('Fixing using PHP_CodeSniffer'); - $fix = $this->process('runPHPCBF', $this->getPaths()); + if ($this->hasCustomConfig()) { + $paths = []; + } else { + if (empty($paths = $this->getPaths())) { + return 0; + } + } + + $fix = $this->process('runPHPCBF', $paths); - $lint = $this->process('runPHPCS', ['-n', '--report=summary', ...$this->getPaths()]); + $lint = $this->process('runPHPCS', ['-n', '--report=summary', ...$paths]); if ($lint !== 0) { $this->failure('PHP Code_Sniffer found errors that cannot be fixed automatically.'); @@ -78,12 +92,21 @@ private function process(string $tool, array $params = []): int */ private function getPaths(): array { - if ($this->getConfigFile() !== 'Tighten') { - return []; - } - - return $this->dusterConfig->get('paths') === [Project::path()] + $paths = $this->dusterConfig->get('paths') === [Project::path()] ? $this->getDefaultDirectories() : $this->dusterConfig->get('paths'); + + return array_values(array_filter($paths, function ($path) { + if (is_dir($path)) { + return true; + } + + return ! str_ends_with($path, '.blade.php'); + })); + } + + private function hasCustomConfig(): bool + { + return $this->getConfigFile() !== 'Tighten'; } private function installTightenCodingStandard(): void diff --git a/builds/duster b/builds/duster index dbd3655..4418c4e 100755 Binary files a/builds/duster and b/builds/duster differ diff --git a/tests/Feature/LintCommandTest.php b/tests/Feature/LintCommandTest.php index 8076fab..aad73ae 100755 --- a/tests/Feature/LintCommandTest.php +++ b/tests/Feature/LintCommandTest.php @@ -73,6 +73,15 @@ ->not->toContain('Linting using Pint'); }); +it('lints with PHP_CodeSniffer skipping blade files passed individually', function () { + [$statusCode, $output] = run('lint', [ + 'path' => base_path('tests/Fixtures/PhpCodeSnifferBladeOnly/file.blade.php'), + '--using' => 'phpcs', + ]); + + expect($statusCode)->toBe(0); +}); + it('lints with PHP CS Fixer', function () { [$statusCode, $output] = run('lint', [ 'path' => base_path('tests/Fixtures/PhpCsFixerFixableIssues'), diff --git a/tests/Fixtures/PhpCodeSnifferBladeOnly/file.blade.php b/tests/Fixtures/PhpCodeSnifferBladeOnly/file.blade.php new file mode 100644 index 0000000..73070c0 --- /dev/null +++ b/tests/Fixtures/PhpCodeSnifferBladeOnly/file.blade.php @@ -0,0 +1 @@ +