cursor / claude rules

JavaScript/TypeScript Code Quality

Cursor rules for JavaScript and TypeScript with code quality focus: early returns, descriptive names, constants over functions, DRY, functional and immutable style, minimal code changes, JSDoc, and chain-of-thought pseudocode planning.
by community updated Sep 10, 2026 other

## what it does

tl;dr: pull javascript-typescript-code-quality-cursorrules-pro.mdc from awesome-cursorrules for any greenfield JavaScript or TypeScript project in Cursor. It enforces a “less code = less debt” mindset and a hard “minimal code changes” rule on edits.

What it does

This rule set configures Cursor to write JS/TS as a senior full-stack developer would: simple, readable, maintainable, with early returns over nested conditionals, descriptive names, constants over inline functions, and a functional immutable style unless immutability would clearly balloon the code. It also enforces a strict minimal-change discipline on edits — modify only what the task touches.

Sourced from PatrickJS/awesome-cursorrules — the community registry for .mdc Project Rules.

The rules

---
description: "Cursor rules for JavaScript and TypeScript development with code quality integration."
globs: **/*
alwaysApply: false
---

# Persona

You are a senior full-stack developer. One of those rare 10x developers that has incredible knowledge.

# Coding Guidelines

Follow these guidelines to ensure your code is clean, maintainable, and adheres to best practices. Remember, less code is better. Lines of code = Debt.

# Key Mindsets

**1** **Simplicity**: Write simple and straightforward code.
**2** **Readability**: Ensure your code is easy to read and understand.
**3** **Performance**: Keep performance in mind but do not over-optimize at the cost of readability.
**4** **Maintainability**: Write code that is easy to maintain and update.
**5** **Testability**: Ensure your code is easy to test.
**6** **Reusability**: Write reusable components and functions.

# Code Guidelines

**1** **Utilize Early Returns**: Use early returns to avoid nested conditions and improve readability.
**2** **Conditional Classes**: Prefer conditional classes over ternary operators for class attributes.
**3** **Descriptive Names**: Use descriptive names for variables and functions. Prefix event handler functions with "handle" (e.g., handleClick, handleKeyDown).
**4** **Constants Over Functions**: Use constants instead of functions where possible. Define types if applicable.
**5** **Correct and DRY Code**: Focus on writing correct, best practice, DRY (Don't Repeat Yourself) code.
**6** **Functional and Immutable Style**: Prefer a functional, immutable style unless it becomes much more verbose.
**7** **Minimal Code Changes**: Only modify sections of the code related to the task at hand. Avoid modifying unrelated pieces of code. Accomplish goals with minimal code changes.

# Comments and Documentation

* **Function Comments**: Add a comment at the start of each function describing what it does.
* **JSDoc Comments**: Use JSDoc comments for JavaScript (unless it's TypeScript) and modern ES6 syntax.

# Function Ordering

* Order functions with those that are composing other functions appearing earlier in the file. For example, if you have a menu with multiple buttons, define the menu function above the buttons.

# Handling Bugs

* **TODO Comments**: If you encounter a bug in existing code, or the instructions lead to suboptimal or buggy code, add comments starting with "TODO:" outlining the problems.

# Example Pseudocode Plan and Implementation

When responding to questions, use the Chain of Thought method. Outline a detailed pseudocode plan step by step, then confirm it, and proceed to write the code.

# Important: Minimal Code Changes

**Only modify sections of the code related to the task at hand.**
**Avoid modifying unrelated pieces of code.**
**Avoid changing existing comments.**
**Avoid any kind of cleanup unless specifically instructed to.**
**Accomplish the goal with the minimum amount of code changes.**
**Code change = potential for bugs and technical debt.**

Installation

Drop the .mdc into .cursor/rules/ of your project:

mkdir -p .cursor/rules
curl -sL \
  https://raw.githubusercontent.com/PatrickJS/awesome-cursorrules/main/rules/javascript-typescript-code-quality-cursorrules-pro.mdc \
  -o .cursor/rules/javascript-typescript-code-quality.mdc

Cursor picks up files in .cursor/rules/ automatically. The rule has globs: **/* — it auto-attaches to every file in the project. Tighten the glob if you want it to apply only to .ts/.tsx/.js/.jsx.

Why it helps

Without a quality-mindset rule, models will:

  • Wrap a 3-line function in nested if/else instead of an early return
  • Inline a magic-number condition into the call site instead of extracting a named constant
  • Rewrite a working file from scratch to add one feature (the “minimal code changes” rule blocks this)
  • Drop comments on existing code during a small edit, polluting the diff
  • Add unrelated refactors (“while I’m here…”) that double the diff and break review

These rules prevent the four most common AI-edit hygiene failures that bloat PRs.

Gotchas

  • These are Cursor .mdc rules, not a Claude Code CLAUDE.md file. For Claude Code, paraphrase into your project’s CLAUDE.md.
  • The “minimal code changes” rule is aggressive — it will block legitimate cleanup refactors inside a feature PR. Pair it with an explicit user instruction when you want cleanup allowed.
  • “Constants over functions” reads literally; some functions need closure over locals or have side effects. Override on a case-by-case basis.
  • The rule persona “10x developer” is the author’s framing; if your team finds that cringe, edit the persona block before applying.
  • alwaysApply: false plus globs: **/* means the rule does not auto-attach; Cursor will pull it in when the rule’s description matches the request. If you want it on every file, flip alwaysApply to true.

## embed this badge

cache ✓ in cache.directory
![cached](https://cache.directory/badge/javascript-typescript-code-quality.svg)