Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
ganyicz authored and github-actions[bot] committed Oct 8, 2022
1 parent 2acc809 commit 8f7bd92
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/Commands/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class LintCommand extends Command
{
public $signature = 'rockero:lint {--json}';

public $description = 'Run linter';

public function handle(): int
Expand All @@ -19,7 +20,7 @@ public function handle(): int
Linter::collect()->whenNotEmpty(function (Collection $errors) {
$this->output->write($errors->toJson());
});

return self::SUCCESS;
}

Expand All @@ -34,7 +35,7 @@ public function handle(): int
});

if ($errors > 0) {
$this->output->error($errors . ' ' . Str::plural('problem', $errors) . ' found');
$this->output->error($errors.' '.Str::plural('problem', $errors).' found');

return self::INVALID;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Linting/LintError.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public function __construct(
readonly public string $file,
readonly public int $line,
readonly public string $message,
) {
) {
}
}
23 changes: 8 additions & 15 deletions src/Linting/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Rockero\StarterKit\Linting\LintError;
use RuntimeException;
use Symfony\Component\Process\Process;

class Linter
{
/**
* Eager load all errors into a collection.
*
*
* @return Collection<LintError>
*/
public static function collect(): Collection
Expand All @@ -26,35 +25,29 @@ public static function collect(): Collection

/**
* Lazily execute a callback over each error.
*
* @param callable(LintError) $callback
*
* @param callable(LintError) $callback
*/
public static function run($callback): void
{
/**
* Parse tlint output similar to:
*
*
* Lints for /User/rockero/www/laravel/app/Models/User.php
* =======
* ! Imports should be ordered alphabetically.
* 5 : `use Illuminate\Notifications\Notifiable;`
* 6 : `use Illuminate\Foundation\Auth\User as Authenticatable;`
*
*/

$file = '';
$message = '';

self::readOutput(function ($line) use (&$file, &$message, $callback) {
if (Str::startsWith($line, 'Lints for')) {
$file = Str::after($line, 'Lints for ' . base_path() . '/');
}

elseif (Str::startsWith($line, '!')) {
$file = Str::after($line, 'Lints for '.base_path().'/');
} elseif (Str::startsWith($line, '!')) {
$message = Str::after($line, '! ');
}

elseif ($line = Str::match('/^(\d+)/', $line)) {
} elseif ($line = Str::match('/^(\d+)/', $line)) {
$callback(new LintError($file, (int) $line, $message));
}
});
Expand All @@ -67,7 +60,7 @@ private static function readOutput(callable $callback): void
{
$process = Process::fromShellCommandline('./vendor/bin/tlint');
$output = '';

$process->setTimeout(null)->run(function ($type, $buffer) use ($callback, &$output) {
$lines = explode("\n", $buffer);

Expand Down
6 changes: 3 additions & 3 deletions src/StarterKitServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public function boot()
parent::boot();

$this->publishes([
__DIR__ . '/../stubs/tlint.stub' => $this->app->basePath('tlint.json'),
__DIR__ . '/../stubs/pint.stub' => $this->app->basePath('pint.json'),
__DIR__ . '/../stubs/phpstan.stub' => $this->app->basePath('phpstan.neon'),
__DIR__.'/../stubs/tlint.stub' => $this->app->basePath('tlint.json'),
__DIR__.'/../stubs/pint.stub' => $this->app->basePath('pint.json'),
__DIR__.'/../stubs/phpstan.stub' => $this->app->basePath('phpstan.neon'),
], );
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function setUp(): void
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'Rockero\\StarterKit\\Database\\Factories\\' . class_basename($modelName) . 'Factory'
fn (string $modelName) => 'Rockero\\StarterKit\\Database\\Factories\\'.class_basename($modelName).'Factory'
);
}

Expand Down

0 comments on commit 8f7bd92

Please sign in to comment.