Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

code-style-principles

/code-style-principles

Stosuje bazowe zasady stylu kodu produkcyjnego w src/: odstępy przy strukturach sterujących, wczesny return, jawne sprawdzenia zamiast truthy/falsy, spłaszczanie zagnieżdżonych null checków i kolejność parametrów.

Licencja
MIT
Ostatnia zmiana repozytorium
12.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 12.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Stosuje bazowe zasady stylu kodu produkcyjnego w src/: odstępy przy strukturach sterujących, wczesny return, jawne sprawdzenia zamiast truthy/falsy, spłaszczanie zagnieżdżonych null checków i kolejność parametrów.

Wyzwalacze z opisu

coding standards
Oryginalny opis (EN)

ACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, wh

Jak działa

  1. 1. Control-Structure Spacing
  2. 2. Early-Return Pattern
  3. 3. If-Continue Pattern in Loops
  4. 4. Flatten Nested Null Checks
  5. 5. Explicit Checks Over Implicit Truthy/Falsy
  6. 6. Parameter Ordering
  7. 7. Comments — Justify or Delete
  8. 8. Function Length
  9. Quick Reference
Sekcje z nagłówków SKILL.md, w oryginale · 108 linii, 728 słów
Podgląd SKILL.md
---
name: code-style-principles
description: "ACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, which apply on top of this skill rather than instead of it. DO NOT use for: language-specific syntax already covered by php-code-conventions / ts-code-conventions (see php:php-code-conventions + typescript:ts-code-conventions for PHP/TS specifics)."
---

# Code Style — Cross-Language Principles

> The **rules** below are language-agnostic. Syntax-specific examples (nullsafe `?->`, optional chaining `?.`, no-`empty()`, nowdoc, template literals) live in:
> - `php-code-conventions`
> - `ts-code-conventions`

These conventions go **beyond** standard linters (PSR-12/PER, eslint/prettier). They encode the project's house style.

## 1. Control-Structure Spacing

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.

## 2. Early-Return Pattern

Always use early return to handle edge cases and invalid conditions **first**. Main logic stays at base indentation.

- Reduces nesting.
- Clarifies intent (edge cases handled upfront).
- Add a blank line **before** the `return` when preceded by other statements.

## 3. If-Continue Pattern in Loops

`continue` in a loop is the equivalent of early-return in a function.

- Use `continue` **only** when the exit condition is simple and the main processing is more complex.
- When both branches have comparable complexity, prefer a classic `if/else` for readability.
- Add a blank line **before** `continue` / `return` / `break` / `throw` when preceded by other statements.

## 4. Flatten Nested Null Checks

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.

## 5. Explicit Checks Over Implicit Truthy/Falsy

Use **explicit** comparisons instead of relying on language coercion.

- Arrays / collections: compare to empty (`=== []`, `.length > 0`) — not truthy.
- Strings: compare to `''` (or use length).
- Null/undefined: compare to `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).

## 6. Parameter Ordering

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).

## 7. Comments — Justify or Delete

Write a comment **only** when the code cannot speak for itself. A comment earns its place if it surfaces something the code does **not**:

- **Hidden complexity** — a non-obvious algorithm, a workaround, a `!important` / specificity hack, an ordering constraint.
- **Business / domain rule** — the *why* behind a magic value or branch (e.g. "French IBAN length = 27").
- **A decision that would otherwise look wrong** — why a line is disabled, why a framework default is overridden.

Delete any comment that **restates the code** without adding value:

```php
// 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 = [];
```

```php
// 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.

## 8. Function Length

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.

## Quick Reference

| 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 |

Wersje

W bazie nie ma innych skilli o nazwie code-style-principles.

Migawka bazy z 13.11.2026 · wersja paczki 6f55946a774e (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95ts-code-conventions
    Podpowiada konwencje stylu kodu TypeScript w katalogu src: optional chaining, nullish coalescing, szablony tekstowe i unikanie truthy/falsy.
  • 100php-code-conventions
    Stosuje konwencje stylu PHP przy pisaniu kontrolerów, serwisów i repozytoriów, z regułami dla operatora nullsafe i nowdoc.
  • 100php-coding-standards
    Pilnuje standardów kodowania PHP w repozytoriach Nette: tabulatory, apostrofy, strict_types i kolejność importów.
  • 100python-code-style
    Ustala styl kodu Python: linting, formatowanie, nazewnictwo i docstringi, przy pisaniu nowego kodu, przeglądzie stylu i konfiguracji linterów.
  • 95csharp-style
    Stosuje konwencje C# przy pisaniu, przeglądzie i refaktoryzacji plików .cs, w tym dokumentację XML i wzorce Unity.
  • 100review-local
    Przegląda lokalny diff php-src względem standardów PHP i zapisuje raport REVIEW.md, bez zmian w kodzie ani stanie gita.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.