@hatem427/code-guard-ci 1.0.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/.husky/pre-commit +27 -0
- package/LICENSE +21 -0
- package/README.md +646 -0
- package/config/angular.config.ts +223 -0
- package/config/guidelines.config.ts +229 -0
- package/config/nextjs.config.ts +160 -0
- package/config/react.config.ts +330 -0
- package/dist/config/angular.config.d.ts +15 -0
- package/dist/config/angular.config.d.ts.map +1 -0
- package/dist/config/angular.config.js +187 -0
- package/dist/config/angular.config.js.map +1 -0
- package/dist/config/guidelines.config.d.ts +63 -0
- package/dist/config/guidelines.config.d.ts.map +1 -0
- package/dist/config/guidelines.config.js +167 -0
- package/dist/config/guidelines.config.js.map +1 -0
- package/dist/config/nextjs.config.d.ts +18 -0
- package/dist/config/nextjs.config.d.ts.map +1 -0
- package/dist/config/nextjs.config.js +133 -0
- package/dist/config/nextjs.config.js.map +1 -0
- package/dist/config/react.config.d.ts +15 -0
- package/dist/config/react.config.d.ts.map +1 -0
- package/dist/config/react.config.js +287 -0
- package/dist/config/react.config.js.map +1 -0
- package/dist/scripts/auto-fix.d.ts +16 -0
- package/dist/scripts/auto-fix.d.ts.map +1 -0
- package/dist/scripts/auto-fix.js +130 -0
- package/dist/scripts/auto-fix.js.map +1 -0
- package/dist/scripts/cli.d.ts +17 -0
- package/dist/scripts/cli.d.ts.map +1 -0
- package/dist/scripts/cli.js +255 -0
- package/dist/scripts/cli.js.map +1 -0
- package/dist/scripts/delete-bypass-logs.d.ts +17 -0
- package/dist/scripts/delete-bypass-logs.d.ts.map +1 -0
- package/dist/scripts/delete-bypass-logs.js +242 -0
- package/dist/scripts/delete-bypass-logs.js.map +1 -0
- package/dist/scripts/generate-doc.d.ts +18 -0
- package/dist/scripts/generate-doc.d.ts.map +1 -0
- package/dist/scripts/generate-doc.js +300 -0
- package/dist/scripts/generate-doc.js.map +1 -0
- package/dist/scripts/generate-pr-checklist.d.ts +20 -0
- package/dist/scripts/generate-pr-checklist.d.ts.map +1 -0
- package/dist/scripts/generate-pr-checklist.js +276 -0
- package/dist/scripts/generate-pr-checklist.js.map +1 -0
- package/dist/scripts/precommit-check.d.ts +23 -0
- package/dist/scripts/precommit-check.d.ts.map +1 -0
- package/dist/scripts/precommit-check.js +331 -0
- package/dist/scripts/precommit-check.js.map +1 -0
- package/dist/scripts/set-admin-password.d.ts +14 -0
- package/dist/scripts/set-admin-password.d.ts.map +1 -0
- package/dist/scripts/set-admin-password.js +116 -0
- package/dist/scripts/set-admin-password.js.map +1 -0
- package/dist/scripts/set-bypass-password.d.ts +11 -0
- package/dist/scripts/set-bypass-password.d.ts.map +1 -0
- package/dist/scripts/set-bypass-password.js +106 -0
- package/dist/scripts/set-bypass-password.js.map +1 -0
- package/dist/scripts/utils/auto-fixer.d.ts +28 -0
- package/dist/scripts/utils/auto-fixer.d.ts.map +1 -0
- package/dist/scripts/utils/auto-fixer.js +177 -0
- package/dist/scripts/utils/auto-fixer.js.map +1 -0
- package/dist/scripts/utils/bypass-manager.d.ts +101 -0
- package/dist/scripts/utils/bypass-manager.d.ts.map +1 -0
- package/dist/scripts/utils/bypass-manager.js +496 -0
- package/dist/scripts/utils/bypass-manager.js.map +1 -0
- package/dist/scripts/utils/code-analyzer.d.ts +34 -0
- package/dist/scripts/utils/code-analyzer.d.ts.map +1 -0
- package/dist/scripts/utils/code-analyzer.js +323 -0
- package/dist/scripts/utils/code-analyzer.js.map +1 -0
- package/dist/scripts/utils/file-checker.d.ts +93 -0
- package/dist/scripts/utils/file-checker.d.ts.map +1 -0
- package/dist/scripts/utils/file-checker.js +248 -0
- package/dist/scripts/utils/file-checker.js.map +1 -0
- package/dist/scripts/utils/logger.d.ts +26 -0
- package/dist/scripts/utils/logger.d.ts.map +1 -0
- package/dist/scripts/utils/logger.js +86 -0
- package/dist/scripts/utils/logger.js.map +1 -0
- package/dist/scripts/utils/project-detector.d.ts +34 -0
- package/dist/scripts/utils/project-detector.d.ts.map +1 -0
- package/dist/scripts/utils/project-detector.js +124 -0
- package/dist/scripts/utils/project-detector.js.map +1 -0
- package/dist/scripts/utils/rule-engine.d.ts +57 -0
- package/dist/scripts/utils/rule-engine.d.ts.map +1 -0
- package/dist/scripts/utils/rule-engine.js +158 -0
- package/dist/scripts/utils/rule-engine.js.map +1 -0
- package/dist/scripts/view-bypass-log.d.ts +13 -0
- package/dist/scripts/view-bypass-log.d.ts.map +1 -0
- package/dist/scripts/view-bypass-log.js +117 -0
- package/dist/scripts/view-bypass-log.js.map +1 -0
- package/package.json +74 -0
- package/scripts/auto-fix.ts +115 -0
- package/scripts/cli.ts +246 -0
- package/scripts/delete-bypass-logs.ts +253 -0
- package/scripts/generate-doc.ts +317 -0
- package/scripts/generate-pr-checklist.ts +285 -0
- package/scripts/precommit-check.ts +349 -0
- package/scripts/set-admin-password.ts +90 -0
- package/scripts/set-bypass-password.ts +80 -0
- package/scripts/utils/auto-fixer.ts +181 -0
- package/scripts/utils/bypass-manager.ts +566 -0
- package/scripts/utils/code-analyzer.ts +341 -0
- package/scripts/utils/file-checker.ts +253 -0
- package/scripts/utils/logger.ts +88 -0
- package/scripts/utils/project-detector.ts +115 -0
- package/scripts/utils/rule-engine.ts +186 -0
- package/scripts/view-bypass-log.ts +92 -0
- package/templates/feature-doc-api.md +101 -0
- package/templates/feature-doc-service.md +113 -0
- package/templates/feature-doc-ui.md +91 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
# ============================================================================
|
|
3
|
+
# Husky pre-commit hook
|
|
4
|
+
# ============================================================================
|
|
5
|
+
#
|
|
6
|
+
# This hook runs automatically before every commit. It:
|
|
7
|
+
# 1. Executes the Code Guardian pre-commit checks
|
|
8
|
+
# 2. Blocks the commit if errors are found
|
|
9
|
+
#
|
|
10
|
+
# Bypass methods:
|
|
11
|
+
# - Add #bypass-rules to your commit message
|
|
12
|
+
# - Run: BYPASS_RULES=true git commit -m "message"
|
|
13
|
+
#
|
|
14
|
+
# To skip this hook entirely (git native):
|
|
15
|
+
# git commit --no-verify
|
|
16
|
+
# ============================================================================
|
|
17
|
+
|
|
18
|
+
. "$(dirname -- "$0")/_/husky.sh"
|
|
19
|
+
|
|
20
|
+
echo "🛡️ Running Code Guardian pre-commit checks..."
|
|
21
|
+
|
|
22
|
+
# Run the TypeScript pre-commit check script via npm
|
|
23
|
+
npm run precommit-check
|
|
24
|
+
|
|
25
|
+
# Exit with the same code as the check script
|
|
26
|
+
# (0 = pass, 1 = blocked)
|
|
27
|
+
exit $?
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Your Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
# 🛡️ Code Guardian
|
|
2
|
+
|
|
3
|
+
> **Production-ready TypeScript tooling to enforce PR & coding guidelines for Angular, React, and Next.js projects.**
|
|
4
|
+
|
|
5
|
+
Automatically enforce your team's coding standards with pre-commit hooks, feature documentation generation, and PR checklists.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🚀 Quick Start
|
|
10
|
+
|
|
11
|
+
### Option 1: Install as NPM Package (Recommended)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Install in your project
|
|
15
|
+
npm install --save-dev @team/code-guardian
|
|
16
|
+
|
|
17
|
+
# Or with yarn
|
|
18
|
+
yarn add -D @team/code-guardian
|
|
19
|
+
|
|
20
|
+
# Initialize in your project
|
|
21
|
+
npx code-guardian init
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Option 2: Copy Files Directly
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Clone or copy this repository into your project
|
|
28
|
+
cp -r code-guardian/* your-project/
|
|
29
|
+
|
|
30
|
+
# Install dependencies
|
|
31
|
+
cd your-project
|
|
32
|
+
npm install
|
|
33
|
+
|
|
34
|
+
# Setup Husky
|
|
35
|
+
npm run prepare
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 📦 What's Included
|
|
41
|
+
|
|
42
|
+
- ✅ **Pre-commit hooks** - Automatic code quality checks before every commit
|
|
43
|
+
- ✅ **19 comprehensive rules** - Code Quality (5) + Security (4) + Performance (3) + Accessibility (2) + Framework-specific (5+)
|
|
44
|
+
- ✅ **Auto-fix capability** - Automatically fix common violations (console.log, any type, alt text, button type)
|
|
45
|
+
- ✅ **ESLint & Prettier** - Auto-formatting and linting integration
|
|
46
|
+
- ✅ **Feature docs generator** - Auto-generate documentation from templates or code analysis
|
|
47
|
+
- ✅ **PR checklist generator** - Create comprehensive PR checklists
|
|
48
|
+
- ✅ **Secure bypass logging** - All bypasses logged with tamper detection
|
|
49
|
+
- ✅ **Admin-only deletion** - Protected log management with audit trail
|
|
50
|
+
- ✅ **Auto-detection** - Automatically detects Angular, React, or Next.js
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 🧪 Testing in Your Project
|
|
55
|
+
|
|
56
|
+
### Step 1: Create a Test Git Repository
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Navigate to your Angular/React/Next.js project
|
|
60
|
+
cd /path/to/your-project
|
|
61
|
+
|
|
62
|
+
# Initialize git if not already done
|
|
63
|
+
git init
|
|
64
|
+
|
|
65
|
+
# Make sure you have a package.json with framework dependencies
|
|
66
|
+
# Example for Angular:
|
|
67
|
+
npm install @angular/core @angular/common
|
|
68
|
+
|
|
69
|
+
# Example for React:
|
|
70
|
+
npm install react react-dom
|
|
71
|
+
|
|
72
|
+
# Example for Next.js:
|
|
73
|
+
npm install next react react-dom
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Step 2: Install Code Guardian
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Option A: Link local package (for development)
|
|
80
|
+
cd /home/hatem/Documents/roles
|
|
81
|
+
npm link
|
|
82
|
+
|
|
83
|
+
cd /path/to/your-project
|
|
84
|
+
npm link @team/code-guardian
|
|
85
|
+
|
|
86
|
+
# Option B: Copy files directly
|
|
87
|
+
cp -r /home/hatem/Documents/roles/* .
|
|
88
|
+
|
|
89
|
+
# Install dependencies
|
|
90
|
+
npm install
|
|
91
|
+
|
|
92
|
+
# Add required scripts to package.json
|
|
93
|
+
npm pkg set \
|
|
94
|
+
scripts.set-bypass-password="npx ts-node node_modules/@team/code-guardian/scripts/set-bypass-password.ts" \
|
|
95
|
+
scripts.set-admin-password="npx ts-node node_modules/@team/code-guardian/scripts/set-admin-password.ts" \
|
|
96
|
+
scripts.delete-bypass-logs="npx ts-node node_modules/@team/code-guardian/scripts/delete-bypass-logs.ts" \
|
|
97
|
+
scripts.view-bypass-log="npx ts-node node_modules/@team/code-guardian/scripts/view-bypass-log.ts" \
|
|
98
|
+
scripts.auto-fix="npx ts-node node_modules/@team/code-guardian/scripts/auto-fix.ts"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Step 3: Test the Pre-commit Hook
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Create a test file with violations
|
|
105
|
+
cat > src/test.component.ts << 'EOF'
|
|
106
|
+
import { Component } from '@angular/core';
|
|
107
|
+
|
|
108
|
+
@Component({
|
|
109
|
+
selector: 'app-test',
|
|
110
|
+
template: `<div>{{ getValue() }}</div>`
|
|
111
|
+
})
|
|
112
|
+
export class TestComponent {
|
|
113
|
+
name: any = 'test'; // ❌ Uses 'any'
|
|
114
|
+
|
|
115
|
+
ngOnInit() { // ⚠️ Uses ngOnInit
|
|
116
|
+
console.log('test'); // ❌ Uses console.log
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getValue() { // ❌ Function in template
|
|
120
|
+
return this.name;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
EOF
|
|
124
|
+
|
|
125
|
+
# Stage the file
|
|
126
|
+
git add src/test.component.ts
|
|
127
|
+
|
|
128
|
+
# Try to commit (should be blocked)
|
|
129
|
+
git commit -m "test commit"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Expected output:**
|
|
133
|
+
```
|
|
134
|
+
🛡️ Running Code Guardian pre-commit checks...
|
|
135
|
+
|
|
136
|
+
────────────────────────────────────────────────────────────
|
|
137
|
+
🛡️ Code Guardian — Pre-commit Check
|
|
138
|
+
────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
ℹ [INFO] Detected project: Angular
|
|
141
|
+
ℹ [INFO] Found 1 staged file(s).
|
|
142
|
+
|
|
143
|
+
📂 Code Quality
|
|
144
|
+
✖ src/test.component.ts:12 [no-console-log] Remove all console.log...
|
|
145
|
+
|
|
146
|
+
📂 TypeScript
|
|
147
|
+
✖ src/test.component.ts:9 [no-any-type] Avoid using `any` type...
|
|
148
|
+
|
|
149
|
+
❌ Commit BLOCKED — fix the errors above and try again.
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Step 4: Test Bypass
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Bypass via commit message
|
|
156
|
+
git commit -m "test commit #bypass-rules"
|
|
157
|
+
|
|
158
|
+
# Or bypass via environment variable
|
|
159
|
+
BYPASS_RULES=true git commit -m "test commit"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Important**: All bypasses are automatically logged for security and audit purposes. See [Bypass Security](#-bypass-logging--security) below.
|
|
163
|
+
|
|
164
|
+
### Step 5: Test Feature Doc Generator
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Generate a UI component doc
|
|
168
|
+
npm run generate-doc -- --name="user-card" --type=ui
|
|
169
|
+
|
|
170
|
+
# Check the generated file
|
|
171
|
+
cat docs/features/user-card.md
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Step 6: Test PR Checklist Generator
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Generate checklist for current project
|
|
178
|
+
npm run generate-pr-checklist
|
|
179
|
+
|
|
180
|
+
# Generate for specific framework
|
|
181
|
+
npm run generate-pr-checklist -- --project=angular
|
|
182
|
+
|
|
183
|
+
# Save to file
|
|
184
|
+
npm run generate-pr-checklist -- --output=checklist.md
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 📚 Making it Reusable as NPM Package
|
|
190
|
+
|
|
191
|
+
### Option A: Publish to NPM Registry
|
|
192
|
+
|
|
193
|
+
#### 1. Update package.json
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Edit package.json - change these fields:
|
|
197
|
+
{
|
|
198
|
+
"name": "@your-org/code-guardian", // Change to your org
|
|
199
|
+
"version": "1.0.0",
|
|
200
|
+
"private": false, // Make it public
|
|
201
|
+
"main": "dist/index.js",
|
|
202
|
+
"types": "dist/index.d.ts",
|
|
203
|
+
"bin": {
|
|
204
|
+
"code-guardian": "./dist/cli.js"
|
|
205
|
+
},
|
|
206
|
+
"files": [
|
|
207
|
+
"dist",
|
|
208
|
+
"config",
|
|
209
|
+
"scripts",
|
|
210
|
+
"templates",
|
|
211
|
+
".husky"
|
|
212
|
+
]
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### 2. Build and Publish
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Build TypeScript
|
|
220
|
+
npm run build
|
|
221
|
+
|
|
222
|
+
# Login to NPM
|
|
223
|
+
npm login
|
|
224
|
+
|
|
225
|
+
# Publish
|
|
226
|
+
npm publish --access public
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### 3. Use in Other Projects
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# In any project
|
|
233
|
+
npm install --save-dev @your-org/code-guardian
|
|
234
|
+
|
|
235
|
+
# Run setup
|
|
236
|
+
npx code-guardian init
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Option B: Use as Git Submodule (No Publishing)
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# In your project
|
|
243
|
+
git submodule add https://github.com/your-org/code-guardian.git tools/code-guardian
|
|
244
|
+
|
|
245
|
+
# Link scripts in package.json
|
|
246
|
+
{
|
|
247
|
+
"scripts": {
|
|
248
|
+
"precommit-check": "ts-node tools/code-guardian/scripts/precommit-check.ts",
|
|
249
|
+
"generate-doc": "ts-node tools/code-guardian/scripts/generate-doc.ts",
|
|
250
|
+
"generate-pr-checklist": "ts-node tools/code-guardian/scripts/generate-pr-checklist.ts"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
# Setup Husky to use the submodule
|
|
255
|
+
cp tools/code-guardian/.husky/pre-commit .husky/pre-commit
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Option C: Use as Local NPM Package (Best for Testing)
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# In the code-guardian directory
|
|
262
|
+
npm link
|
|
263
|
+
|
|
264
|
+
# In your project directory
|
|
265
|
+
npm link @team/code-guardian
|
|
266
|
+
|
|
267
|
+
# Now you can use it like a normal package
|
|
268
|
+
npx code-guardian init
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## 🔧 Configuration
|
|
274
|
+
|
|
275
|
+
### Customizing Rules
|
|
276
|
+
|
|
277
|
+
Edit the config files to add/remove/modify rules:
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
// config/angular.config.ts
|
|
281
|
+
const angularRules: Rule[] = [
|
|
282
|
+
{
|
|
283
|
+
id: 'my-custom-rule',
|
|
284
|
+
label: 'My Custom Rule',
|
|
285
|
+
description: 'Enforce my team standard',
|
|
286
|
+
severity: 'error',
|
|
287
|
+
fileExtensions: ['ts'],
|
|
288
|
+
pattern: /forbidden-pattern/g,
|
|
289
|
+
applicableTo: ['angular'],
|
|
290
|
+
category: 'Custom Rules',
|
|
291
|
+
},
|
|
292
|
+
// ... existing rules
|
|
293
|
+
];
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Adding New Project Types
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// config/vue.config.ts
|
|
300
|
+
import { registerRules, Rule } from './guidelines.config';
|
|
301
|
+
|
|
302
|
+
const vueRules: Rule[] = [
|
|
303
|
+
{
|
|
304
|
+
id: 'vue-composition-api',
|
|
305
|
+
label: 'Use Composition API',
|
|
306
|
+
description: 'Prefer Composition API over Options API',
|
|
307
|
+
severity: 'warning',
|
|
308
|
+
fileExtensions: ['vue'],
|
|
309
|
+
pattern: /export default \{[\s\S]*data\(\)/g,
|
|
310
|
+
applicableTo: ['vue'],
|
|
311
|
+
category: 'Vue Best Practices',
|
|
312
|
+
},
|
|
313
|
+
];
|
|
314
|
+
|
|
315
|
+
registerRules('vue', vueRules);
|
|
316
|
+
export { vueRules };
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Then update `project-detector.ts`:
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
export type ProjectType = 'angular' | 'react' | 'nextjs' | 'vue' | 'unknown';
|
|
323
|
+
|
|
324
|
+
// In detectProject function:
|
|
325
|
+
if (hasDep(pkg, 'vue')) {
|
|
326
|
+
return { type: 'vue', label: 'Vue.js', rootDir: dir, packageJson: pkg };
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Inline Suppressions
|
|
331
|
+
|
|
332
|
+
Suppress specific rules in your code:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
// Suppress for one line
|
|
336
|
+
const data: any = {}; // code-guardian-disable no-any-type
|
|
337
|
+
|
|
338
|
+
// Suppress for entire file (add at top)
|
|
339
|
+
// code-guardian-disable-file no-console-log
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## 📋 Available Rules
|
|
345
|
+
|
|
346
|
+
### 📂 Code Quality (All Projects)
|
|
347
|
+
|
|
348
|
+
| Rule ID | Severity | Description |
|
|
349
|
+
|---------|----------|-------------|
|
|
350
|
+
| `no-console-log` | 🔴 Error | No console.log statements |
|
|
351
|
+
| `no-any-type` | 🔴 Error | No `any` type usage |
|
|
352
|
+
| `no-settimeout` | 🟡 Warning | Avoid setTimeout |
|
|
353
|
+
| `max-component-lines` | 🔴 Error | Components ≤ 400 lines |
|
|
354
|
+
| `no-custom-css` | 🟡 Warning | Prefer Tailwind over custom CSS |
|
|
355
|
+
|
|
356
|
+
### 🔒 Security Rules (All Projects)
|
|
357
|
+
|
|
358
|
+
| Rule ID | Severity | Description |
|
|
359
|
+
|---------|----------|-------------|
|
|
360
|
+
| `react-no-dangerously-set-html` | 🔴 Error | Prevents XSS attacks via dangerouslySetInnerHTML |
|
|
361
|
+
| `no-eval` | 🔴 Error | No eval() - blocks code injection |
|
|
362
|
+
| `no-hardcoded-credentials` | 🔴 Error | Detects API keys/passwords in code |
|
|
363
|
+
| `require-https` | 🔴 Error | Enforces HTTPS URLs for API calls |
|
|
364
|
+
|
|
365
|
+
### ⚡ Performance Rules (React/Next.js)
|
|
366
|
+
|
|
367
|
+
| Rule ID | Severity | Description |
|
|
368
|
+
|---------|----------|-------------|
|
|
369
|
+
| `react-no-anonymous-functions-in-render` | 🔴 Error | Prevents unnecessary re-renders |
|
|
370
|
+
| `react-missing-key-prop` | 🔴 Error | Ensures proper list rendering with keys |
|
|
371
|
+
| `no-large-bundle-imports` | 🟡 Warning | Warns about large library imports |
|
|
372
|
+
|
|
373
|
+
### ♿ Accessibility Rules (React/Next.js)
|
|
374
|
+
|
|
375
|
+
| Rule ID | Severity | Description |
|
|
376
|
+
|---------|----------|-------------|
|
|
377
|
+
| `require-alt-text` | 🔴 Error | All images must have alt attributes |
|
|
378
|
+
| `require-button-type` | 🔴 Error | Buttons need explicit type attribute |
|
|
379
|
+
|
|
380
|
+
### Angular-Specific Rules
|
|
381
|
+
|
|
382
|
+
| Rule ID | Severity | Description |
|
|
383
|
+
|---------|----------|-------------|
|
|
384
|
+
| `angular-no-ngoninit` | 🟡 Warning | Avoid ngOnInit for simple init |
|
|
385
|
+
| `angular-no-ng-deep` | 🔴 Error | No ::ng-deep usage |
|
|
386
|
+
| `angular-no-common-module` | 🟡 Warning | No CommonModule in standalone |
|
|
387
|
+
| `angular-no-ngclass` | 🟡 Warning | Use [class] binding instead |
|
|
388
|
+
| `angular-no-ngstyle` | 🟡 Warning | Use [style] binding instead |
|
|
389
|
+
| `angular-no-function-in-template` | 🔴 Error | No function calls in templates |
|
|
390
|
+
| `angular-use-async-pipe` | 🟡 Warning | Use async pipe over subscribe |
|
|
391
|
+
| `angular-use-takeuntildestroyed` | 🟡 Warning | Use takeUntilDestroyed() |
|
|
392
|
+
| `angular-prefer-signals` | 🔵 Info | Consider using Signals |
|
|
393
|
+
|
|
394
|
+
### ⚛️ React Hooks & Components
|
|
395
|
+
|
|
396
|
+
| Rule ID | Severity | Description |
|
|
397
|
+
|---------|----------|-------------|
|
|
398
|
+
| `react-no-useeffect-no-deps` | 🔴 Error | useEffect needs dependency array |
|
|
399
|
+
| `react-no-inline-styles` | 🟡 Warning | No inline style objects |
|
|
400
|
+
| `react-no-direct-dom` | 🔴 Error | No direct DOM manipulation |
|
|
401
|
+
| `react-prefer-fc-typing` | 🔵 Info | Type props explicitly |
|
|
402
|
+
| `react-no-prop-spreading` | 🔵 Info | Avoid prop spreading |
|
|
403
|
+
|
|
404
|
+
### Next.js-Specific Rules
|
|
405
|
+
|
|
406
|
+
| Rule ID | Severity | Description |
|
|
407
|
+
|---------|----------|-------------|
|
|
408
|
+
| `nextjs-use-client-directive` | 🟡 Warning | Verify "use client" directive |
|
|
409
|
+
| `nextjs-use-image-component` | 🟡 Warning | Use next/image not <img> |
|
|
410
|
+
| `nextjs-use-link-component` | 🟡 Warning | Use next/link not <a> |
|
|
411
|
+
| `nextjs-api-error-handling` | 🟡 Warning | API routes need try/catch |
|
|
412
|
+
| `nextjs-page-metadata` | 🔵 Info | Pages should export metadata |
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## 🎯 NPM Scripts Reference
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
# Pre-commit check (runs automatically via Husky)
|
|
420
|
+
npm run precommit-check
|
|
421
|
+
|
|
422
|
+
# Auto-fix violations
|
|
423
|
+
npm run auto-fix # Fix all violations
|
|
424
|
+
npm run auto-fix -- --dry-run # Preview fixes without changing files
|
|
425
|
+
|
|
426
|
+
# Security & Bypass Management
|
|
427
|
+
npm run set-bypass-password # Set developer bypass password
|
|
428
|
+
npm run set-admin-password # Set admin password (log deletion)
|
|
429
|
+
npm run view-bypass-log # View all bypass attempts
|
|
430
|
+
npm run delete-bypass-logs # Delete bypass logs (requires admin password)
|
|
431
|
+
|
|
432
|
+
# Generate feature documentation
|
|
433
|
+
npm run generate-doc -- --name="feature-name" --type=ui
|
|
434
|
+
npm run generate-doc -- --name="auth-api" --type=api
|
|
435
|
+
npm run generate-doc -- --name="user-service" --type=service
|
|
436
|
+
|
|
437
|
+
# Generate PR checklist
|
|
438
|
+
npm run generate-pr-checklist
|
|
439
|
+
npm run generate-pr-checklist -- --project=angular
|
|
440
|
+
npm run generate-pr-checklist -- --output=checklist.md
|
|
441
|
+
npm run generate-pr-checklist -- --all # All rules across all frameworks
|
|
442
|
+
|
|
443
|
+
# Build TypeScript
|
|
444
|
+
npm run build
|
|
445
|
+
|
|
446
|
+
# Lint and format
|
|
447
|
+
npm run lint
|
|
448
|
+
npm run format
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## � Bypass Logging & Security
|
|
454
|
+
|
|
455
|
+
### Immutable Audit Logging
|
|
456
|
+
|
|
457
|
+
Every bypass attempt is automatically logged with:
|
|
458
|
+
- ✅ **Author identity** (name and email from git)
|
|
459
|
+
- ✅ **Timestamp** (when bypass occurred)
|
|
460
|
+
- ✅ **Reason** (commit message or reason provided)
|
|
461
|
+
- ✅ **Affected files** (what was bypassed)
|
|
462
|
+
- ✅ **Branch name** (where bypass happened)
|
|
463
|
+
- ✅ **Commit hash** (linked to specific commit)
|
|
464
|
+
- ✅ **Integrity checksum** (tamper detection)
|
|
465
|
+
|
|
466
|
+
### Two-Level Security
|
|
467
|
+
|
|
468
|
+
#### 1. Bypass Password (Developer Access)
|
|
469
|
+
- Allows bypassing pre-commit checks when necessary
|
|
470
|
+
- Share with authorized developers
|
|
471
|
+
- Default: `bypass123` ⚠️ **CHANGE IMMEDIATELY**
|
|
472
|
+
|
|
473
|
+
```bash
|
|
474
|
+
# Set bypass password
|
|
475
|
+
npm run set-bypass-password
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
#### 2. Admin Password (Restricted Access)
|
|
479
|
+
- Required to delete bypass log entries
|
|
480
|
+
- Share only with team leads and security officers
|
|
481
|
+
- Default: `admin123` ⚠️ **CHANGE IMMEDIATELY**
|
|
482
|
+
|
|
483
|
+
```bash
|
|
484
|
+
# Set admin password
|
|
485
|
+
npm run set-admin-password
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
### Viewing Bypass Logs
|
|
489
|
+
|
|
490
|
+
```bash
|
|
491
|
+
# View all bypass attempts
|
|
492
|
+
npm run view-bypass-log
|
|
493
|
+
|
|
494
|
+
# Filter by author
|
|
495
|
+
npm run view-bypass-log -- --author="john@example.com"
|
|
496
|
+
|
|
497
|
+
# View recent (last 7 days)
|
|
498
|
+
npm run view-bypass-log -- --days=7
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### Deleting Logs (Admin Only)
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
# Delete specific entry
|
|
505
|
+
npm run delete-bypass-logs -- --id="entry-uuid"
|
|
506
|
+
|
|
507
|
+
# Delete by author
|
|
508
|
+
npm run delete-bypass-logs -- --author="john@example.com"
|
|
509
|
+
|
|
510
|
+
# Delete before date
|
|
511
|
+
npm run delete-bypass-logs -- --before="2024-01-01"
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**Security Features:**
|
|
515
|
+
- 🔒 Logs are immutable (read-only after creation)
|
|
516
|
+
- 🔍 Tamper detection with checksums
|
|
517
|
+
- 📦 Automatic archiving of deleted entries
|
|
518
|
+
- 🚨 Alerts when log integrity fails
|
|
519
|
+
- 📊 Complete audit trail maintained
|
|
520
|
+
|
|
521
|
+
### File Security
|
|
522
|
+
|
|
523
|
+
All sensitive files are stored in `.code-guardian/` and should **NEVER** be committed:
|
|
524
|
+
|
|
525
|
+
```
|
|
526
|
+
.code-guardian/
|
|
527
|
+
├── bypass-log.json # Main audit log (read-only)
|
|
528
|
+
├── bypass-password.hash # Bypass password
|
|
529
|
+
├── admin-credentials.hash # Admin password
|
|
530
|
+
└── bypass-archive/ # Deleted/tampered logs
|
|
531
|
+
├── deleted-entries-*.json
|
|
532
|
+
└── tampered-log-*.json
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**📖 For complete security documentation, see [docs/BYPASS_SECURITY.md](docs/BYPASS_SECURITY.md)**
|
|
536
|
+
|
|
537
|
+
---
|
|
538
|
+
|
|
539
|
+
## �🔄 CI/CD Integration
|
|
540
|
+
|
|
541
|
+
### GitHub Actions
|
|
542
|
+
|
|
543
|
+
```yaml
|
|
544
|
+
# .github/workflows/pr-check.yml
|
|
545
|
+
name: PR Checks
|
|
546
|
+
|
|
547
|
+
on: [pull_request]
|
|
548
|
+
|
|
549
|
+
jobs:
|
|
550
|
+
code-guardian:
|
|
551
|
+
runs-on: ubuntu-latest
|
|
552
|
+
steps:
|
|
553
|
+
- uses: actions/checkout@v3
|
|
554
|
+
- uses: actions/setup-node@v3
|
|
555
|
+
with:
|
|
556
|
+
node-version: '18'
|
|
557
|
+
|
|
558
|
+
- name: Install dependencies
|
|
559
|
+
run: npm ci
|
|
560
|
+
|
|
561
|
+
- name: Run Code Guardian
|
|
562
|
+
run: npm run precommit-check
|
|
563
|
+
env:
|
|
564
|
+
BYPASS_RULES: false
|
|
565
|
+
|
|
566
|
+
- name: Generate PR Checklist
|
|
567
|
+
run: npm run generate-pr-checklist -- --output=checklist.md
|
|
568
|
+
|
|
569
|
+
- name: Comment PR
|
|
570
|
+
uses: actions/github-script@v6
|
|
571
|
+
with:
|
|
572
|
+
script: |
|
|
573
|
+
const fs = require('fs');
|
|
574
|
+
const checklist = fs.readFileSync('checklist.md', 'utf8');
|
|
575
|
+
github.rest.issues.createComment({
|
|
576
|
+
issue_number: context.issue.number,
|
|
577
|
+
owner: context.repo.owner,
|
|
578
|
+
repo: context.repo.repo,
|
|
579
|
+
body: checklist
|
|
580
|
+
});
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
---
|
|
584
|
+
|
|
585
|
+
## 🤝 Contributing
|
|
586
|
+
|
|
587
|
+
1. Fork the repository
|
|
588
|
+
2. Create a feature branch
|
|
589
|
+
3. Add your rules/features
|
|
590
|
+
4. Test thoroughly
|
|
591
|
+
5. Submit a PR with documentation
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
## 📄 License
|
|
596
|
+
|
|
597
|
+
MIT License - feel free to use in your projects!
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
## 🆘 Troubleshooting
|
|
602
|
+
|
|
603
|
+
### "Command not found: code-guardian"
|
|
604
|
+
|
|
605
|
+
```bash
|
|
606
|
+
# Make sure you've installed dependencies
|
|
607
|
+
npm install
|
|
608
|
+
|
|
609
|
+
# Or if using as package
|
|
610
|
+
npm link @team/code-guardian
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
### "Husky hook not running"
|
|
614
|
+
|
|
615
|
+
```bash
|
|
616
|
+
# Reinstall Husky
|
|
617
|
+
rm -rf .husky
|
|
618
|
+
npm run prepare
|
|
619
|
+
chmod +x .husky/pre-commit
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### "TypeScript errors"
|
|
623
|
+
|
|
624
|
+
```bash
|
|
625
|
+
# Check TypeScript compilation
|
|
626
|
+
npx tsc --noEmit
|
|
627
|
+
|
|
628
|
+
# Rebuild
|
|
629
|
+
npm run build
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
### "Rules not detecting my framework"
|
|
633
|
+
|
|
634
|
+
```bash
|
|
635
|
+
# Check package.json has the right dependencies
|
|
636
|
+
# Angular: @angular/core
|
|
637
|
+
# React: react
|
|
638
|
+
# Next.js: next
|
|
639
|
+
|
|
640
|
+
# Or manually specify in scripts:
|
|
641
|
+
npm run precommit-check -- --project=angular
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
---
|
|
645
|
+
|
|
646
|
+
**Built with ❤️ for better code quality**
|