Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collectionWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/refactoring)<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/refactoring"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/refactoring/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/refactoring"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/refactoring.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00683 | $0.00683 |
| Opus 5.5 | $0.00273 | $0.00273 |
| Sonnet 5.5 | $0.00137 | $0.00137 |
| Haiku 4.5 | $0.00068 | $0.00068 |
Grade A, and why
refactoring scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
Copies of this mod
1 near-identical copy found in the catalogue:
- refactoring — 100% identical, 0 lines differ
How it starts
The opening of the file, as written. The whole thing — 80 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Refactoring Cursor Rules
You are an expert in systematic code refactoring. Follow these rules:
Before Refactoring
- Ensure tests exist for the code being refactored — no tests, no refactoring
- Run the full test suite before starting — establish a green baseline
- Commit the current state before making any changes
- Identify the specific code smell you're fixing — don't refactor "just because"
Guard Clauses & Early Returns
- Replace nested if/else with early returns for error cases
- Check preconditions at the top of the function, return/throw early
- Each guard clause should handle one condition — not compound boolean expressions
- After all guards pass, the main logic runs at the base indentation level
// ❌ Nested
function process(user) {
if (user) {
if (user.isActive) {
if (user.hasPermission) {
// actual logic buried 3 levels deep
}
}
}
}
// ✅ Guard clauses
function process(user) {
if (!user) throw new Error('User required');
if (!user.isActive) return;
if (!user.hasPermission) throw new ForbiddenError();
// actual logic at base level
}
Extract Function/Method
- Extract when a code block needs a comment explaining what it does — the function name IS the comment
- Extracted functions should do one thing and be nameable with a verb phrase
- Pass only what the extracted function needs — not the entire context/object
- If you extract and the original function is just a list of calls, that's good — it reads like a plan
Inline
- Inline when a function/variable adds indirection without clarity
- Inline temporary variables that are used once and the expression is clear
- Inline trivial delegating functions that just call another function
Rename
- Rename when the name doesn't match what the code does (after behavior changes)
- Use find-all-references, not find-and-replace — catch all usages including types
- Rename in a separate commit from behavior changes
Simplify Conditionals
- Replace complex boolean expressions with named boolean variables or functions
- Use De Morgan's laws to simplify negated compound conditions
- Replace switch/case with object lookup when mapping values
- Replace type-checking conditionals with polymorphism when the pattern repeats
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 80 lines · 683 tokens per session scan A c5c297793cbe
refactoring is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (38 stars, last pushed 7mo ago), licensed MIT. It adds 683 tokens to every session, about $0.0027 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other cursor rules, from other repositories
tdd
Test-driven development — red-green-refactor cycle.
07-testing
Cursor rule "07-testing" from orbitalsonic/AndroidPilot, covering testing, architecture, prefer, unit testing and scope.
webdriver-management
Selenium WebDriver lifecycle management — driver factory, explicit waits, browser options, and teardown.
api-testing
Cypress network interception and API testing patterns (cy.intercept, service mocking, request/response validation).
test-patterns
Selenium pytest test patterns — data-driven tests, fixtures, error handling, and performance checks.
testing-fundamentals
Core Cypress testing principles — selector strategy, smart waiting, and spec organization. Apply when writing or reviewing Cypress E2E tests.