Skip to content

Commit 606dd95

Browse files
committed
feat: laravel lint
0 parents  commit 606dd95

14 files changed

+375
-0
lines changed

.github/workflows/laravel-6.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Laravel 6
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-18.04
13+
container:
14+
image: php:7.4-cli
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
- name: PHPUnit
19+
run: |
20+
apt update
21+
apt install -y libzip-dev unzip
22+
pecl install xdebug
23+
docker-php-ext-enable xdebug
24+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
25+
composer require orchestra/testbench:^v4 --dev
26+
./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-filter src/ tests/
27+
- name: codecov
28+
uses: codecov/codecov-action@v1
29+
with:
30+
name: laravel-6

.github/workflows/laravel-7.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Laravel 7
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-18.04
13+
container:
14+
image: php:7.4-cli
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
- name: PHPUnit
19+
run: |
20+
apt update
21+
apt install -y libzip-dev unzip
22+
pecl install xdebug
23+
docker-php-ext-enable xdebug
24+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
25+
composer require orchestra/testbench:^v5 --dev
26+
./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-filter src/ tests/
27+
- name: codecov
28+
uses: codecov/codecov-action@v1
29+
with:
30+
name: laravel-6

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea/
2+
/composer.lock
3+
/vendor/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Laravel Fans
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Laravel Lint
2+
3+
[![codecov](https://codecov.io/gh/laravel-fans/laravel-lint/branch/main/graph/badge.svg)](https://codecov.io/gh/laravel-fans/laravel-lint)
4+
[![Laravel 6](https://github.com/laravel-fans/laravel-lint/workflows/Laravel%206/badge.svg)](https://github.com/laravel-fans/laravel-lint/actions)
5+
[![Laravel 7](https://github.com/laravel-fans/laravel-lint/workflows/Laravel%207/badge.svg)](https://github.com/laravel-fans/laravel-lint/actions)
6+
7+
Check Code Style(default PSR-12) for Laravel
8+
9+
## install
10+
11+
Run in your Laravel project:
12+
13+
```shell
14+
composer install --dev laravel-fans/lint
15+
php artisan lint:publish
16+
```
17+
18+
## use
19+
20+
```shell
21+
php artisan lint:check .
22+
php artisan lint:check app/ tests/
23+
php artisan lint:check --standard=Squiz app/
24+
php artisan lint:staged
25+
```
26+
27+
The default standard is PSR-12, feel free to change the `phpcs.xml`.

composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "laravel-fans/lint",
3+
"description": "Laravel Lint Code Style",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "sinkcup",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"LaravelFans\\Lint\\": "src"
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"App\\": "vendor/orchestra/testbench-core/laravel/app/",
20+
"LaravelFans\\Lint\\Tests\\": "tests/"
21+
}
22+
},
23+
"extra": {
24+
"laravel": {
25+
"providers": [
26+
"LaravelFans\\Lint\\LintServiceProvider"
27+
]
28+
}
29+
},
30+
"minimum-stability": "stable",
31+
"require": {
32+
"laravel/framework": ">=v6.18.38",
33+
"squizlabs/php_codesniffer": "^3.5"
34+
},
35+
"require-dev": {
36+
"orchestra/testbench": ">=v4.8.0"
37+
}
38+
}

src/LintCheckCommand.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint;
4+
5+
use FilesystemIterator;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\File;
8+
9+
class LintCheckCommand extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'lint:check
17+
{files*}
18+
{--standard=phpcs.xml : coding standards}';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Lint files';
26+
27+
/**
28+
* Execute the console command.
29+
*
30+
* @return void
31+
*/
32+
public function handle()
33+
{
34+
exec(
35+
'vendor/bin/phpcs --standard=' . $this->option('standard')
36+
. ' ' . implode(' ', $this->argument('files')),
37+
$output,
38+
$code
39+
);
40+
foreach ($output as $line) {
41+
$this->line($line);
42+
}
43+
return $code;
44+
}
45+
}

src/LintPublishCommand.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint;
4+
5+
use FilesystemIterator;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\File;
8+
9+
class LintPublishCommand extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'lint:publish';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Publish Lint config files';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return void
29+
*/
30+
public function handle()
31+
{
32+
$basePath = $this->laravel->basePath();
33+
34+
File::copy(__DIR__ . '/stubs/phpcs.xml', $basePath . '/phpcs.xml');
35+
if (File::exists($basePath . '/.git')) {
36+
File::copy(__DIR__ . '/stubs/git-pre-commit', $basePath . '/.git/hooks/pre-commit');
37+
File::chmod($basePath . '/.git/hooks/pre-commit', 0755);
38+
}
39+
40+
$this->info('published successfully.');
41+
}
42+
}

src/LintServiceProvider.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class LintServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Bootstrap any application services.
11+
*
12+
* @return void
13+
*/
14+
public function boot()
15+
{
16+
if ($this->app->runningInConsole()) {
17+
$this->commands([
18+
LintCheckCommand::class,
19+
LintPublishCommand::class,
20+
LintStagedCommand::class,
21+
]);
22+
}
23+
}
24+
25+
/**
26+
* Get the services provided by the provider.
27+
*
28+
* @return array
29+
*/
30+
public function provides()
31+
{
32+
return [
33+
LintCheckCommand::class,
34+
LintPublishCommand::class,
35+
LintStagedCommand::class,
36+
];
37+
}
38+
}

src/LintStagedCommand.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace LaravelFans\Lint;
4+
5+
use FilesystemIterator;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\File;
8+
9+
class LintStagedCommand extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'lint:staged';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Lint git staged files';
24+
25+
/**
26+
* Execute the console command.
27+
*
28+
* @return void
29+
*/
30+
public function handle()
31+
{
32+
exec('.git/hooks/pre-commit', $output, $code);
33+
foreach ($output as $line) {
34+
$this->line($line);
35+
}
36+
return $code;
37+
}
38+
}

0 commit comments

Comments
 (0)