A comprehensive Git-hook based code quality scanner that automatically runs SOLID principles validation, ESLint, and Sonar rules on your codebase. Built following SOLID principles itself, CQScan provides automatic code quality checking without requiring manual intervention.
π Multiple Rule Engines
- SOLID Principles validation
- ESLint integration
- SonarJS rules (optional)
π Automatic Git Integration
- Runs on
git addandgit commit - Works across multiple terminals
- No session-based limitations
π― SOLID Architecture
- Single Responsibility Principle
- Open/Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
βοΈ Flexible Configuration
- Multiple output formats (console, JSON, XML)
- Include/exclude patterns
- Customizable rules per engine
npm install -g cqscannpm install --save-dev cqscan- Initialize CQScan in your project:
cqscan init- That's it! CQScan will now automatically run when you:
- Add files with
git add - Commit with
git commit
- Add files with
cqscan scan --stagedcqscan scancqscan scan src/file1.ts src/file2.jscqscan scan --format jsonCQScan creates a .cqscanrc.json file in your project root:
{
"rules": {
"eslint": {
"enabled": true,
"options": {}
},
"solid": {
"enabled": true,
"options": {}
},
"sonar": {
"enabled": false,
"options": {}
}
},
"languages": ["js", "ts", "jsx", "tsx"],
"exclude": ["node_modules/**", "dist/**"],
"include": ["src/**"],
"output": {
"format": "console",
"silent": false
},
"hooks": {
"preCommit": true,
"postAdd": true
}
}- rules: Enable/disable specific rule engines
- languages: File extensions to scan
- exclude: Glob patterns for files to exclude
- include: Glob patterns for files to include
- output.format:
console,json, orxml - output.silent: Suppress output in hook mode
- hooks: Control which Git hooks are active
Initialize CQScan in the current project. This will:
- Create a default configuration file
- Install Git hooks automatically
- Set up the scanning environment
Run code quality analysis with the following options:
--staged: Only scan staged files--hook-mode: Run in Git hook mode (minimal output)--silent: No output except errors--format <format>: Output format (console,json,xml)--files <files...>: Scan specific files
Install Git hooks only (without configuration)
Remove Git hooks while keeping configuration
Complete uninstall of CQScan
Validates code against the five SOLID principles:
- Single Responsibility Principle (SRP): Classes should have one reason to change
- Open/Closed Principle (OCP): Open for extension, closed for modification
- Liskov Substitution Principle (LSP): Subtypes should be substitutable for base types
- Interface Segregation Principle (ISP): Clients shouldn't depend on unused interfaces
- Dependency Inversion Principle (DIP): Depend on abstractions, not concretions
Integrates with your existing ESLint configuration to catch:
- Syntax errors
- Code style violations
- Best practice violations
- Custom rules
Provides SonarJS-style analysis for:
- Cognitive complexity
- Magic numbers
- TODO comments
- Duplicated strings
- File length violations
CQScan follows SOLID principles in its own design:
βββ engines/ # Rule engine implementations (Strategy Pattern)
βββ hooks/ # Git hook management (Single Responsibility)
βββ config/ # Configuration management (Single Responsibility)
βββ scanning/ # File discovery and filtering (Single Responsibility)
βββ reporting/ # Output formatting (Strategy Pattern)
βββ cli/ # Command-line interface (Interface Segregation)
Add new rule engines by implementing the IRuleEngine interface:
import { IRuleEngine, RuleResult } from 'cqscan';
class MyCustomEngine implements IRuleEngine {
getName(): string { return "MyEngine"; }
isEnabled(config: any): boolean { return config?.rules?.myengine?.enabled; }
canHandle(filePath: string): boolean { return filePath.endsWith('.ts'); }
async execute(files: string[]): Promise<RuleResult[]> {
// Your rule logic here
}
}CQScan installs two Git hooks:
- pre-commit: Runs on staged files before commit
- prepare-commit-msg: Runs after
git addto provide immediate feedback
The hooks are designed to:
- Work without user confirmation
- Function across multiple terminals
- Provide consistent behavior across environments
- Be robust and reliable
# Check if hooks are installed
ls -la .git/hooks/
# Reinstall hooks
cqscan install-hooks# Make hooks executable
chmod +x .git/hooks/*# Validate your config
cqscan scan --format json | jqWe welcome contributions! Please see our contributing guidelines for details.
MIT License - see LICENSE file for details.
CQScan - Automatic code quality scanning that just worksβ’