Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

spatie-guidelines

БесплатноБез исполняемых скриптовНе проверен

Spatie's PHP, Laravel, JavaScript and Vue coding guidelines and conventions. Use when writing or reviewing PHP, Laravel, JavaScript, or Vue code for Spatie…

freekmurzeот freekmurze★ 1 019 звёзд на GitHub

Об этом скилле

Spatie Guidelines

Apply these guidelines when writing code for Spatie projects or contributing to Spatie packages.

Core principle: write things the way Laravel intended. If Laravel has a documented way to do something, use it. Deviate only with a clear justification.


PHP Style

Type System

  • Type properties, parameters, and return types. Skip docblocks for fully typed methods.
  • Use ?Type (short nullable), not Type|null.
  • Always use the void return type when a method returns nothing.
  • Use constructor property promotion when all properties can be promoted. One per line, trailing comma:
class MyClass {
    public function __construct(
        protected string $firstArgument,
        protected string $secondArgument,
    ) {}
}

Docblocks

  • Skip docblocks for fully type-hinted methods unless you need a description.
  • Use full sentences with a period for descriptions.
  • Always import classnames, then reference the short name in the docblock. Never write a fully qualified name inside a docblock:
use Spatie\Url\Url;

/** @return Url */
  • Use one-line docblocks when possible: /** @var string */
  • Always add types for iterables, specifying both key and value:
/**
 * @param array<int, MyObject> $myArray
 * @param int $typedArgument
 */
function someFunction(array $myArray, int $typedArgument) {}
  • Put the most common type first in a multi-type docblock:
/** @var Collection|SomeWeirdVendor\Collection */
  • Use array shape notation for fixed keys, with each key on its own line:
/** @return array{
    first: SomeClass,
    second: SomeClass
} */
  • If one parameter needs a docblock, add docblocks for all the other parameters too.

Code Style

  • Follow PSR-1, PSR-2, and PSR-12.
  • Use camelCase for non-public-facing strings.
  • Don't use final by default.
  • Prefer string interpolation over concatenation: "Hi, I am {$name}."
  • Enum values use PascalCase: case Diamonds;
  • Each trait on its own line with its own use:
class MyClass
{
    use TraitA;
    use TraitB;
}
  • Always import namespaces with use statements. Never use inline fully qualified class names such as \Exception or \Illuminate\Support\Facades\Http.
  • Never use single-letter variable names. Write $exception instead of $e, $request instead of $r.

Avoid private const

Don't introduce private const. Replace each one:

  • Used once: inline it. When a raw literal would obscure the meaning the name carried, assign it to a descriptively named local variable instead.
  • Used more than once: turn it into a private property. Use private static when the methods using it are static.
  • Referenced from a default parameter value or a PHP attribute, where no property can be used: inline the literal there.

Control Flow

  • Happy path last. Handle failure conditions first and return early.
  • Avoid else. Refactor to early returns or ternaries.
  • Separate compound ifs. Prefer nested if statements over && chains.
  • Always use curly brackets, even for a single statement.
  • Ternary operators: keep each part on its own line unless the expression is very short.
  • Add blank lines between statements so the code can breathe. The exception is a sequence of equivalent single-line operations.
  • No extra empty lines between {} brackets.
// Happy path last
if (! $user) {
    return null;
}

if (! $user->isActive()) {
    return null;
}

// Process active user...

// Short ternary
$name = $isFoo ? 'foo' : 'bar';

// Multi-line ternary
$result = $object instanceof Model ?
    $object->name :
    'A default value';

// Ternary instead of else
$condition
    ? $this->doSomething()
    : $this->doSomethingElse();

// Bad: compound condition with &&
if ($user->isActive() && $user->hasPermission('edit')) {
    $user->edit();
}

// Good: nested ifs
if ($user->isActive()) {
    if ($user->hasPermission('edit')) {
        $user->edit();
    }
}

Comments

Be very critical about adding comments. They often become outdated and mislead over time. Code should be self-documenting through descriptive variable and function names. Adding a comment should never be the first tactic for making code readable.

Instead of this:

// Get the failed checks for this site
$checks = $site->checks()->where('status', 'failed')->get();

Do this:

$failedChecks = $site->checks()->where('status', 'failed')->get();
  • Don't add comments that describe what the code does. Make the code describe itself.
  • Short, readable code doesn't need comments explaining it.
  • Use descriptive variable names instead of generic names plus a comment.
  • Only add a comment to explain why something non-obvious is done, never what is being done.
  • Refactor explanatory comments into descriptively named methods.
  • Never add comments to tests. Test names should be descriptive enough.

Laravel Conventions

Configur

Полный SKILL.md на GitHub

Установить spatie-guidelines в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/javascript.mdreferences/laravel-php.mdreferences/new-project-setup.mdreferences/package-architecture.mdreferences/testing-pest.mdreferences/version-control.md

FAQ

Что делает скилл spatie-guidelines?

Spatie's PHP, Laravel, JavaScript and Vue coding guidelines and conventions. Use when writing or reviewing PHP, Laravel, JavaScript, or Vue code for Spatie projects or packages. Covers code style, type declarations, docblocks, control flow, naming, routing, controllers, Blade, validation, comments, testing (Pest), package structure, service providers, and Git workflow. Triggers include "follow Spatie guidelines", "Spatie style", "Spatie package", or any code review for Spatie packages and projects.

Как установить скилл spatie-guidelines?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл spatie-guidelines запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить spatie-guidelines с