Skip to content
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
39 changes: 31 additions & 8 deletions app/Support/PhpCodeSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -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
Expand Down
Binary file modified builds/duster
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/Feature/LintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/PhpCodeSnifferBladeOnly/file.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>{{ $foo }}</div>