claude-git-hooks 2.0.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +212 -0
- package/README.md +217 -92
- package/bin/claude-hooks +311 -149
- package/lib/config.js +163 -0
- package/lib/hooks/pre-commit.js +180 -68
- package/lib/hooks/prepare-commit-msg.js +47 -41
- package/lib/utils/claude-client.js +93 -11
- package/lib/utils/file-operations.js +23 -74
- package/lib/utils/file-utils.js +65 -0
- package/lib/utils/package-info.js +75 -0
- package/lib/utils/preset-loader.js +209 -0
- package/lib/utils/prompt-builder.js +83 -67
- package/lib/utils/resolution-prompt.js +12 -2
- package/package.json +49 -50
- package/templates/ANALYZE_DIFF.md +33 -0
- package/templates/COMMIT_MESSAGE.md +24 -0
- package/templates/SUBAGENT_INSTRUCTION.md +1 -0
- package/templates/config.example.json +41 -0
- package/templates/presets/ai/ANALYSIS_PROMPT.md +133 -0
- package/templates/presets/ai/PRE_COMMIT_GUIDELINES.md +176 -0
- package/templates/presets/ai/config.json +12 -0
- package/templates/presets/ai/preset.json +42 -0
- package/templates/presets/backend/ANALYSIS_PROMPT.md +85 -0
- package/templates/presets/backend/PRE_COMMIT_GUIDELINES.md +87 -0
- package/templates/presets/backend/config.json +12 -0
- package/templates/presets/backend/preset.json +49 -0
- package/templates/presets/database/ANALYSIS_PROMPT.md +114 -0
- package/templates/presets/database/PRE_COMMIT_GUIDELINES.md +143 -0
- package/templates/presets/database/config.json +12 -0
- package/templates/presets/database/preset.json +38 -0
- package/templates/presets/default/config.json +12 -0
- package/templates/presets/default/preset.json +53 -0
- package/templates/presets/frontend/ANALYSIS_PROMPT.md +99 -0
- package/templates/presets/frontend/PRE_COMMIT_GUIDELINES.md +95 -0
- package/templates/presets/frontend/config.json +12 -0
- package/templates/presets/frontend/preset.json +50 -0
- package/templates/presets/fullstack/ANALYSIS_PROMPT.md +107 -0
- package/templates/presets/fullstack/CONSISTENCY_CHECKS.md +147 -0
- package/templates/presets/fullstack/PRE_COMMIT_GUIDELINES.md +125 -0
- package/templates/presets/fullstack/config.json +12 -0
- package/templates/presets/fullstack/preset.json +55 -0
- package/templates/shared/ANALYSIS_PROMPT.md +103 -0
- package/templates/shared/ANALYZE_DIFF.md +33 -0
- package/templates/shared/COMMIT_MESSAGE.md +24 -0
- package/templates/shared/PRE_COMMIT_GUIDELINES.md +145 -0
- package/templates/shared/RESOLUTION_PROMPT.md +32 -0
- package/templates/check-version.sh +0 -266
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# AI/CLI Code Quality Guidelines
|
|
2
|
+
|
|
3
|
+
## Claude API Best Practices
|
|
4
|
+
|
|
5
|
+
### Model Selection
|
|
6
|
+
✅ **Haiku**: Simple tasks, fast responses, cost-effective
|
|
7
|
+
✅ **Sonnet**: Balanced performance, most use cases
|
|
8
|
+
✅ **Opus**: Complex reasoning, highest quality
|
|
9
|
+
❌ Don't use Opus when Haiku would suffice
|
|
10
|
+
|
|
11
|
+
### API Usage
|
|
12
|
+
✅ Implement proper timeout handling
|
|
13
|
+
✅ Handle rate limiting gracefully
|
|
14
|
+
✅ Retry with exponential backoff on failures
|
|
15
|
+
✅ Validate API responses before use
|
|
16
|
+
✅ Log API errors (but never log API keys!)
|
|
17
|
+
✅ Calculate and monitor token usage
|
|
18
|
+
|
|
19
|
+
### Error Handling
|
|
20
|
+
```javascript
|
|
21
|
+
// ✅ Good
|
|
22
|
+
try {
|
|
23
|
+
const response = await callClaudeAPI(prompt);
|
|
24
|
+
if (!response || !response.content) {
|
|
25
|
+
throw new Error('Invalid API response');
|
|
26
|
+
}
|
|
27
|
+
return parseResponse(response);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (error.status === 429) {
|
|
30
|
+
// Handle rate limiting
|
|
31
|
+
} else if (error.status === 500) {
|
|
32
|
+
// Handle server error
|
|
33
|
+
}
|
|
34
|
+
logger.error('API call failed', error);
|
|
35
|
+
throw new UserFriendlyError('Failed to analyze code');
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Prompt Engineering
|
|
40
|
+
|
|
41
|
+
### Structure
|
|
42
|
+
✅ Clear role/context at the beginning
|
|
43
|
+
✅ Specific task instructions
|
|
44
|
+
✅ Well-defined output format (usually JSON)
|
|
45
|
+
✅ Relevant examples when helpful
|
|
46
|
+
✅ Appropriate length (token-efficient)
|
|
47
|
+
|
|
48
|
+
### Quality Checklist
|
|
49
|
+
✅ Instructions are unambiguous
|
|
50
|
+
✅ Output format is machine-parseable
|
|
51
|
+
✅ Context is sufficient but not excessive
|
|
52
|
+
✅ Examples match expected usage
|
|
53
|
+
✅ Placeholders are replaced correctly
|
|
54
|
+
|
|
55
|
+
### Common Prompt Issues
|
|
56
|
+
❌ Vague instructions
|
|
57
|
+
❌ No output format specification
|
|
58
|
+
❌ Too much unnecessary context
|
|
59
|
+
❌ Ambiguous requirements
|
|
60
|
+
❌ Missing examples for complex tasks
|
|
61
|
+
|
|
62
|
+
## CLI User Experience
|
|
63
|
+
|
|
64
|
+
### Error Messages
|
|
65
|
+
✅ Clear, actionable error messages
|
|
66
|
+
✅ Suggest solutions when possible
|
|
67
|
+
✅ Use appropriate log levels
|
|
68
|
+
✅ Color-code for readability (error=red, success=green)
|
|
69
|
+
✅ Include context (what was being attempted)
|
|
70
|
+
|
|
71
|
+
### User Feedback
|
|
72
|
+
✅ Show progress for long operations
|
|
73
|
+
✅ Confirm destructive operations
|
|
74
|
+
✅ Provide helpful usage information
|
|
75
|
+
✅ Display meaningful results
|
|
76
|
+
✅ Log debug info only when debug mode enabled
|
|
77
|
+
|
|
78
|
+
## Git Operations Safety
|
|
79
|
+
|
|
80
|
+
### Safe Practices
|
|
81
|
+
✅ Validate repository state before operations
|
|
82
|
+
✅ Use `--cached` for staged changes
|
|
83
|
+
✅ Handle special characters in filenames
|
|
84
|
+
✅ Cross-platform path handling
|
|
85
|
+
✅ Graceful handling of git errors
|
|
86
|
+
|
|
87
|
+
### Dangerous Operations
|
|
88
|
+
❌ Never run git commands that modify history without explicit user confirmation
|
|
89
|
+
❌ Avoid hard resets
|
|
90
|
+
❌ Be careful with force pushes
|
|
91
|
+
❌ Validate before bulk operations
|
|
92
|
+
|
|
93
|
+
## Security
|
|
94
|
+
|
|
95
|
+
### API Keys
|
|
96
|
+
✅ Load from environment variables
|
|
97
|
+
✅ Never log or display API keys
|
|
98
|
+
✅ Never commit API keys to repository
|
|
99
|
+
✅ Use secure storage methods
|
|
100
|
+
✅ Clear keys from memory when done
|
|
101
|
+
|
|
102
|
+
### Command Injection
|
|
103
|
+
✅ Validate all user input
|
|
104
|
+
✅ Use parameterized commands when possible
|
|
105
|
+
✅ Escape special characters
|
|
106
|
+
✅ Avoid `eval()` and similar
|
|
107
|
+
✅ Sanitize file paths
|
|
108
|
+
|
|
109
|
+
### Sensitive Data
|
|
110
|
+
✅ Don't send secrets to Claude API
|
|
111
|
+
✅ Filter sensitive data from diffs
|
|
112
|
+
✅ Be careful with error messages (don't expose internals)
|
|
113
|
+
✅ Implement SKIP_ANALYSIS for sensitive code
|
|
114
|
+
|
|
115
|
+
## Code Organization
|
|
116
|
+
|
|
117
|
+
### File Structure
|
|
118
|
+
```
|
|
119
|
+
lib/
|
|
120
|
+
hooks/ # Git hook implementations
|
|
121
|
+
utils/ # Utility functions
|
|
122
|
+
claude-client.js
|
|
123
|
+
git-operations.js
|
|
124
|
+
file-operations.js
|
|
125
|
+
logger.js
|
|
126
|
+
config.js # Configuration management
|
|
127
|
+
templates/ # Prompt templates
|
|
128
|
+
bin/ # CLI entry points
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Module Design
|
|
132
|
+
✅ Single responsibility principle
|
|
133
|
+
✅ Clear, descriptive function names
|
|
134
|
+
✅ Comprehensive error handling
|
|
135
|
+
✅ Proper logging at decision points
|
|
136
|
+
✅ Export reusable functions
|
|
137
|
+
|
|
138
|
+
## Common Issues to Avoid
|
|
139
|
+
|
|
140
|
+
### Critical Issues
|
|
141
|
+
❌ Exposed API keys or secrets
|
|
142
|
+
❌ Command injection vulnerabilities
|
|
143
|
+
❌ Destructive git operations without confirmation
|
|
144
|
+
❌ Unhandled promise rejections
|
|
145
|
+
|
|
146
|
+
### Major Issues
|
|
147
|
+
❌ Missing error handling
|
|
148
|
+
❌ Poor user experience (unclear errors)
|
|
149
|
+
❌ Cross-platform incompatibility
|
|
150
|
+
❌ Memory leaks (large file handling)
|
|
151
|
+
❌ Missing input validation
|
|
152
|
+
|
|
153
|
+
### Minor Issues
|
|
154
|
+
❌ Insufficient logging
|
|
155
|
+
❌ Unclear variable names
|
|
156
|
+
❌ Missing documentation
|
|
157
|
+
❌ Inefficient token usage
|
|
158
|
+
❌ Poor code organization
|
|
159
|
+
|
|
160
|
+
## Testing
|
|
161
|
+
|
|
162
|
+
✅ Test with various input sizes
|
|
163
|
+
✅ Test error scenarios (API failures, git errors)
|
|
164
|
+
✅ Test cross-platform compatibility
|
|
165
|
+
✅ Mock external dependencies (Claude API, git)
|
|
166
|
+
✅ Test with edge cases (special characters, large files)
|
|
167
|
+
✅ Verify token usage calculations
|
|
168
|
+
|
|
169
|
+
## Documentation
|
|
170
|
+
|
|
171
|
+
✅ Document API usage patterns
|
|
172
|
+
✅ Explain prompt design decisions
|
|
173
|
+
✅ Document configuration options
|
|
174
|
+
✅ Provide usage examples
|
|
175
|
+
✅ Keep README up to date
|
|
176
|
+
✅ Document breaking changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai",
|
|
3
|
+
"displayName": "AI/CLI (Node.js + Claude)",
|
|
4
|
+
"description": "Node.js CLI tools with Claude API integration",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
|
|
7
|
+
"techStack": [
|
|
8
|
+
"Node.js",
|
|
9
|
+
"ES Modules",
|
|
10
|
+
"Claude API",
|
|
11
|
+
"CLI tools",
|
|
12
|
+
"Git hooks",
|
|
13
|
+
"Bash scripting",
|
|
14
|
+
"Markdown templates"
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
"fileExtensions": [
|
|
18
|
+
".js",
|
|
19
|
+
".json",
|
|
20
|
+
".md",
|
|
21
|
+
".sh"
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
"focusAreas": [
|
|
25
|
+
"Claude API usage and best practices",
|
|
26
|
+
"Prompt engineering quality",
|
|
27
|
+
"CLI user experience",
|
|
28
|
+
"Error handling and logging",
|
|
29
|
+
"Git operations safety",
|
|
30
|
+
"Cross-platform compatibility",
|
|
31
|
+
"Token usage optimization",
|
|
32
|
+
"Security (API keys, secrets)"
|
|
33
|
+
],
|
|
34
|
+
|
|
35
|
+
"templates": {
|
|
36
|
+
"analysis": "ANALYSIS_PROMPT.md",
|
|
37
|
+
"guidelines": "PRE_COMMIT_GUIDELINES.md",
|
|
38
|
+
"commitMessage": "../shared/COMMIT_MESSAGE.md",
|
|
39
|
+
"analyzeDiff": "../shared/ANALYZE_DIFF.md",
|
|
40
|
+
"resolution": "../shared/RESOLUTION_PROMPT.md"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
You are analyzing a **{{PRESET_NAME}}** project with the following technology stack:
|
|
2
|
+
|
|
3
|
+
**Tech Stack:** {{TECH_STACK}}
|
|
4
|
+
|
|
5
|
+
**Analyzing files matching:** {{FILE_EXTENSIONS}}
|
|
6
|
+
|
|
7
|
+
## Your Task
|
|
8
|
+
|
|
9
|
+
Perform a comprehensive code quality analysis focusing on these areas:
|
|
10
|
+
|
|
11
|
+
{{FOCUS_AREAS}}
|
|
12
|
+
|
|
13
|
+
## Analysis Guidelines
|
|
14
|
+
|
|
15
|
+
1. **Security First**: Check for OWASP Top 10 vulnerabilities, especially:
|
|
16
|
+
- SQL injection risks
|
|
17
|
+
- Authentication/authorization flaws
|
|
18
|
+
- Sensitive data exposure
|
|
19
|
+
- XML external entities (XXE)
|
|
20
|
+
- Insecure deserialization
|
|
21
|
+
|
|
22
|
+
2. **Spring Boot Best Practices**:
|
|
23
|
+
- Proper use of `@Transactional`
|
|
24
|
+
- Correct exception handling
|
|
25
|
+
- Appropriate use of DTOs vs Entities
|
|
26
|
+
- Proper dependency injection
|
|
27
|
+
- Configuration management
|
|
28
|
+
|
|
29
|
+
3. **JPA/Hibernate**:
|
|
30
|
+
- N+1 query problems
|
|
31
|
+
- Lazy loading issues
|
|
32
|
+
- Proper use of relationships
|
|
33
|
+
- Query optimization
|
|
34
|
+
- Transaction boundaries
|
|
35
|
+
|
|
36
|
+
4. **Code Quality**:
|
|
37
|
+
- SOLID principles
|
|
38
|
+
- DRY violations
|
|
39
|
+
- Proper error handling
|
|
40
|
+
- Logging best practices
|
|
41
|
+
- Test coverage
|
|
42
|
+
|
|
43
|
+
## Output Format
|
|
44
|
+
|
|
45
|
+
Respond with a valid JSON following the SonarQube format:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"QUALITY_GATE": "PASSED|FAILED",
|
|
50
|
+
"approved": true|false,
|
|
51
|
+
"metrics": {
|
|
52
|
+
"reliability": "A|B|C|D|E",
|
|
53
|
+
"security": "A|B|C|D|E",
|
|
54
|
+
"maintainability": "A|B|C|D|E",
|
|
55
|
+
"coverage": 0-100,
|
|
56
|
+
"duplications": 0-100,
|
|
57
|
+
"complexity": "number"
|
|
58
|
+
},
|
|
59
|
+
"issues": {
|
|
60
|
+
"blocker": 0,
|
|
61
|
+
"critical": 0,
|
|
62
|
+
"major": 0,
|
|
63
|
+
"minor": 0,
|
|
64
|
+
"info": 0
|
|
65
|
+
},
|
|
66
|
+
"details": [
|
|
67
|
+
{
|
|
68
|
+
"severity": "BLOCKER|CRITICAL|MAJOR|MINOR|INFO",
|
|
69
|
+
"type": "BUG|VULNERABILITY|CODE_SMELL",
|
|
70
|
+
"file": "path/to/file.java",
|
|
71
|
+
"line": 123,
|
|
72
|
+
"message": "Clear description of the issue"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"securityHotspots": 0,
|
|
76
|
+
"blockingIssues": ["List of critical issues that must be fixed"]
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Analysis Rules
|
|
81
|
+
|
|
82
|
+
- **Block commit** if: Security vulnerabilities, critical bugs, or blocker issues found
|
|
83
|
+
- **Pass** if: Only minor issues, info messages, or no issues
|
|
84
|
+
- Be strict but fair - focus on real problems, not style preferences
|
|
85
|
+
- Provide actionable, specific feedback with line numbers
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Backend Code Quality Guidelines
|
|
2
|
+
|
|
3
|
+
## Spring Boot Standards
|
|
4
|
+
|
|
5
|
+
### Controllers
|
|
6
|
+
- Use proper HTTP methods and status codes
|
|
7
|
+
- Validate input with `@Valid`
|
|
8
|
+
- Handle exceptions with `@ExceptionHandler`
|
|
9
|
+
- Keep controllers thin - business logic in services
|
|
10
|
+
- Use DTOs for API contracts
|
|
11
|
+
|
|
12
|
+
### Services
|
|
13
|
+
- Use `@Transactional` appropriately
|
|
14
|
+
- Handle exceptions properly
|
|
15
|
+
- Keep methods focused and small
|
|
16
|
+
- Avoid business logic in controllers or repositories
|
|
17
|
+
|
|
18
|
+
### Repositories
|
|
19
|
+
- Extend appropriate Spring Data interfaces
|
|
20
|
+
- Use method naming conventions for queries
|
|
21
|
+
- Optimize queries with `@Query` when needed
|
|
22
|
+
- Avoid N+1 problems with `@EntityGraph`
|
|
23
|
+
|
|
24
|
+
### Entities
|
|
25
|
+
- Use Lombok annotations appropriately
|
|
26
|
+
- Define proper relationships (`@OneToMany`, `@ManyToOne`, etc.)
|
|
27
|
+
- Use `@Version` for optimistic locking
|
|
28
|
+
- Never expose entities in API - use DTOs
|
|
29
|
+
|
|
30
|
+
## Security Requirements
|
|
31
|
+
|
|
32
|
+
### Authentication & Authorization
|
|
33
|
+
- Never hardcode credentials
|
|
34
|
+
- Use Spring Security properly
|
|
35
|
+
- Validate JWT tokens correctly
|
|
36
|
+
- Check permissions before operations
|
|
37
|
+
|
|
38
|
+
### Data Validation
|
|
39
|
+
- Validate all user input
|
|
40
|
+
- Use parameterized queries (JPA does this by default)
|
|
41
|
+
- Sanitize data before logging
|
|
42
|
+
- Never trust client-side validation alone
|
|
43
|
+
|
|
44
|
+
### SQL Injection Prevention
|
|
45
|
+
- Always use JPA/JPQL or prepared statements
|
|
46
|
+
- Never concatenate SQL strings
|
|
47
|
+
- Be careful with native queries
|
|
48
|
+
- Use `@Query` with proper parameter binding
|
|
49
|
+
|
|
50
|
+
## Performance
|
|
51
|
+
|
|
52
|
+
### Database
|
|
53
|
+
- Use pagination for large result sets
|
|
54
|
+
- Optimize queries with proper indexes
|
|
55
|
+
- Avoid loading unnecessary data
|
|
56
|
+
- Use projections when you don't need full entities
|
|
57
|
+
|
|
58
|
+
### Threading
|
|
59
|
+
- Be careful with `@Async` methods
|
|
60
|
+
- Use proper thread pool configuration
|
|
61
|
+
- Avoid blocking operations in async methods
|
|
62
|
+
- Handle exceptions in async methods
|
|
63
|
+
|
|
64
|
+
### Caching
|
|
65
|
+
- Use `@Cacheable` appropriately
|
|
66
|
+
- Clear caches when data changes
|
|
67
|
+
- Don't cache sensitive data without encryption
|
|
68
|
+
|
|
69
|
+
## Testing
|
|
70
|
+
|
|
71
|
+
- Write unit tests for business logic
|
|
72
|
+
- Use `@DataJpaTest` for repository tests
|
|
73
|
+
- Use `@WebMvcTest` for controller tests
|
|
74
|
+
- Mock external dependencies
|
|
75
|
+
- Aim for 80%+ coverage on new code
|
|
76
|
+
|
|
77
|
+
## Common Issues to Avoid
|
|
78
|
+
|
|
79
|
+
❌ Returning entities from controllers
|
|
80
|
+
❌ Missing `@Transactional` on write operations
|
|
81
|
+
❌ N+1 query problems
|
|
82
|
+
❌ Hardcoded secrets or credentials
|
|
83
|
+
❌ Catching and ignoring exceptions
|
|
84
|
+
❌ Missing input validation
|
|
85
|
+
❌ Exposing sensitive data in logs
|
|
86
|
+
❌ Using `SELECT *` in queries
|
|
87
|
+
❌ Not handling null values properly
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "backend",
|
|
3
|
+
"displayName": "Backend (Spring Boot + SQL Server)",
|
|
4
|
+
"description": "Java backend with Spring Boot, JPA, SQL Server, AWS",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
|
|
7
|
+
"techStack": [
|
|
8
|
+
"Spring Boot 2.6+",
|
|
9
|
+
"JPA",
|
|
10
|
+
"Hibernate",
|
|
11
|
+
"SQL Server",
|
|
12
|
+
"Spring Security",
|
|
13
|
+
"JWT",
|
|
14
|
+
"MapStruct",
|
|
15
|
+
"Lombok",
|
|
16
|
+
"AWS SDK",
|
|
17
|
+
"Maven",
|
|
18
|
+
"Cucumber",
|
|
19
|
+
"JUnit",
|
|
20
|
+
"JaCoCo"
|
|
21
|
+
],
|
|
22
|
+
|
|
23
|
+
"fileExtensions": [
|
|
24
|
+
".java",
|
|
25
|
+
".xml",
|
|
26
|
+
".yml",
|
|
27
|
+
".yaml"
|
|
28
|
+
],
|
|
29
|
+
|
|
30
|
+
"focusAreas": [
|
|
31
|
+
"REST API design and best practices",
|
|
32
|
+
"JPA entities and repositories",
|
|
33
|
+
"Service layer patterns",
|
|
34
|
+
"Security vulnerabilities (OWASP Top 10)",
|
|
35
|
+
"SQL injection prevention",
|
|
36
|
+
"Performance (threads, async operations)",
|
|
37
|
+
"Transaction management",
|
|
38
|
+
"DTO mappings",
|
|
39
|
+
"Test coverage"
|
|
40
|
+
],
|
|
41
|
+
|
|
42
|
+
"templates": {
|
|
43
|
+
"analysis": "ANALYSIS_PROMPT.md",
|
|
44
|
+
"guidelines": "PRE_COMMIT_GUIDELINES.md",
|
|
45
|
+
"commitMessage": "../shared/COMMIT_MESSAGE.md",
|
|
46
|
+
"analyzeDiff": "../shared/ANALYZE_DIFF.md",
|
|
47
|
+
"resolution": "../shared/RESOLUTION_PROMPT.md"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
You are analyzing a **{{PRESET_NAME}}** project with the following technology stack:
|
|
2
|
+
|
|
3
|
+
**Tech Stack:** {{TECH_STACK}}
|
|
4
|
+
|
|
5
|
+
**Analyzing files matching:** {{FILE_EXTENSIONS}}
|
|
6
|
+
|
|
7
|
+
## Your Task
|
|
8
|
+
|
|
9
|
+
Perform a comprehensive database code quality analysis focusing on these areas:
|
|
10
|
+
|
|
11
|
+
{{FOCUS_AREAS}}
|
|
12
|
+
|
|
13
|
+
## Analysis Guidelines
|
|
14
|
+
|
|
15
|
+
1. **Security First**: Check for SQL security issues:
|
|
16
|
+
- SQL injection vulnerabilities
|
|
17
|
+
- Excessive permissions granted
|
|
18
|
+
- Unencrypted sensitive data
|
|
19
|
+
- SQL dynamic execution risks
|
|
20
|
+
- Missing input validation
|
|
21
|
+
|
|
22
|
+
2. **Performance**:
|
|
23
|
+
- Missing indexes on foreign keys
|
|
24
|
+
- Full table scans
|
|
25
|
+
- N+1 query patterns
|
|
26
|
+
- Inefficient joins
|
|
27
|
+
- Missing WHERE clauses
|
|
28
|
+
- SELECT * usage
|
|
29
|
+
- Implicit conversions
|
|
30
|
+
|
|
31
|
+
3. **Data Integrity**:
|
|
32
|
+
- Missing constraints (PK, FK, CHECK, UNIQUE)
|
|
33
|
+
- Nullable columns that shouldn't be
|
|
34
|
+
- Missing default values
|
|
35
|
+
- Orphaned data risks
|
|
36
|
+
- Referential integrity issues
|
|
37
|
+
|
|
38
|
+
4. **T-SQL Best Practices**:
|
|
39
|
+
- Proper transaction handling
|
|
40
|
+
- Error handling with TRY...CATCH
|
|
41
|
+
- SET NOCOUNT ON in procedures
|
|
42
|
+
- Proper use of parameters
|
|
43
|
+
- Avoiding cursors when possible
|
|
44
|
+
|
|
45
|
+
5. **Maintainability**:
|
|
46
|
+
- Code clarity and comments
|
|
47
|
+
- Consistent naming conventions
|
|
48
|
+
- Proper formatting
|
|
49
|
+
- Avoiding magic numbers
|
|
50
|
+
- Version control for schema changes
|
|
51
|
+
|
|
52
|
+
## Common Database Anti-Patterns to Check
|
|
53
|
+
|
|
54
|
+
❌ **No WHERE clause on UPDATE/DELETE** (dangerous!)
|
|
55
|
+
❌ **Missing indexes on foreign keys**
|
|
56
|
+
❌ **Using SELECT \*** in production code
|
|
57
|
+
❌ **No error handling in stored procedures**
|
|
58
|
+
❌ **Implicit conversions** (kills index usage)
|
|
59
|
+
❌ **Cursors for set-based operations**
|
|
60
|
+
❌ **Dynamic SQL without parameterization**
|
|
61
|
+
❌ **Missing transaction handling**
|
|
62
|
+
❌ **No constraints** (relying on app logic only)
|
|
63
|
+
❌ **Excessive permissions** (granting db_owner)
|
|
64
|
+
|
|
65
|
+
## Output Format
|
|
66
|
+
|
|
67
|
+
Respond with a valid JSON following the SonarQube format:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"QUALITY_GATE": "PASSED|FAILED",
|
|
72
|
+
"approved": true|false,
|
|
73
|
+
"metrics": {
|
|
74
|
+
"reliability": "A|B|C|D|E",
|
|
75
|
+
"security": "A|B|C|D|E",
|
|
76
|
+
"maintainability": "A|B|C|D|E",
|
|
77
|
+
"coverage": 0-100,
|
|
78
|
+
"duplications": 0-100,
|
|
79
|
+
"complexity": "number"
|
|
80
|
+
},
|
|
81
|
+
"issues": {
|
|
82
|
+
"blocker": 0,
|
|
83
|
+
"critical": 0,
|
|
84
|
+
"major": 0,
|
|
85
|
+
"minor": 0,
|
|
86
|
+
"info": 0
|
|
87
|
+
},
|
|
88
|
+
"details": [
|
|
89
|
+
{
|
|
90
|
+
"severity": "BLOCKER|CRITICAL|MAJOR|MINOR|INFO",
|
|
91
|
+
"type": "BUG|VULNERABILITY|CODE_SMELL|PERFORMANCE",
|
|
92
|
+
"file": "path/to/file.sql",
|
|
93
|
+
"line": 123,
|
|
94
|
+
"message": "Clear description of the issue"
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"securityHotspots": 0,
|
|
98
|
+
"blockingIssues": ["List of critical issues that must be fixed"]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Analysis Rules
|
|
103
|
+
|
|
104
|
+
- **Block commit** if:
|
|
105
|
+
- SQL injection vulnerabilities
|
|
106
|
+
- UPDATE/DELETE without WHERE clause
|
|
107
|
+
- Dangerous permission grants
|
|
108
|
+
- Critical data integrity issues
|
|
109
|
+
|
|
110
|
+
- **Pass** if: Only minor issues, performance suggestions, or no issues
|
|
111
|
+
|
|
112
|
+
- Be strict on security and data integrity
|
|
113
|
+
- Be helpful on performance (suggest, don't block)
|
|
114
|
+
- Provide actionable, specific feedback with line numbers
|