Skip to content

Commit 52bacc0

Browse files
authored
Do a regression testing for all Cursor rules based on XML (#165)
* Updated design * Updating the rules * Update examples
1 parent c7b5fbb commit 52bacc0

45 files changed

Lines changed: 1104 additions & 382 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cursor/rules/110-java-maven-best-practices.mdc

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: Maven Best Practices
3-
globs: pom.xml
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Maven Best Practices
@@ -11,7 +11,34 @@ You are a Senior software engineer with extensive experience in Java software de
1111

1212
## Goal
1313

14-
Update the pom.xml based on the following rules about Maven best practices.
14+
Analyze `pom.xml` files to identify Maven best practices improvement opportunities and present actionable alternatives to the user. When you encounter Maven POM files:
15+
16+
1. **Analyze** the POM for Maven best practices issues using the principles and examples below
17+
2. **Identify** the most impactful improvements (dependency management, plugin configuration, build profiles, version management)
18+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19+
4. **Ask** the user which improvement they'd like to implement
20+
5. **Wait** for user choice before making any changes
21+
22+
**Example interaction:**
23+
```
24+
🔍 I found 3 Maven best practices improvements in this POM:
25+
26+
1. **CRITICAL: Hardcoded Dependency Versions**
27+
- Problem: Dependencies have hardcoded versions scattered throughout the POM
28+
- Solutions: A) Move to properties section B) Use dependencyManagement C) Import BOM files
29+
30+
2. **MAINTAINABILITY: Missing Plugin Version Management**
31+
- Problem: Maven plugins lack explicit version declarations
32+
- Solutions: A) Add pluginManagement section B) Define plugin versions in properties C) Use parent POM approach
33+
34+
3. **ORGANIZATION: Inconsistent POM Structure**
35+
- Problem: Elements are not in logical order, affecting readability
36+
- Solutions: A) Reorganize sections B) Add descriptive comments C) Use consistent naming conventions
37+
38+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39+
```
40+
41+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
1542

1643
## Examples
1744

@@ -587,8 +614,12 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
587614

588615
## Output Format
589616

590-
- Update the file pom.xml if something is not correct
617+
- Analyze Maven POM files for best practices violations and improvement opportunities
618+
- Present structured analysis with prioritized improvement recommendations
619+
- Provide multiple solution options with clear pros/cons for each issue
620+
- Wait for user selection before implementing any changes
621+
- When implementing, apply only the chosen solution without adding unrequested plugins or dependencies
591622

592623
## Safeguards
593624

594-
- verify changes with the command: `mvn validate`
625+
- verify changes with the command: `mvn validate` or `./mvnw validate`

.cursor/rules/111-java-maven-deps-and-plugins.mdc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: Update pom.xml to add Maven dependencies & plugins
3-
globs: pom.xml
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Update pom.xml to add Maven dependencies & plugins
@@ -48,7 +48,7 @@ This rule provides a comprehensive, conversational approach to updating Maven po
4848

4949
4. **Verify installation**: Check that the following files were created:
5050
- `mvnw` (executable script for Unix/Mac)
51-
- `mvnw.cmd` (batch script for Windows)
51+
- `mvnw.cmd` (batch script for Windows)
5252
- `.mvn/wrapper/maven-wrapper.properties`
5353
- `.mvn/wrapper/maven-wrapper.jar`
5454

@@ -149,7 +149,7 @@ After getting answers, implement the configuration following this order:
149149

150150
#### Implementation Approach:
151151
1. **Ask about code quality dependencies**: Follow the questions in the template file
152-
2. **Add only selected dependencies**: Don't include dependencies the user doesn't need
152+
2. **Add only selected dependencies**: Don't include dependencies the user doesn't need
153153
3. **Configure with appropriate scope**: Use `provided` scope for compile-time only dependencies
154154

155155
### 2.3 Build Plugins Section (Conditional)
@@ -162,7 +162,7 @@ After getting answers, implement the configuration following this order:
162162

163163
**Core Plugins** (ask if user wants enhanced enforcement):
164164
- **maven-compiler-plugin**: Enhanced with Error Prone and NullAway analysis
165-
- **maven-enforcer-plugin**: With dependency convergence and circular dependency checks
165+
- **maven-enforcer-plugin**: With dependency convergence and circular dependency checks
166166
- **maven-surefire-plugin**: For unit testing with proper configuration
167167

168168
**Feature-Based Plugins** (add only if selected):
@@ -190,7 +190,7 @@ After getting answers, implement the configuration following this order:
190190

191191
**Available Profiles** (add only if features selected):
192192
- `jacoco`: Code coverage analysis
193-
- `pitest`: Mutation testing
193+
- `pitest`: Mutation testing
194194
- `security`: OWASP dependency security scanning
195195
- `find-bugs`: Static analysis with SpotBugs and PMD
196196

.cursor/rules/112-java-maven-documentation.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: Create README-DEV.md with information about how to use the Maven project
3-
globs: pom.xml
2+
description:
3+
globs:
44
alwaysApply: false
55
---
66
# Create README-DEV.md with information about how to use the Maven project

.cursor/rules/121-java-object-oriented-design.mdc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,33 @@ You are a Senior software engineer with extensive experience in Java software de
1111

1212
## Goal
1313

14-
Apply comprehensive guidelines for robust Java object-oriented design and refactoring. Follow core principles like SOLID, DRY, and YAGNI, implement best practices for class and interface design including favoring composition over inheritance and designing for immutability. Master encapsulation, inheritance, and polymorphism, and identify and refactor common object-oriented design code smells such as God Classes, Feature Envy, and Data Clumps to promote maintainable, flexible, and understandable code.
14+
Analyze Java code to identify object-oriented design improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
15+
16+
1. **Analyze** the code for OOD issues using the principles and examples below
17+
2. **Identify** the most impactful improvements (SOLID violations, code smells, design patterns)
18+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19+
4. **Ask** the user which improvement they'd like to implement
20+
5. **Wait** for user choice before making any changes
21+
22+
**Example interaction:**
23+
```
24+
🔍 I found 3 object-oriented design improvements in this code:
25+
26+
1. **CRITICAL: Single Responsibility Principle Violation**
27+
- Problem: UserService handles data, persistence, and notifications
28+
- Solutions: A) Split into separate services B) Extract repositories C) Use mediator pattern
29+
30+
2. **DESIGN: Feature Envy in calculateTotal()**
31+
- Problem: Method uses more Order data than Item data
32+
- Solutions: A) Move to Order class B) Create Calculator utility C) Use visitor pattern
33+
34+
3. **QUALITY: Public fields break encapsulation**
35+
- Solutions: A) Add getters/setters B) Use records C) Apply builder pattern
36+
37+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
38+
```
39+
40+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
1541

1642
### Implementing These Principles
1743

@@ -2471,4 +2497,7 @@ public class FileManager {
24712497

24722498
- Apply object-oriented design principles to improve code quality and maintainability
24732499
- Refactor code to follow SOLID principles and eliminate design smells
2474-
- Verify code changes compile and pass tests
2500+
2501+
## Safeguards
2502+
2503+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`

.cursor/rules/122-java-type-design.mdc

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,36 @@ You are a Senior software engineer with extensive experience in Java software de
1313

1414
Type design thinking in Java applies typography principles to code structure and organization. Just as typography creates readable, accessible text, thoughtful type design in Java produces maintainable, comprehensible code.
1515

16-
### Implementing These Principles
16+
Analyze Java code to identify type design improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
17+
18+
1. **Analyze** the code for type design issues using the principles and examples below
19+
2. **Identify** the most impactful improvements (primitive obsession, type hierarchy problems, naming inconsistencies, missing type safety)
20+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
21+
4. **Ask** the user which improvement they'd like to implement
22+
5. **Wait** for user choice before making any changes
23+
24+
**Example interaction:**
25+
```
26+
🔍 I found 3 type design improvements in this code:
27+
28+
1. **CRITICAL: Primitive Obsession with String IDs**
29+
- Problem: Using String for CustomerID and OrderID creates type confusion
30+
- Solutions: A) Create type-safe wrapper classes B) Use records for ID types C) Apply builder pattern with validation
31+
32+
2. **DESIGN: Inconsistent Naming Patterns**
33+
- Problem: PaymentProcessor vs ShipCalc vs TaxSystem naming inconsistency
34+
- Solutions: A) Standardize to *Service pattern B) Use *Calculator pattern C) Apply *Provider pattern
35+
36+
3. **SAFETY: Missing BigDecimal for Financial Calculations**
37+
- Problem: Using double for monetary calculations causes precision issues
38+
- Solutions: A) Convert to BigDecimal with rounding B) Create Money type wrapper C) Use financial calculation utilities
39+
40+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
41+
```
42+
43+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
44+
45+
### Core Type Design Principles
1746

1847
1. **Start with domain modeling**: Sketch your type system before coding.
1948
2. **Create a type style guide**: Document naming conventions and patterns.
@@ -859,4 +888,7 @@ class BadProductService {
859888
- Use generics to create flexible and reusable components
860889
- Establish clear type hierarchies and consistent naming conventions
861890
- Use BigDecimal for precision-sensitive calculations
862-
- Verify code changes compile and pass tests
891+
892+
## Safeguards
893+
894+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`

