Skip to content

About

code-guardian

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Guardian

Code quality toolkit with git hooks for JavaScript/TypeScript projects. Automatically checks syntax, formatting, and dead code on commit and push.

Features

  • ESLint - Syntax checking and code quality
  • Prettier - Consistent code formatting
  • knip - Dead code and unused dependency detection
  • Husky - Git hooks (pre-commit, pre-push)
  • lint-staged - Run checks only on staged files (fast commits)

Installation

# From GitHub
npm install -D github:tedin7/code-guardian

# Install peer dependencies
npm install -D eslint prettier knip husky lint-staged typescript-eslint @eslint/js globals

Quick Start

# Initialize in your project
npx code-guardian init

This will:

  1. Create ESLint, Prettier, and knip configs
  2. Set up Husky git hooks
  3. Configure lint-staged for pre-commit

Git Hooks

Pre-commit (fast, staged files only)

  • ESLint with auto-fix
  • Prettier formatting

Pre-push (full project scan)

  • TypeScript type checking
  • Dead code detection (knip)
  • Full ESLint scan

Commands

# Run all checks
npx code-guardian check

# Auto-fix issues
npx code-guardian fix

# Individual tools
npx eslint . --fix    # Lint and fix
npx prettier --write . # Format
npx knip              # Find dead code

Manual Setup (without CLI)

1. Install dependencies

npm install -D eslint prettier knip husky lint-staged @eslint/js globals typescript-eslint

2. Create eslint.config.js

import js from "@eslint/js";
import tseslint from "typescript-eslint";
import globals from "globals";

export default tseslint.config(
  js.configs.recommended,
  ...tseslint.configs.recommended,
  {
    languageOptions: {
      globals: { ...globals.node, ...globals.browser },
    },
    rules: {
      "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
    },
  },
  { ignores: ["node_modules", "dist", ".next"] }
);

3. Create knip.json

{
  "$schema": "https://unpkg.com/knip@5/schema.json",
  "next": true,
  "ignoreDependencies": ["sharp", "autoprefixer"]
}

4. Add to package.json

{
  "scripts": {
    "lint": "eslint . --fix",
    "format": "prettier --write .",
    "typecheck": "tsc --noEmit",
    "deadcode": "knip",
    "check": "tsc --noEmit && eslint . && knip"
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"],
    "*.{json,md,yml}": ["prettier --write"]
  }
}

5. Initialize Husky

npx husky init

6. Create .husky/pre-commit

npx lint-staged

7. Create .husky/pre-push

#!/bin/sh
echo "Running pre-push checks..."
npx tsc --noEmit || exit 1
npx knip --no-exit-code || echo "Dead code found (warning)"
npx eslint . --max-warnings 0 || exit 1
echo "All checks passed!"

Monorepo Setup

For monorepos, initialize Husky at the root where .git lives:

# At monorepo root
npm install -D husky lint-staged
npx husky init

Then in .husky/pre-commit:

cd apps/web && npx lint-staged

License

MIT

About

code-guardian

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages