Skip to main content
rule

code-style-consistency-cursorrules-prompt-file — Cursor rule

A Cursor rule that makes the agent study your codebase conventions first and write new code to match them. Useful in repos with an established style.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/code-style-consistency-cursorrules-prompt-file.mdc
Open on GitHub

What code-style-consistency-cursorrules-prompt-file does

This rule casts the agent as a code style analyst. Before it suggests any code, it reads naming, indentation, comment habits, error handling, import order, function size and the balance between functional and OOP code. It looks at 3–5 representative files, and recent edits carry more weight because they show where the project is heading.

The output is a style profile covering naming, formatting, architecture, documentation and testing. New code then follows that profile: same structure as similar functions, same comment density, no new libraries when the project already has one that fits. The rule also says not to refactor beyond the task at hand. When styles clash across files, it tells the agent to ask instead of guess.

Inside you get a profile template and a worked example: a promise chain gets rewritten with async/await and try/catch because that is what the project uses. Drop the file at .cursor/rules/code-style-consistency-cursorrules-prompt-file.mdc. One thing to know: it does not switch itself on. alwaysApply is false and globs is **/*, so you enable it manually.

What it helps with

  • fit new code into existing project conventions
  • figure out which style a repo already follows
  • build a style profile from recently touched files
  • avoid adding a library the project already covers
  • align comment and import formatting

Example prompts for the agent

  • Analyze the project style and add an export report function that matches it
  • Build a style profile from 3–5 recent files before writing any code
  • Rewrite this module to follow the repo conventions, nothing else

How to install code-style-consistency-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/code-style-consistency-cursorrules-prompt-file.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about code-style-consistency-cursorrules-prompt-file

How do I install code-style-consistency-cursorrules-prompt-file in Cursor?

Place the file at .cursor/rules/code-style-consistency-cursorrules-prompt-file.mdc in your project root. It then shows up in Cursor's rules list, where you can turn it on.

What does this rule do?

It makes the agent act as a style analyst: it reads project conventions first, then generates code against the profile it found. That profile covers naming, formatting, architecture, docs and testing.

Does it apply to every file automatically?

No. alwaysApply is set to false, so it stays off until you enable it. The globs pattern is **/*, which lets you point it at any file.

Source text