.cursor/rules/123-java-general-guidelines.mdc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,38 @@ You are a Senior software engineer with extensive experience in Java software de
1111

1212
## Goal
1313

14-
This document outlines general Java coding guidelines covering fundamental aspects such as naming conventions for packages, classes, methods, variables, and constants; code formatting rules including indentation, line length, brace style, and whitespace usage; standards for organizing import statements; best practices for Javadoc documentation; and comprehensive error and exception handling with a strong focus on security, including avoiding sensitive information exposure, catching specific exceptions, and secure resource management.
14+
Analyze Java code to identify general coding guideline violations and present actionable alternatives to the user. When you encounter Java code:
15+
16+
1. **Analyze** the code for guideline violations using the principles and examples below
17+
2. **Identify** the most impactful improvements (naming, formatting, imports, documentation, error handling)
18+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19+
4. **Ask** the user which improvement they'd like to implement
20+
5. **Wait** for user choice before making any changes
21+
22+
**Example interaction:**
23+
```
24+
🔍 I found 4 Java guideline improvements in this code:
25+
26+
1. **CRITICAL: Naming Convention Violations**
27+
- Problem: Class uses snake_case, variables use Hungarian notation
28+
- Solutions: A) Apply standard Java naming B) Refactor with IDE tools C) Gradual migration approach
29+
30+
2. **FORMATTING: Inconsistent Code Style**
31+
- Problem: Mixed brace styles, missing spaces, poor indentation
32+
- Solutions: A) Apply Google Java Style B) Use Checkstyle configuration C) Manual formatting cleanup
33+
34+
3. **IMPORTS: Disorganized and Inefficient**
35+
- Problem: Wildcard imports, mixed ordering, missing grouping
36+
- Solutions: A) Organize by package groups B) Remove wildcards C) Use IDE auto-organization
37+
38+
4. **DOCUMENTATION: Missing Javadoc**
39+
- Problem: Public APIs lack documentation, no @param/@return tags
40+
- Solutions: A) Add comprehensive Javadoc B) Generate skeleton docs C) Document critical methods first
41+
42+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, 4A, 4B, 4C, or 'show more details')
43+
```
44+
45+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
1546

