claude-git-hooks 2.1.0 → 2.3.1
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 +240 -0
- package/README.md +280 -78
- package/bin/claude-hooks +295 -119
- package/lib/config.js +164 -0
- package/lib/hooks/pre-commit.js +180 -67
- package/lib/hooks/prepare-commit-msg.js +47 -41
- package/lib/utils/claude-client.js +107 -16
- package/lib/utils/claude-diagnostics.js +266 -0
- package/lib/utils/file-operations.js +1 -65
- package/lib/utils/file-utils.js +65 -0
- package/lib/utils/installation-diagnostics.js +145 -0
- package/lib/utils/package-info.js +75 -0
- package/lib/utils/preset-loader.js +214 -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/CUSTOMIZATION_GUIDE.md +656 -0
- package/templates/SUBAGENT_INSTRUCTION.md +1 -0
- package/templates/config.example.json +41 -0
- package/templates/pre-commit +40 -2
- package/templates/prepare-commit-msg +40 -2
- 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,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
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Database Code Quality Guidelines
|
|
2
|
+
|
|
3
|
+
## SQL Server Best Practices
|
|
4
|
+
|
|
5
|
+
### Schema Design
|
|
6
|
+
✅ Use appropriate data types (avoid VARCHAR(MAX) unless needed)
|
|
7
|
+
✅ Define primary keys on all tables
|
|
8
|
+
✅ Define foreign keys for relationships
|
|
9
|
+
✅ Add CHECK constraints for data validation
|
|
10
|
+
✅ Use NOT NULL where appropriate
|
|
11
|
+
✅ Add default values where sensible
|
|
12
|
+
|
|
13
|
+
### Indexes
|
|
14
|
+
✅ Index all foreign key columns
|
|
15
|
+
✅ Index columns used in WHERE, JOIN, ORDER BY
|
|
16
|
+
✅ Consider covering indexes for frequent queries
|
|
17
|
+
✅ Don't over-index (impacts INSERT/UPDATE performance)
|
|
18
|
+
✅ Use include columns for covering indexes
|
|
19
|
+
✅ Monitor index fragmentation
|
|
20
|
+
|
|
21
|
+
### Query Performance
|
|
22
|
+
✅ Avoid SELECT * (specify columns)
|
|
23
|
+
✅ Use proper JOIN types (INNER, LEFT, etc.)
|
|
24
|
+
✅ Include WHERE clauses to limit results
|
|
25
|
+
✅ Use appropriate indexes
|
|
26
|
+
✅ Avoid functions on indexed columns in WHERE
|
|
27
|
+
✅ Use EXISTS instead of IN for subqueries
|
|
28
|
+
✅ Implement pagination for large result sets
|
|
29
|
+
|
|
30
|
+
### Stored Procedures
|
|
31
|
+
✅ Start with SET NOCOUNT ON
|
|
32
|
+
✅ Use TRY...CATCH for error handling
|
|
33
|
+
✅ Use parameters (prevent SQL injection)
|
|
34
|
+
✅ Return meaningful error codes/messages
|
|
35
|
+
✅ Use transactions for multi-step operations
|
|
36
|
+
✅ Comment complex logic
|
|
37
|
+
|
|
38
|
+
### Transactions
|
|
39
|
+
✅ Keep transactions short
|
|
40
|
+
✅ Handle errors properly (ROLLBACK on error)
|
|
41
|
+
✅ Use appropriate isolation level
|
|
42
|
+
✅ Don't hold locks longer than needed
|
|
43
|
+
✅ Commit or rollback all transactions
|
|
44
|
+
|
|
45
|
+
### Security
|
|
46
|
+
✅ Use parameterized queries (no string concatenation)
|
|
47
|
+
✅ Grant minimum necessary permissions
|
|
48
|
+
✅ Encrypt sensitive data at rest
|
|
49
|
+
✅ Use schemas to organize objects
|
|
50
|
+
✅ Avoid dynamic SQL when possible
|
|
51
|
+
✅ If using dynamic SQL, use sp_executesql with parameters
|
|
52
|
+
|
|
53
|
+
## Common Issues to Avoid
|
|
54
|
+
|
|
55
|
+
### Critical Issues (BLOCKER)
|
|
56
|
+
❌ UPDATE/DELETE without WHERE clause
|
|
57
|
+
❌ SQL injection vulnerabilities
|
|
58
|
+
❌ Granting excessive permissions (db_owner, sysadmin)
|
|
59
|
+
❌ No transaction handling for multi-step operations
|
|
60
|
+
|
|
61
|
+
### Performance Issues (MAJOR)
|
|
62
|
+
❌ SELECT * in production code
|
|
63
|
+
❌ Missing indexes on foreign keys
|
|
64
|
+
❌ Functions on indexed columns in WHERE
|
|
65
|
+
❌ Implicit conversions
|
|
66
|
+
❌ Cursors for set-based operations
|
|
67
|
+
❌ Missing WHERE clause causing full table scan
|
|
68
|
+
|
|
69
|
+
### Data Integrity Issues (CRITICAL)
|
|
70
|
+
❌ Missing foreign key constraints
|
|
71
|
+
❌ Missing primary keys
|
|
72
|
+
❌ No CHECK constraints for validation
|
|
73
|
+
❌ Nullable columns that shouldn't be
|
|
74
|
+
❌ No default values where needed
|
|
75
|
+
|
|
76
|
+
### Code Quality Issues (MINOR)
|
|
77
|
+
❌ No error handling
|
|
78
|
+
❌ Unclear variable names
|
|
79
|
+
❌ Missing comments on complex logic
|
|
80
|
+
❌ Inconsistent formatting
|
|
81
|
+
❌ Magic numbers without explanation
|
|
82
|
+
|
|
83
|
+
## T-SQL Specific
|
|
84
|
+
|
|
85
|
+
### Error Handling
|
|
86
|
+
```sql
|
|
87
|
+
BEGIN TRY
|
|
88
|
+
BEGIN TRANSACTION;
|
|
89
|
+
|
|
90
|
+
-- Your operations here
|
|
91
|
+
|
|
92
|
+
COMMIT TRANSACTION;
|
|
93
|
+
END TRY
|
|
94
|
+
BEGIN CATCH
|
|
95
|
+
IF @@TRANCOUNT > 0
|
|
96
|
+
ROLLBACK TRANSACTION;
|
|
97
|
+
|
|
98
|
+
-- Log error or re-throw
|
|
99
|
+
THROW;
|
|
100
|
+
END CATCH;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Parameterization
|
|
104
|
+
```sql
|
|
105
|
+
-- ✅ Good (parameterized)
|
|
106
|
+
EXEC sp_executesql
|
|
107
|
+
N'SELECT * FROM Users WHERE UserId = @UserId',
|
|
108
|
+
N'@UserId INT',
|
|
109
|
+
@UserId = @InputUserId;
|
|
110
|
+
|
|
111
|
+
-- ❌ Bad (SQL injection risk)
|
|
112
|
+
EXEC('SELECT * FROM Users WHERE UserId = ' + @InputUserId);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Index Usage
|
|
116
|
+
```sql
|
|
117
|
+
-- ❌ Bad (function prevents index usage)
|
|
118
|
+
SELECT * FROM Users WHERE YEAR(CreatedDate) = 2024;
|
|
119
|
+
|
|
120
|
+
-- ✅ Good (can use index)
|
|
121
|
+
SELECT * FROM Users
|
|
122
|
+
WHERE CreatedDate >= '2024-01-01'
|
|
123
|
+
AND CreatedDate < '2025-01-01';
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Migration Scripts
|
|
127
|
+
|
|
128
|
+
✅ Include rollback script
|
|
129
|
+
✅ Make scripts idempotent when possible
|
|
130
|
+
✅ Check for existence before CREATE/ALTER
|
|
131
|
+
✅ Use transactions
|
|
132
|
+
✅ Test on non-production first
|
|
133
|
+
✅ Document breaking changes
|
|
134
|
+
✅ Version your scripts
|
|
135
|
+
|
|
136
|
+
## Testing
|
|
137
|
+
|
|
138
|
+
- Test with realistic data volumes
|
|
139
|
+
- Test edge cases (NULL, empty strings, etc.)
|
|
140
|
+
- Test concurrent access
|
|
141
|
+
- Verify indexes are being used (execution plan)
|
|
142
|
+
- Test rollback scenarios
|
|
143
|
+
- Verify constraints work as expected
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "database",
|
|
3
|
+
"displayName": "Database (SQL Server)",
|
|
4
|
+
"description": "SQL Server database scripts and migrations",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
|
|
7
|
+
"techStack": [
|
|
8
|
+
"SQL Server",
|
|
9
|
+
"T-SQL",
|
|
10
|
+
"Stored Procedures",
|
|
11
|
+
"Views",
|
|
12
|
+
"Triggers",
|
|
13
|
+
"Indexes"
|
|
14
|
+
],
|
|
15
|
+
|
|
16
|
+
"fileExtensions": [
|
|
17
|
+
".sql"
|
|
18
|
+
],
|
|
19
|
+
|
|
20
|
+
"focusAreas": [
|
|
21
|
+
"SQL injection prevention",
|
|
22
|
+
"Query performance and optimization",
|
|
23
|
+
"Index usage and design",
|
|
24
|
+
"Transaction management",
|
|
25
|
+
"Proper use of constraints",
|
|
26
|
+
"Data integrity",
|
|
27
|
+
"Security and permissions",
|
|
28
|
+
"Avoiding common anti-patterns"
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
"templates": {
|
|
32
|
+
"analysis": "ANALYSIS_PROMPT.md",
|
|
33
|
+
"guidelines": "PRE_COMMIT_GUIDELINES.md",
|
|
34
|
+
"commitMessage": "../shared/COMMIT_MESSAGE.md",
|
|
35
|
+
"analyzeDiff": "../shared/ANALYZE_DIFF.md",
|
|
36
|
+
"resolution": "../shared/RESOLUTION_PROMPT.md"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "default",
|
|
3
|
+
"displayName": "Default (General-purpose)",
|
|
4
|
+
"description": "General scripting and development",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
|
|
7
|
+
"techStack": [
|
|
8
|
+
"General scripting",
|
|
9
|
+
"JavaScript",
|
|
10
|
+
"Python",
|
|
11
|
+
"Bash",
|
|
12
|
+
"Ruby",
|
|
13
|
+
"Perl",
|
|
14
|
+
"PowerShell",
|
|
15
|
+
"SQL",
|
|
16
|
+
"YAML",
|
|
17
|
+
"JSON",
|
|
18
|
+
"XML"
|
|
19
|
+
],
|
|
20
|
+
|
|
21
|
+
"fileExtensions": [
|
|
22
|
+
".js",
|
|
23
|
+
".sh",
|
|
24
|
+
".bash",
|
|
25
|
+
".py",
|
|
26
|
+
".rb",
|
|
27
|
+
".pl",
|
|
28
|
+
".ps1",
|
|
29
|
+
".sql",
|
|
30
|
+
".yaml",
|
|
31
|
+
".yml",
|
|
32
|
+
".json",
|
|
33
|
+
".xml",
|
|
34
|
+
".md"
|
|
35
|
+
],
|
|
36
|
+
|
|
37
|
+
"focusAreas": [
|
|
38
|
+
"Code quality basics",
|
|
39
|
+
"Security fundamentals (input validation, escaping)",
|
|
40
|
+
"Performance best practices",
|
|
41
|
+
"Maintainability",
|
|
42
|
+
"Error handling",
|
|
43
|
+
"Documentation"
|
|
44
|
+
],
|
|
45
|
+
|
|
46
|
+
"templates": {
|
|
47
|
+
"analysis": "../shared/ANALYSIS_PROMPT.md",
|
|
48
|
+
"guidelines": "../shared/PRE_COMMIT_GUIDELINES.md",
|
|
49
|
+
"commitMessage": "../shared/COMMIT_MESSAGE.md",
|
|
50
|
+
"analyzeDiff": "../shared/ANALYZE_DIFF.md",
|
|
51
|
+
"resolution": "../shared/RESOLUTION_PROMPT.md"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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 frontend security issues:
|
|
16
|
+
- XSS vulnerabilities (dangerouslySetInnerHTML)
|
|
17
|
+
- Exposed API keys or secrets
|
|
18
|
+
- Insecure authentication token handling
|
|
19
|
+
- CSRF vulnerabilities
|
|
20
|
+
- Unvalidated redirects
|
|
21
|
+
|
|
22
|
+
2. **React Best Practices**:
|
|
23
|
+
- Proper use of hooks (useState, useEffect, useCallback, useMemo)
|
|
24
|
+
- Avoiding unnecessary re-renders
|
|
25
|
+
- Proper dependency arrays in useEffect
|
|
26
|
+
- Component composition over inheritance
|
|
27
|
+
- Proper prop types or TypeScript types
|
|
28
|
+
|
|
29
|
+
3. **State Management**:
|
|
30
|
+
- Redux patterns and anti-patterns
|
|
31
|
+
- Proper use of Redux Saga
|
|
32
|
+
- Immutable state updates
|
|
33
|
+
- Avoid prop drilling
|
|
34
|
+
- Local vs global state decisions
|
|
35
|
+
|
|
36
|
+
4. **Performance**:
|
|
37
|
+
- Unnecessary re-renders
|
|
38
|
+
- Missing React.memo or useMemo
|
|
39
|
+
- Large bundle sizes
|
|
40
|
+
- Unoptimized images
|
|
41
|
+
- Memory leaks (cleanup in useEffect)
|
|
42
|
+
|
|
43
|
+
5. **Accessibility**:
|
|
44
|
+
- Semantic HTML
|
|
45
|
+
- ARIA labels where needed
|
|
46
|
+
- Keyboard navigation
|
|
47
|
+
- Screen reader support
|
|
48
|
+
- Color contrast
|
|
49
|
+
|
|
50
|
+
6. **Code Quality**:
|
|
51
|
+
- Component reusability
|
|
52
|
+
- DRY violations
|
|
53
|
+
- Proper error handling
|
|
54
|
+
- Console errors/warnings
|
|
55
|
+
- Test coverage
|
|
56
|
+
|
|
57
|
+
## Output Format
|
|
58
|
+
|
|
59
|
+
Respond with a valid JSON following the SonarQube format:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"QUALITY_GATE": "PASSED|FAILED",
|
|
64
|
+
"approved": true|false,
|
|
65
|
+
"metrics": {
|
|
66
|
+
"reliability": "A|B|C|D|E",
|
|
67
|
+
"security": "A|B|C|D|E",
|
|
68
|
+
"maintainability": "A|B|C|D|E",
|
|
69
|
+
"coverage": 0-100,
|
|
70
|
+
"duplications": 0-100,
|
|
71
|
+
"complexity": "number"
|
|
72
|
+
},
|
|
73
|
+
"issues": {
|
|
74
|
+
"blocker": 0,
|
|
75
|
+
"critical": 0,
|
|
76
|
+
"major": 0,
|
|
77
|
+
"minor": 0,
|
|
78
|
+
"info": 0
|
|
79
|
+
},
|
|
80
|
+
"details": [
|
|
81
|
+
{
|
|
82
|
+
"severity": "BLOCKER|CRITICAL|MAJOR|MINOR|INFO",
|
|
83
|
+
"type": "BUG|VULNERABILITY|CODE_SMELL",
|
|
84
|
+
"file": "path/to/file.jsx",
|
|
85
|
+
"line": 123,
|
|
86
|
+
"message": "Clear description of the issue"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"securityHotspots": 0,
|
|
90
|
+
"blockingIssues": ["List of critical issues that must be fixed"]
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Analysis Rules
|
|
95
|
+
|
|
96
|
+
- **Block commit** if: Security vulnerabilities (XSS, exposed secrets), critical bugs, or accessibility blockers
|
|
97
|
+
- **Pass** if: Only minor issues, info messages, or no issues
|
|
98
|
+
- Be strict but fair - focus on real problems, not style preferences
|
|
99
|
+
- Provide actionable, specific feedback with line numbers
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Frontend Code Quality Guidelines
|
|
2
|
+
|
|
3
|
+
## React Standards
|
|
4
|
+
|
|
5
|
+
### Components
|
|
6
|
+
- Use functional components with hooks
|
|
7
|
+
- Keep components small and focused (< 200 lines)
|
|
8
|
+
- Extract reusable logic into custom hooks
|
|
9
|
+
- Use proper prop types or TypeScript
|
|
10
|
+
- Avoid deep nesting (max 3-4 levels)
|
|
11
|
+
|
|
12
|
+
### Hooks
|
|
13
|
+
- Follow Rules of Hooks (top level, not in loops/conditions)
|
|
14
|
+
- Provide complete dependency arrays in useEffect
|
|
15
|
+
- Use useCallback for functions passed to child components
|
|
16
|
+
- Use useMemo for expensive calculations
|
|
17
|
+
- Clean up effects (return cleanup function)
|
|
18
|
+
|
|
19
|
+
### State Management
|
|
20
|
+
- Keep state as local as possible
|
|
21
|
+
- Use Redux only for truly global state
|
|
22
|
+
- Follow Redux best practices (immutable updates)
|
|
23
|
+
- Use Redux Saga for side effects
|
|
24
|
+
- Normalize state shape
|
|
25
|
+
|
|
26
|
+
### Performance
|
|
27
|
+
- Use React.memo for expensive components
|
|
28
|
+
- Lazy load routes and heavy components
|
|
29
|
+
- Optimize images and assets
|
|
30
|
+
- Avoid inline function definitions in JSX
|
|
31
|
+
- Use virtualization for long lists
|
|
32
|
+
|
|
33
|
+
## Security Requirements
|
|
34
|
+
|
|
35
|
+
### XSS Prevention
|
|
36
|
+
- Never use `dangerouslySetInnerHTML` without sanitization
|
|
37
|
+
- Validate and sanitize user input
|
|
38
|
+
- Be careful with URL parameters
|
|
39
|
+
- Escape user-generated content
|
|
40
|
+
|
|
41
|
+
### Authentication
|
|
42
|
+
- Store tokens securely (httpOnly cookies preferred)
|
|
43
|
+
- Never log sensitive data
|
|
44
|
+
- Implement proper session timeout
|
|
45
|
+
- Clear sensitive data on logout
|
|
46
|
+
|
|
47
|
+
### API Security
|
|
48
|
+
- Never expose API keys in client code
|
|
49
|
+
- Use environment variables for configuration
|
|
50
|
+
- Validate API responses
|
|
51
|
+
- Handle errors without exposing internals
|
|
52
|
+
|
|
53
|
+
## Accessibility (a11y)
|
|
54
|
+
|
|
55
|
+
### Must Have
|
|
56
|
+
- Semantic HTML elements
|
|
57
|
+
- Alt text for images
|
|
58
|
+
- ARIA labels for icons and buttons
|
|
59
|
+
- Keyboard navigation support
|
|
60
|
+
- Focus management
|
|
61
|
+
|
|
62
|
+
### Forms
|
|
63
|
+
- Label all inputs properly
|
|
64
|
+
- Show validation errors clearly
|
|
65
|
+
- Support keyboard navigation
|
|
66
|
+
- Provide helpful error messages
|
|
67
|
+
|
|
68
|
+
## Common Issues to Avoid
|
|
69
|
+
|
|
70
|
+
❌ Missing dependency arrays in useEffect
|
|
71
|
+
❌ Using dangerouslySetInnerHTML
|
|
72
|
+
❌ Exposed API keys or secrets
|
|
73
|
+
❌ Missing error boundaries
|
|
74
|
+
❌ Unnecessary re-renders
|
|
75
|
+
❌ Memory leaks (missing cleanup)
|
|
76
|
+
❌ Ignoring console warnings
|
|
77
|
+
❌ Poor accessibility
|
|
78
|
+
❌ Missing loading/error states
|
|
79
|
+
❌ Not handling async errors
|
|
80
|
+
|
|
81
|
+
## Testing
|
|
82
|
+
|
|
83
|
+
- Write tests for complex components
|
|
84
|
+
- Test user interactions
|
|
85
|
+
- Test error scenarios
|
|
86
|
+
- Mock API calls
|
|
87
|
+
- Aim for 70%+ coverage on new code
|
|
88
|
+
|
|
89
|
+
## Styling
|
|
90
|
+
|
|
91
|
+
- Use consistent naming (BEM, CSS modules, or styled-components)
|
|
92
|
+
- Avoid inline styles except for dynamic values
|
|
93
|
+
- Ensure responsive design
|
|
94
|
+
- Check color contrast ratios
|
|
95
|
+
- Use CSS variables for theming
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "frontend",
|
|
3
|
+
"displayName": "Frontend (React + Material-UI)",
|
|
4
|
+
"description": "React frontend with Material-UI, Redux, React Hook Form",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
|
|
7
|
+
"techStack": [
|
|
8
|
+
"React 18+",
|
|
9
|
+
"React Router 6+",
|
|
10
|
+
"Material-UI v5",
|
|
11
|
+
"Semantic UI",
|
|
12
|
+
"Redux",
|
|
13
|
+
"Redux Saga",
|
|
14
|
+
"React Hook Form",
|
|
15
|
+
"Highcharts",
|
|
16
|
+
"Axios",
|
|
17
|
+
"Jest",
|
|
18
|
+
"Testing Library"
|
|
19
|
+
],
|
|
20
|
+
|
|
21
|
+
"fileExtensions": [
|
|
22
|
+
".js",
|
|
23
|
+
".jsx",
|
|
24
|
+
".ts",
|
|
25
|
+
".tsx",
|
|
26
|
+
".css",
|
|
27
|
+
".scss",
|
|
28
|
+
".html"
|
|
29
|
+
],
|
|
30
|
+
|
|
31
|
+
"focusAreas": [
|
|
32
|
+
"Component design and reusability",
|
|
33
|
+
"React hooks best practices",
|
|
34
|
+
"State management patterns",
|
|
35
|
+
"Performance optimization (memoization, lazy loading)",
|
|
36
|
+
"XSS prevention and input sanitization",
|
|
37
|
+
"Accessibility (a11y)",
|
|
38
|
+
"Responsive design",
|
|
39
|
+
"Error boundaries and error handling",
|
|
40
|
+
"Test coverage"
|
|
41
|
+
],
|
|
42
|
+
|
|
43
|
+
"templates": {
|
|
44
|
+
"analysis": "ANALYSIS_PROMPT.md",
|
|
45
|
+
"guidelines": "PRE_COMMIT_GUIDELINES.md",
|
|
46
|
+
"commitMessage": "../shared/COMMIT_MESSAGE.md",
|
|
47
|
+
"analyzeDiff": "../shared/ANALYZE_DIFF.md",
|
|
48
|
+
"resolution": "../shared/RESOLUTION_PROMPT.md"
|
|
49
|
+
}
|
|
50
|
+
}
|