Skip to content

Commit 462db8d

Browse files
committed
feat: #32 pint
1 parent 150a6a8 commit 462db8d

17 files changed

+103
-17
lines changed

.github/workflows/laravel-11.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
run: |
3131
./vendor/bin/phpcs --standard=PSR12 src/ tests/
3232
./vendor/bin/phpmd . text src/stubs/phpmd.xml
33+
./vendor/bin/pint --test --config src/stubs/pint.json
3334
-
3435
name: Upload coverage to Codecov
3536
uses: codecov/codecov-action@v4

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ composer require --dev laravel-fans/lint
1717
php artisan lint:publish
1818
```
1919

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

2222
## usage
2323

@@ -35,15 +35,16 @@ php artisan lint:code
3535
php artisan lint:code --fix
3636
php artisan lint:code app/ tests/
3737
php artisan lint:code app/ tests/ --fix
38+
php artisan lint:pint
3839
php artisan lint:phpcs
3940
php artisan lint:pmd
4041
php artisan lint:staged
4142
```
4243

43-
### lint route URI
44+
### lint route
4445

4546
```shell
4647
php artisan lint:route
4748
```
4849

49-
Slug(kebab-case) standard: lowercase ASCII letters, digits, and hyphens (a-z, 0–9, -)
50+
Slug(kebab-case) URI standard: lowercase ASCII letters, digits, and hyphens (a-z, 0–9, -)

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"require": {
3232
"ext-json": "*",
3333
"illuminate/support": ">=v9",
34+
"laravel/pint": ">=v1",
3435
"phpmd/phpmd": ">=2.10",
3536
"squizlabs/php_codesniffer": ">=3.5"
3637
},

src/LintCodeCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintCodeCommand extends Command
108
{

src/LintCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintCommand extends Command
108
{
@@ -34,7 +32,15 @@ public function handle()
3432
$code = $this->call('lint:phpcs', [
3533
'files' => $this->argument('files'), '--fix' => $this->option('fix')
3634
]);
35+
if ($this->option('fix')) {
36+
$code = $this->call('lint:pint', [
37+
'files' => $this->argument('files'), '--repair' => true
38+
]);
39+
}
3740
if (!$this->option('fix')) {
41+
$code = $this->call('lint:pint', [
42+
'files' => $this->argument('files'), '--test' => true
43+
]);
3844
$code += $this->call('lint:pmd', [
3945
'files' => $this->argument('files')
4046
]);

src/LintPhpcsCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintPhpcsCommand extends Command
108
{

src/LintPintCommand.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint;
4+
5+
use Illuminate\Console\Command;
6+
7+
class LintPintCommand extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'lint:pint
15+
{--test}
16+
{--repair}
17+
{--config=pint.json}
18+
{files?*}';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Lint by pint';
26+
27+
/**
28+
* Execute the console command.
29+
*
30+
* @return void
31+
*/
32+
public function handle()
33+
{
34+
$files = empty($this->argument('files')) ? ['.'] : $this->argument('files');
35+
$command = "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "pint";
36+
$command .= " --config=" . $this->option('config');
37+
if ($this->option('test')) {
38+
$command .= ' --test';
39+
}
40+
if ($this->option('repair')) {
41+
$command .= ' --repair';
42+
}
43+
exec(
44+
$command . ' ' . implode(' ', $files),
45+
$output,
46+
$code
47+
);
48+
foreach ($output as $line) {
49+
$this->line($line);
50+
}
51+
return $code;
52+
}
53+
}

src/LintPmdCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace LaravelFans\Lint;
44

5-
use FilesystemIterator;
65
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\File;
86

97
class LintPmdCommand extends Command
108
{

src/LintPublishCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public function handle()
3030
{
3131
$basePath = $this->laravel->basePath();
3232

33+
if (!File::exists($basePath . '/pint.json')) {
34+
File::copy(__DIR__ . '/stubs/pint.json', $basePath . '/pint.json');
35+
}
3336
if (!File::exists($basePath . '/phpcs.xml')) {
3437
File::copy(__DIR__ . '/stubs/phpcs.xml', $basePath . '/phpcs.xml');
3538
}

src/LintServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function boot()
1717
$this->commands([
1818
LintCommand::class,
1919
LintCodeCommand::class,
20+
LintPintCommand::class,
2021
LintPmdCommand::class,
2122
LintPhpcsCommand::class,
2223
LintPublishCommand::class,

0 commit comments

Comments
 (0)