1647
### Implementing These Principles
1748

@@ -334,3 +365,7 @@ public class UnsafeFileProcessor {
334365
- Apply the Java general guidelines to improve code quality and maintainability
335366
- Follow naming conventions, formatting rules, and documentation standards
336367
- Implement comprehensive error handling with security considerations
368+
369+
## Safeguards
370+
371+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`

.cursor/rules/124-java-secure-coding.mdc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@ You are a Senior software engineer with extensive experience in Java software de
1111

1212
## Goal
1313

14-
Apply secure coding practices to Java code to prevent common vulnerabilities and enhance application security.
14+
Analyze Java code to identify security vulnerabilities and present actionable alternatives to the user. When you encounter Java code:
15+
16+
1. **Analyze** the code for security issues using the principles and examples below
17+
2. **Identify** the most critical vulnerabilities (injection flaws, weak cryptography, information disclosure, etc.)
18+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19+
4. **Ask** the user which improvement they'd like to implement
20+
5. **Wait** for user choice before making any changes
21+
22+
**Example interaction:**
23+
```
24+
🔒 I found 3 security vulnerabilities in this code:
25+
26+
1. **CRITICAL: SQL Injection Vulnerability**
27+
- Problem: User input directly concatenated into SQL query
28+
- Solutions: A) Use PreparedStatement B) Use JPA/Hibernate C) Add input validation layer
29+
30+
2. **HIGH: Weak Password Hashing**
31+
- Problem: Using MD5 for password storage without salt
32+
- Solutions: A) Switch to BCrypt B) Use Argon2 C) Implement PBKDF2 with salt
33+
34+
3. **MEDIUM: Information Disclosure in Exception Handling**
35+
- Problem: Stack traces exposed to users
36+
- Solutions: A) Generic error messages B) Centralized exception handler C) Separate logging
37+
38+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39+
```
40+
41+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
1542

1643
This document provides essential Java secure coding guidelines, focusing on five key areas: validating all untrusted inputs to prevent attacks like injection and path traversal; protecting against injection attacks (e.g., SQL injection) by using parameterized queries or prepared statements; minimizing the attack surface by adhering to the principle of least privilege and reducing exposure; employing strong, current cryptographic algorithms for hashing, encryption, and digital signatures while avoiding deprecated ones; and handling exceptions securely by avoiding the exposure of sensitive information in error messages to users and logging detailed, non-sensitive diagnostic information for developers.
1744

@@ -632,3 +659,7 @@ public class InsecureExceptionHandler {
632659
}
633660
}
634661
```
662+
663+
## Safeguards
664+
665+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`

.cursor/rules/125-java-concurrency.mdc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,35 @@ You are a Senior software engineer with extensive experience in Java software de
1111

1212
## Goal
1313

14+
Analyze Java code to identify concurrency improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
15+
16+
1. **Analyze** the code for concurrency issues using the principles and examples below
17+
2. **Identify** the most impactful improvements (thread safety violations, performance issues, modern alternatives)
18+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19+
4. **Ask** the user which improvement they'd like to implement
20+
5. **Wait** for user choice before making any changes
21+
22+
**Example interaction:**
23+
```
24+
🔍 I found 3 concurrency improvements in this code:
25+
26+
1. **CRITICAL: Thread Safety Violation**
27+
- Problem: HashMap accessed by multiple threads without synchronization
28+
- Solutions: A) Use ConcurrentHashMap B) Add synchronization C) Use lock-free atomic operations
29+
30+
2. **PERFORMANCE: Blocking Operations in Virtual Threads**
31+
- Problem: Using synchronized blocks that can pin virtual threads
32+
- Solutions: A) Replace with ReentrantLock B) Use concurrent collections C) Redesign with async patterns
33+
34+
3. **MODERN: ThreadLocal with Virtual Threads**
35+
- Problem: ThreadLocal doesn't work well with virtual threads
36+
- Solutions: A) Use ScopedValue B) Pass context explicitly C) Use structured concurrency
37+
38+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39+
```
40+
41+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
42+
1443
Effective Java concurrency relies on understanding thread safety fundamentals, using `java.util.concurrent` utilities, and managing thread pools with `ExecutorService`. Key practices include implementing concurrent design patterns like Producer-Consumer, leveraging `CompletableFuture` for asynchronous tasks, and ensuring thread safety through immutability and safe publication. Performance aspects like lock contention and memory consistency must be considered. Thorough testing, including stress tests and thread dump analysis, is crucial. Modern Java offers virtual threads for enhanced scalability, structured concurrency for simplified task management, and scoped values for safer thread-shared data as alternatives to thread-locals.
1544

1645
### Implementing These Principles
@@ -1651,3 +1680,7 @@ class BadScopedValueUsage {
16511680
}
16521681
}
16531682
```
1683+
1684+
## Safeguards
1685+
1686+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`

.cursor/rules/126-java-logging.mdc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@ You are a Senior software engineer with extensive experience in Java software de
1111

1212
## Goal
1313

14-
Effective Java logging involves selecting a standard framework (SLF4J with Logback/Log4j2), using appropriate log levels (ERROR, WARN, INFO, DEBUG, TRACE), and adhering to core practices like parameterized logging, proper exception handling, and avoiding sensitive data exposure. Configuration should be environment-specific with clear output formats. Security is paramount: mask sensitive data, control log access, and ensure secure transmission. Implement centralized log aggregation, monitoring, and alerting for proactive issue detection. Finally, logging behavior and its impact should be validated through comprehensive testing.
14+
Analyze Java code to identify logging improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
15+
16+
1. **Analyze** the code for logging issues using the principles and examples below
17+
2. **Identify** the most impactful improvements (framework selection, log levels, security, performance, monitoring)
18+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19+
4. **Ask** the user which improvement they'd like to implement
20+
5. **Wait** for user choice before making any changes
21+
22+
**Example interaction:**
23+
```
24+
🔍 I found 3 logging improvements in this code:
25+
26+
1. **CRITICAL: Security Risk - Sensitive Data Exposure**
27+
- Problem: Credit card numbers and passwords logged in plain text
28+
- Solutions: A) Implement data masking B) Use structured logging with filters C) Remove sensitive logging entirely
29+
30+
2. **PERFORMANCE: String Concatenation in Logging**
31+
- Problem: Using + operator instead of parameterized logging
32+
- Solutions: A) Convert to SLF4J placeholders B) Add guard clauses C) Use lazy evaluation
33+
34+
3. **MAINTAINABILITY: Inconsistent Log Levels**
35+
- Problem: Business events logged as DEBUG, errors as INFO
36+
- Solutions: A) Standardize level usage B) Create logging guidelines C) Use different loggers by category
37+
38+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39+
```
40+
41+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
1542

1643
### Implementing These Principles
1744

@@ -1383,3 +1410,7 @@ public class UntestableLogging {
13831410
}
13841411
}
13851412
```
1413+
1414+
## Safeguards
1415+
1416+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`

0 commit comments

Comments
 (0)