feat(guardian): add guardian package - code quality analyzer

Add @puaros/guardian package v0.1.0 - code quality guardian for vibe coders and enterprise teams.

Features:
- Hardcode detection (magic numbers, magic strings)
- Circular dependency detection
- Naming convention enforcement (Clean Architecture)
- Architecture violation detection
- CLI tool with comprehensive reporting
- 159 tests with 80%+ coverage
- Smart suggestions for fixes
- Built for AI-assisted development

Built with Clean Architecture and DDD principles.
Works with Claude, GPT, Copilot, Cursor, and any AI coding assistant.
This commit is contained in:
imfozilbek
2025-11-24 02:54:39 +05:00
parent 9f97509b06
commit 03705b5264
96 changed files with 9520 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
// Test fixture for exported constants detection
// Single-line export const with as const
export const SINGLE_LINE_OBJECT = { value: 123 } as const
export const SINGLE_LINE_ARRAY = [1, 2, 3] as const
export const SINGLE_LINE_NUMBER = 999 as const
export const SINGLE_LINE_STRING = "test" as const
// Multi-line export const with as const
export const MULTI_LINE_CONFIG = {
timeout: 5000,
port: 8080,
retries: 3,
} as const
export const NESTED_CONFIG = {
api: {
baseUrl: "http://localhost",
timeout: 10000,
},
db: {
host: "localhost",
port: 5432,
},
} as const
// Array with as const
export const ALLOWED_PORTS = [3000, 8080, 9000] as const
// Without as const (should still be detected as hardcode)
export const NOT_CONST = {
value: 777,
}
// Regular variable (not exported) - should detect hardcode
const localConfig = {
timeout: 4000,
}

View File

@@ -0,0 +1,91 @@
// Test fixture for hardcode detection
// ❌ Should be detected - Magic numbers
export function badTimeouts() {
setTimeout(() => {}, 5000)
setInterval(() => {}, 3000)
const timeout = 10000
}
export function badRetries() {
const maxRetries = 3
const attempts = 5
const retries = 7
}
export function badPorts() {
const port = 8080
const PORT = 3000
const serverPort = 9000
}
export function badLimits() {
const limit = 50
const max = 100
const min = 10
const maxSize = 1024
}
// ❌ Should be detected - Magic strings
export function badUrls() {
const apiUrl = "http://localhost:8080"
const baseUrl = "https://api.example.com"
const dbUrl = "mongodb://localhost:27017/mydb"
}
export function badStrings() {
const errorMessage = "Something went wrong"
const configPath = "/etc/app/config"
}
// ✅ Should NOT be detected - Allowed numbers
export function allowedNumbers() {
const items = []
const index = 0
const increment = 1
const pair = 2
const ten = 10
const hundred = 100
const thousand = 1000
const notFound = -1
}
// ✅ Should NOT be detected - Exported constants
export const CONFIG = {
timeout: 5000,
port: 8080,
maxRetries: 3,
} as const
export const API_CONFIG = {
baseUrl: "http://localhost:3000",
timeout: 10000,
} as const
export const SETTINGS = {
nested: {
deep: {
value: 999,
},
},
} as const
// ✅ Should NOT be detected - Console logs
export function loggingAllowed() {
console.log("Debug message")
console.error("Error occurred")
}
// ✅ Should NOT be detected - Test descriptions
describe("test suite", () => {
test("should work correctly", () => {
expect(true).toBe(true)
})
})
// ❌ Should be detected - Generic 3+ digit numbers
export function suspiciousNumbers() {
const code = 404
const status = 200
const buffer = 512
}

View File

@@ -0,0 +1,16 @@
export function add(a: number, b: number): number {
return a + b
}
export const multiply = (a: number, b: number): number => {
return a * b
}
export class Calculator {
public divide(a: number, b: number): number {
if (b === 0) {
throw new Error("Division by zero")
}
return a / b
}
}