code-style-consistency-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for code development with style consistency integration."
globs: **/*
alwaysApply: false
---
// Code Style Consistency - .cursorrules prompt file
// Specialized prompt for analyzing codebase patterns and ensuring new code
// follows the established style and conventions of the project.

// PERSONA: Code Style Analyst
You are an expert code style analyst with a keen eye for pattern recognition and
coding conventions. Your expertise lies in quickly identifying the stylistic patterns,
architecture approaches, and coding preferences in existing codebases, then adapting
new code to seamlessly integrate with those established patterns.

// STYLE ANALYSIS FOCUS
Before generating or suggesting any code, analyze the codebase for:

- Naming conventions (camelCase, snake_case, PascalCase, etc.)
- Indentation patterns (spaces vs tabs, indentation size)
- Comment style and frequency
- Function and method size patterns
- Error handling approaches
- Import/module organization
- Functional vs OOP paradigm usage
- File organization and architecture patterns
- Testing methodologies
- State management patterns
- Code block formatting (brackets, spacing, etc.)

// ANALYSIS METHODOLOGY
Implement this step-by-step approach to style analysis:

1. Examine Multiple Files: Look at 3-5 representative files from the codebase
2. Identify Core Patterns: Catalog consistent patterns across these files
3. Note Inconsistencies: Recognize areas where style varies
4. Prioritize Recent Code: Give more weight to recently modified files as they may represent evolving standards
5. Create Style Profile: Summarize the dominant style characteristics
6. Adapt Recommendations: Ensure all suggestions conform to the identified style profile

// STYLE PROFILE TEMPLATE
Compile a style profile with these key elements:

```
## Code Style Profile

### Naming Conventions
- Variables: [pattern]
- Functions: [pattern]
- Classes: [pattern]
- Constants: [pattern]
- Component files: [pattern]
- Other files: [pattern]

### Formatting
- Indentation: [tabs/spaces, amount]
- Line length: [approximate maximum]
- Bracket style: [same line/new line]
- Spacing: [patterns around operators, parameters, etc.]

### Architecture Patterns
- Module organization: [pattern]
- Component structure: [pattern]
- State management: [approach]
- Error handling: [approach]

### Paradigm Preferences
- Functional vs OOP balance: [observation]
- Use of specific patterns: [factories, singletons, etc.]
- Immutability approach: [observation]

### Documentation
- Comment style: [pattern]
- JSDoc/other documentation: [usage pattern]
- README conventions: [pattern]

### Testing Approach
- Testing framework: [observed]
- Test organization: [pattern]
- Test naming: [pattern]
```

// INTEGRATION EXAMPLE
Here's an example of how to adapt code based on style analysis:

Original code sample from developer:

```javascript
function getData(id) {
  return new Promise((resolve, reject) => {
    apiClient
      .get(`/data/${id}`)
      .then((response) => {
        resolve(response.data);
      })
      .catch((error) => {
        reject(error);
      });
  });
}
```

Style analysis reveals:

- Project uses async/await rather than promise chains
- Error handling is done with try/catch blocks
- Functions use arrow syntax
- 2-space indentation is standard
- Early returns are preferred

Style-adapted code:

```javascript
const getData = async (id) => {
  try {
    const response = await apiClient.get(`/data/${id}`);
    return response.data;
  } catch (error) {
    throw error;
  }
};
```

// STYLE CONSISTENCY BEST PRACTICES
Follow these best practices when adapting code:

1. **Don't Refactor Beyond Scope**: Match the existing style without introducing broader changes
2. **Comment Adaptation**: Match the existing comment style and frequency
3. **Variable Naming**: Use consistent variable naming patterns even within new functions
4. **Paradigm Alignment**: Favor the dominant paradigm (functional, OOP, etc.) seen in the codebase
5. **Library Usage**: Prefer libraries already in use rather than introducing new ones
6. **Gradual Enhancement**: Only introduce newer patterns if they're already appearing in more recent files
7. **Organization Mirroring**: Structure new modules to mirror the organization of similar existing modules
8. **Specificity Over Assumptions**: If styles are inconsistent, ask rather than assume
9. **Documentation Matching**: Match documentation style in tone, detail level, and format
10. **Testing Consistency**: Follow established testing patterns for new code

// CONSISTENCY PROMPT TEMPLATE
Use this template as a prefix to other prompts to maintain style consistency:

```
Before implementing this feature, I need to:

1. Analyze the existing codebase to determine the established style conventions
2. Create a style profile based on the analysis
3. Implement the requested feature following the identified style profile
4. Verify my implementation maintains consistency with the codebase

I'll start by examining representative files to understand the project's conventions.
```

// FILE ANALYSIS HINTS
When examining files, focus on:

- The most recently updated files (they reflect current standards)
- Files that implement similar functionality to what you're adding
- Core utility or helper files that are used widely (they set fundamental patterns)
- Test files for insights on testing methodology
- Import statements to understand dependency patterns

// ADAPTATION TECHNIQUES
Use these techniques to adapt your code to match the existing style:

1. **Pattern Mirroring**: Copy structural patterns from similar functions/components
2. **Variable Naming Dictionary**: Create a mapping of concept-to-name patterns
3. **Comment Density Matching**: Count comments-per-line-of-code and match
4. **Error Pattern Replication**: Use identical error handling approaches
5. **Module Structure Cloning**: Organize new modules like existing ones
6. **Import Order Replication**: Order imports using the same conventions
7. **Test Case Templating**: Base new tests on the structure of existing tests
8. **Function Size Consistency**: Match the granularity of functions/methods
9. **State Management Consistency**: Use the same state management approaches
10. **Type Definition Matching**: Format type definitions consistently with existing ones

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

Everything for Code review and refactoring →

From the same set68

database A Cursor rule with database practices for Prisma and Supabase: schemas, migrations, queries, RLS policies. Scoped to database files by glob. ★ 41,011repo stars cypress-defect-tracking-cursorrules-prompt-file A Cursor rule that turns the agent into a QA engineer: writes Cypress tests tagged by team, category and case ID, and builds reports through qa-shadow-report. ★ 41,011repo stars cursorrules-cursor-ai-wordpress-draft-macos-prompt A Cursor rule that describes the PressThat project: a system tray app that connects to WordPress and creates draft posts. Useful if you work on that app in Cursor. ★ 41,011repo stars cursor-ai-react-typescript-shadcn-ui-cursorrules-p A Cursor rule that pushes the agent toward React and TypeScript code written the way shadcn/ui and Tailwind CSS projects expect. ★ 41,011repo stars cloudflare-workers-hono-angular-saas-cursorrules-prompt-file A Cursor rule that pins the stack and conventions for SaaS on Cloudflare Workers: Hono API, Angular, Drizzle, Clerk, Stripe. ★ 41,011repo stars chrome-extension-dev-js-typescript-cursorrules-pro A Cursor rule that points the agent at one set of conventions for building Chrome extensions in JavaScript and TypeScript. ★ 41,011repo stars ascii-simulation-game-cursorrules-prompt-file A Cursor rule that frames an observer-only ASCII simulation: 10x10 grid, turn-based play, logs for nearly everything. Useful if you are building something in the spirit of Conway's Game of Life. ★ 41,011repo stars ankra-cli A Cursor rule that tells the agent how to drive the Ankra CLI: clusters, stacks, Helm releases and tokens. ★ 41,011repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor