machichdigital

IDE-Tools · Foto: Homedust, CC BY 2.0

RegelCursor RulesLizenz: CC0 1.0frei kopierbar

Clean Code

Zuletzt aktualisiert:

⬇ Als Datei laden

⧉ –× kopiert⬇ –× heruntergeladenBewertung:

Typ

Regel

Lizenz

CC0 1.0

Anwendungsfeld

Cursor Rules

Voraussetzungen

Keine besonderen — direkt loslegen.

Cursor-Regel für kurze Funktionen, klare Namen und keine Code-Duplikation — sprachübergreifend nutzbar.

Original-Beschreibung der Autoren: Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing or reviewing code to ensure consistency and quality.

Die Regel

---
description: Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing or reviewing code to ensure consistency and quality.
globs: ["**/*"]
alwaysApply: false
---
# Clean Code Guidelines

## Constants Over Magic Numbers
- Replace hard-coded values with named constants
- Use descriptive constant names that explain the value's purpose
- Keep constants at the top of the file or in a dedicated constants file

## Meaningful Names
- Variables, functions, and classes should reveal their purpose
- Names should explain why something exists and how it's used
- Avoid abbreviations unless they're universally understood

## Smart Comments
- Don't comment on what the code does - make the code self-documenting
- Use comments to explain why something is done a certain way
- Document APIs, complex algorithms, and non-obvious side effects

## Single Responsibility
- Each function should do exactly one thing
- Functions should be small and focused
- If a function needs a comment to explain what it does, it should be split

## DRY (Don't Repeat Yourself)
- Extract repeated code into reusable functions
- Share common logic through proper abstraction
- Maintain single sources of truth

## Clean Structure
- Keep related code together
- Organize code in a logical hierarchy
- Use consistent file and folder naming conventions

## Encapsulation
- Hide implementation details
- Expose clear interfaces
- Move nested conditionals into well-named functions

## Code Quality Maintenance
- Refactor continuously
- Fix technical debt early
- Leave code cleaner than you found it

## Testing
- Write tests before fixing bugs
- Keep tests readable and maintainable
- Test edge cases and error conditions

## Version Control
- Write clear commit messages
- Make small, focused commits
- Use meaningful branch names

So nutzt du sie

Die Regel kopieren (Button oben) oder als Datei herunterladen und im Projekt unter .cursor/rules/ ablegen — Cursor lädt sie beim nächsten Start automatisch. Ältere Cursor-Versionen lesen alternativ eine einzelne .cursorrules-Datei im Projektstamm; dort einfach den Regel-Text ohne den Kopfblock zwischen den ----Zeilen einfügen.

Der Regel-Text ist englisch — Cursor versteht ihn unabhängig von der Sprache, in der Sie mit dem Editor chatten.

Im Detail

Diese Cursor-Regel (CC0-Lizenz, frei nutzbar) legt bei jeder Code-Generierung Clean-Code-Prinzipien fest: kurze Funktionen mit einer Aufgabe, sprechende Namen statt Abkürzungen, keine Duplikation (DRY) und flache Verschachtelung. Anders als generische Style-Guides ist sie sprachunabhängig formuliert und lässt sich in jedes Projekt kopieren, ohne Linter-Konfiguration anzupassen. Der Nutzen zeigt sich vor allem in Teams, die viel KI-generierten Code reviewen: Cursor hält sich beim Vorschlagen und Refactoring automatisch an die Prinzipien, statt sie nur auf Nachfrage anzuwenden. Wer bereits einen strikten Linter (ESLint, Ruff) fährt, bekommt hier eher eine Denkweise als zusätzliche technische Durchsetzung.

Praxis-Tipp

Legen Sie die Regel als projekt-globale .cursor/rules-Datei ab, damit sie bei jedem Prompt automatisch aktiv ist — z. B. bei „Refactor diese Funktion“ wendet Cursor dann automatisch das Single-Responsibility-Prinzip an.

Siehe auch

Lizenz & Quelle

Inhalt ansehen (clean-code.mdc)
Lade …

Erfahrungen & Kommentare.

Funktioniert der Regel bei Ihnen? Tipps, Stolperfallen, Varianten — teilen Sie es mit der Community.

Lade Kommentare …

Ihre IP-Adresse wird zum Schutz vor Missbrauch gespeichert und nach 14 Tagen automatisch entfernt (Datenschutz).

Passt dazu.