Skip to content

Jitendersingh2001/cqscan

Repository files navigation

CQScan - Code Quality Scanner

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.

Features

πŸ” Multiple Rule Engines

  • SOLID Principles validation
  • ESLint integration
  • SonarJS rules (optional)

πŸš€ Automatic Git Integration

  • Runs on git add and git 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

Installation

Global Installation (Recommended)

npm install -g cqscan

Local Installation

npm install --save-dev cqscan

Quick Start

  1. Initialize CQScan in your project:
cqscan init
  1. That's it! CQScan will now automatically run when you:
    • Add files with git add
    • Commit with git commit

Manual Usage

Scan staged files

cqscan scan --staged

Scan all modified files

cqscan scan

Scan specific files

cqscan scan src/file1.ts src/file2.js

Output as JSON

cqscan scan --format json

Configuration

CQScan 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
  }
}

Configuration Options

  • 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, or xml
  • output.silent: Suppress output in hook mode
  • hooks: Control which Git hooks are active

Commands

cqscan init

Initialize CQScan in the current project. This will:

  • Create a default configuration file
  • Install Git hooks automatically
  • Set up the scanning environment

cqscan scan [options]

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

cqscan install-hooks

Install Git hooks only (without configuration)

cqscan uninstall-hooks

Remove Git hooks while keeping configuration

cqscan uninstall

Complete uninstall of CQScan

Rule Engines

SOLID Principles Engine

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

ESLint Engine

Integrates with your existing ESLint configuration to catch:

  • Syntax errors
  • Code style violations
  • Best practice violations
  • Custom rules

Sonar Engine

Provides SonarJS-style analysis for:

  • Cognitive complexity
  • Magic numbers
  • TODO comments
  • Duplicated strings
  • File length violations

Architecture

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)

Extensibility

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
  }
}

Git Hook Details

CQScan installs two Git hooks:

  1. pre-commit: Runs on staged files before commit
  2. prepare-commit-msg: Runs after git add to 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

Troubleshooting

Hooks not running?

# Check if hooks are installed
ls -la .git/hooks/

# Reinstall hooks
cqscan install-hooks

Permission issues?

# Make hooks executable
chmod +x .git/hooks/*

Configuration errors?

# Validate your config
cqscan scan --format json | jq

Contributing

We welcome contributions! Please see our contributing guidelines for details.

License

MIT License - see LICENSE file for details.


CQScan - Automatic code quality scanning that just worksβ„’

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published