Skip to content

Commit

Permalink
feat: #32 pint
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Nov 19, 2024
1 parent 150a6a8 commit 462db8d
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/laravel-11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
run: |
./vendor/bin/phpcs --standard=PSR12 src/ tests/
./vendor/bin/phpmd . text src/stubs/phpmd.xml
./vendor/bin/pint --test --config src/stubs/pint.json
-
name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ composer require --dev laravel-fans/lint
php artisan lint:publish
```

You will find `phpcs.xml` and `phpmd.xml` in your project, feel free to change it.
You will find `pint.json`, `phpcs.xml` and `phpmd.xml` in your project, feel free to change it.

## usage

Expand All @@ -35,15 +35,16 @@ php artisan lint:code
php artisan lint:code --fix
php artisan lint:code app/ tests/
php artisan lint:code app/ tests/ --fix
php artisan lint:pint
php artisan lint:phpcs
php artisan lint:pmd
php artisan lint:staged
```

### lint route URI
### lint route

```shell
php artisan lint:route
```

Slug(kebab-case) standard: lowercase ASCII letters, digits, and hyphens (a-z, 0–9, -)
Slug(kebab-case) URI standard: lowercase ASCII letters, digits, and hyphens (a-z, 0–9, -)
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"require": {
"ext-json": "*",
"illuminate/support": ">=v9",
"laravel/pint": ">=v1",
"phpmd/phpmd": ">=2.10",
"squizlabs/php_codesniffer": ">=3.5"
},
Expand Down
2 changes: 0 additions & 2 deletions src/LintCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace LaravelFans\Lint;

use FilesystemIterator;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class LintCodeCommand extends Command
{
Expand Down
10 changes: 8 additions & 2 deletions src/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace LaravelFans\Lint;

use FilesystemIterator;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class LintCommand extends Command
{
Expand Down Expand Up @@ -34,7 +32,15 @@ public function handle()
$code = $this->call('lint:phpcs', [
'files' => $this->argument('files'), '--fix' => $this->option('fix')
]);
if ($this->option('fix')) {
$code = $this->call('lint:pint', [
'files' => $this->argument('files'), '--repair' => true
]);
}
if (!$this->option('fix')) {
$code = $this->call('lint:pint', [
'files' => $this->argument('files'), '--test' => true
]);
$code += $this->call('lint:pmd', [
'files' => $this->argument('files')
]);
Expand Down
2 changes: 0 additions & 2 deletions src/LintPhpcsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace LaravelFans\Lint;

use FilesystemIterator;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class LintPhpcsCommand extends Command
{
Expand Down
53 changes: 53 additions & 0 deletions src/LintPintCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace LaravelFans\Lint;

use Illuminate\Console\Command;

class LintPintCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'lint:pint
{--test}
{--repair}
{--config=pint.json}
{files?*}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Lint by pint';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$files = empty($this->argument('files')) ? ['.'] : $this->argument('files');
$command = "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "pint";
$command .= " --config=" . $this->option('config');
if ($this->option('test')) {
$command .= ' --test';
}
if ($this->option('repair')) {
$command .= ' --repair';
}
exec(
$command . ' ' . implode(' ', $files),
$output,
$code
);
foreach ($output as $line) {
$this->line($line);
}
return $code;
}
}
2 changes: 0 additions & 2 deletions src/LintPmdCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace LaravelFans\Lint;

use FilesystemIterator;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class LintPmdCommand extends Command
{
Expand Down
3 changes: 3 additions & 0 deletions src/LintPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function handle()
{
$basePath = $this->laravel->basePath();

if (!File::exists($basePath . '/pint.json')) {
File::copy(__DIR__ . '/stubs/pint.json', $basePath . '/pint.json');
}
if (!File::exists($basePath . '/phpcs.xml')) {
File::copy(__DIR__ . '/stubs/phpcs.xml', $basePath . '/phpcs.xml');
}
Expand Down
1 change: 1 addition & 0 deletions src/LintServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function boot()
$this->commands([
LintCommand::class,
LintCodeCommand::class,
LintPintCommand::class,
LintPmdCommand::class,
LintPhpcsCommand::class,
LintPublishCommand::class,
Expand Down
2 changes: 0 additions & 2 deletions src/LintStagedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace LaravelFans\Lint;

use FilesystemIterator;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class LintStagedCommand extends Command
{
Expand Down
2 changes: 2 additions & 0 deletions src/stubs/git-pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

FILES=$(git diff --diff-filter=d --name-only HEAD | { grep '.php$' || true; })
for file in $FILES; do
./vendor/bin/phpcs --config=pint.json --repair "$file"
./vendor/bin/phpcbf --extensions=php --standard=phpcs.xml "$file"
./vendor/bin/phpcs --extensions=php --standard=phpcs.xml "$file"
./vendor/bin/phpmd "$file" text phpmd.xml
done
Expand Down
3 changes: 3 additions & 0 deletions src/stubs/pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "psr12"
}
2 changes: 0 additions & 2 deletions tests/LintPhpcsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace LaravelFans\Lint\Tests;

use Illuminate\Support\Facades\File;
use phpmock\MockBuilder;
use phpmock\functions\FixedValueFunction;

class LintPhpcsCommandTest extends TestCase
{
Expand Down
26 changes: 26 additions & 0 deletions tests/LintPintCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace LaravelFans\Lint\Tests;

use phpmock\MockBuilder;

class LintPintCommandTest extends TestCase
{
public function testLintPintWithoutArgs()
{
$builder = new MockBuilder();
$builder->setNamespace('\\LaravelFans\\Lint')
->setName("exec")
->setFunction(
function ($command, &$output, &$code) {
$this->assertEquals("vendor/bin/pint --config=pint.json .", $command);
$output = [];
$code = 0;
}
);
$mock = $builder->build();
$mock->enable();
$this->artisan('lint:pint')->assertExitCode(0);
$mock->disable();
}
}
2 changes: 0 additions & 2 deletions tests/LintPmdCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace LaravelFans\Lint\Tests;

use Illuminate\Support\Facades\File;
use phpmock\MockBuilder;
use phpmock\functions\FixedValueFunction;

class LintPmdCommandTest extends TestCase
{
Expand Down
1 change: 1 addition & 0 deletions tests/LintPublishCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testGitExists()
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
File::makeDirectory($laravelPath . '/.git/hooks/', 0755, true);
$this->artisan('lint:publish')->run();
$this->assertFileExists($laravelPath . '/pint.json');
$this->assertFileExists($laravelPath . '/phpcs.xml');
$this->assertFileExists($laravelPath . '/phpmd.xml');
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');
Expand Down

0 comments on commit 462db8d

Please sign in to comment.