/craft:code-style-principlesfrom craft
Provides cross-language code-style rules covering control-structure spacing, early-return patterns, explicit checks, and null-conditional flattening. Activates during code review or when writing/editing production code.
Ships in craft. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The rules below are language-agnostic. Syntax-specific examples (nullsafe
?->, optional chaining?., no-empty(), nowdoc, template literals) live in:
php-code-conventionsts-code-conventions
These conventions go beyond standard linters (PSR-12/PER, eslint/prettier). They encode the project's house style.
Always add a blank line before AND after control structures (if, for, foreach/for...of, while, switch) when they are not at the start or end of the enclosing block.
Exception: no blank line at start or end of a method/function/block.
Why: visual separation between sequential statements and branching/looping logic.
Always use early return to handle edge cases and invalid conditions first. Main logic stays at base indentation.
return when preceded by other statements.continue in a loop is the equivalent of early-return in a function.
continue only when the exit condition is simple and the main processing is more complex.if/else for readability.continue / return / break / throw when preceded by other statements.Replace nested null-guards with the language's null-propagation operator (PHP: ?->, TS: ?., Kotlin: ?., Swift: ?.).
For absent values with a default, use the null-coalescing operator (PHP: ??, TS: ??, …).
Criterion: if you nest more than one if (x !== null), use null-propagation.
Use explicit comparisons instead of relying on language coercion.
=== [], .length > 0) — not truthy.'' (or use length).null / undefined explicitly.Exception: booleans can be checked directly (if (isValid)).
Why: implicit truthy/falsy hides type bugs and gives unstable results across languages (and even across the same language: PHP empty(), JS coercion).
Constructors / function signatures: mandatory parameters before optional / nullable.
Within each group, the language's natural ordering applies (e.g. promoted properties in PHP, default values in TS).
Write a comment only when the code cannot speak for itself. A comment earns its place if it surfaces something the code does not:
!important / specificity hack, an ordering constraint.Delete any comment that restates the code without adding value:
// AVOID — reproduces the code
// Uppercase the IBAN and strip whitespace
return strtoupper(preg_replace('/\s+/', '', $iban));
// AVOID — restates the name
/** Extra HTML attributes applied to the wrapper. */
public array $wrapperAttributes = [];
// CORRECT — surfaces a non-obvious rule
// !important: beat Bootstrap's :valid border (empty boxes are HTML5-valid)
border-color: $danger !important;
Type annotations are not prose comments: keep @var / @return / @param when they add type information a tool or reader needs — they are not subject to this rule.
Heuristic: if deleting the comment loses no information a competent reader couldn't get from the code in seconds, delete it.
Extract a private or local helper as soon as a function's body no longer fits in one glance.
Measure: no function body exceeds 25 executable lines, blank lines and comments excluded.
| Rule | Principle |
|---|---|
| Control-structure spacing | Blank line before AND after if/for/while/switch (except start/end of block) |
| Early return | Edge cases first, main logic at base indentation |
| Continue vs if/else | continue only when exit is simple and main is complex |
| Flatten null checks | Use null-propagation operator instead of nested if |
| Explicit checks | No implicit truthy/falsy — compare to empty / null explicitly |
| Parameter ordering | Mandatory before optional |
| Comments | Only for hidden complexity / business rule; delete anything that restates the code |
| Function length | Extract a helper past 25 executable lines |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub fabiensalles/claude-marketplace --plugin craft8 skills in this plugin
/ddd-fp-principlesACTIVATE when modeling DDD aggregates, value objects and domain logic using functional patterns — immutable records, curried operations, Result types, validation/enrichment pipelines, handler orchestration. ACTIVATE for 'aggregate', 'smart constructor', 'make*', 'validation pipeline', 'enrichment', 'domain handler' in a functional context. Provides cross-language functional DDD principles. For OOP-style DDD (classes, decorators, module-bounded contexts) see craft:ddd-principles. Companion examples: ddd-ts-fp./ddd-principlesACTIVATE when designing the domain layer in OOP languages — bounded contexts, aggregates, value objects, layer purity, ports/adapters, dependency direction. ACTIVATE for 'domain', 'DDD', 'hexagonal', 'ports and adapters', 'domain purity', 'bounded context', 'aggregate'. Provides cross-language OOP-style DDD principles. For functional-style DDD (immutable records, smart constructors, pipelines) see craft:ddd-fp-principles. Language-specific examples live in php-ddd-conventions, nest-ddd-conventions./oop-principlesACTIVATE when designing classes, and the value objects or collections modelled as classes, or when the user asks about object design, encapsulation, or 'Tell Don't Ask' across languages. Covers cross-language OOP principles: Tell Don't Ask, collection over named properties, Whole Object pattern, iterable collections, self-describing value objects. Language-specific examples and constructs (IteratorAggregate, Symbol.iterator, branded types) live in companion skills (php-oop, ts-oop). DO NOT use for: a value object or an aggregate modelled as an immutable record with functions over it rather than as a class (see craft:ddd-fp-principles).