Index of every page on this site: llms.txt
All skills
grahamcrackers avatar

/clean-code-principles

@ca83de4
Run it yourself

Clean code principles for readable, maintainable TypeScript and React codebases. Covers naming, functions, abstraction, composition, error handling, comments, and code smells. Use when writing new code, refactoring, reviewing code quality, or when the user asks about clean code, readability, or maintainability.

Use this Skill: https://skilld.dev/gh/grahamcrackers/skills/clean-code-principles

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencespattern-prototype.md

≈932 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Prototype

Prototype copies existing objects without coupling to their specific classes. Objects can clone themselves, including nested objects and circular references. Learn more

Category: Creational

TypeScript Example

/**
 * The example class that has cloning ability. We'll see how the values of field
 * with different types will be cloned.
 */
class Prototype {
    public primitive: any;
    public component: object;
    public circularReference: ComponentWithBackReference;

    public clone(): this {
        const clone = Object.create(this);

        clone.component = Object.create(this.component);

        // Cloning an object that has a nested object with backreference
        // requires special treatment. After the cloning is completed, the
        // nested object should point to the cloned object, instead of the
        // original object. Spread operator can be handy for this case.
        clone.circularReference = new ComponentWithBackReference(clone);

        return clone;
    }
}

class ComponentWithBackReference {
    public prototype;

    constructor(prototype: Prototype) {
        this.prototype = prototype;
    }
}

/**
 * The client code.
 */
function clientCode() {
    const p1 = new Prototype();
    p1.primitive = 245;
    p1.component = new Date();
    p1.circularReference = new ComponentWithBackReference(p1);

    const p2 = p1.clone();
    if (p1.primitive === p2.primitive) {
        console.log("Primitive field values have been carried over to a clone. Yay!");
    } else {
        console.log("Primitive field values have not been copied. Booo!");
    }
    if (p1.component === p2.component) {
        console.log("Simple component has not been cloned. Booo!");
    } else {
        console.log("Simple component has been cloned. Yay!");
    }

    if (p1.circularReference === p2.circularReference) {
        console.log("Component with back reference has not been cloned. Booo!");
    } else {
        console.log("Component with back reference has been cloned. Yay!");
    }

    if (p1.circularReference.prototype === p2.circularReference.prototype) {
        console.log("Component with back reference is linked to original object. Booo!");
    } else {
        console.log("Component with back reference is linked to the clone. Yay!");
    }
}

clientCode();

Output

Primitive field values have been carried over to a clone. Yay!
Simple component has been cloned. Yay!
Component with back reference has been cloned. Yay!
Component with back reference is linked to the clone. Yay!

Also Known As

Clone

Real-World Example

A document editor where users can duplicate existing templates or pages. Cloning preserves all settings without re-configuring from scratch.

interface Cloneable<T> {
    clone(): T;
}

class PageTemplate implements Cloneable<PageTemplate> {
    constructor(
        public title: string,
        public layout: string,
        public styles: Record<string, string>,
    ) {}

    clone(): PageTemplate {
        return new PageTemplate(this.title, this.layout, { ...this.styles });
    }
}

const blogTemplate = new PageTemplate("Blog Post", "single-column", { fontSize: "16px", color: "#333" });
const newPage = blogTemplate.clone();
newPage.title = "My First Post";

When NOT to Use

  • When objects are simple and cheap to create from scratch
  • When deep cloning is complex (circular references, closures, DOM nodes)
  • When object creation involves side effects (API calls, subscriptions) that shouldn't be duplicated
  • In most frontend code, plain object spread ({ ...obj }) or structuredClone() is sufficient

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning9mo4 checks · Risk SAFE
  • Gen Agent Trust Hub9mo

    This skill is a comprehensive documentation library for clean code principles and design patterns in TypeScript and React. It contains no executable code, network operations, or security risks.

  • Socket9mo

    No alerts

  • Snyk9mo

    Risk: LOW · No issues

  • Runlayer9mo

    1/25 files flagged

Signed by skilld at ca83de4. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 9 months ago

README badge

README badge for grahamcrackers/skills/clean-code-principles