Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>gaurd-virusNew to Visual Studio Code? Get it now.
gaurd-virus

gaurd-virus

Meet Kathiriya

|
1 install
| (0) | Free
Scan code for forbidden patterns before every git push. VS Code extension + CLI + Git hooks.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Code Guardian 🛡️

Scan code for forbidden patterns before every git push. Blocks bad code at the source.

Code Guardian is a developer tool that combines a VS Code Extension, a Git pre-push hook, and a CLI – all powered by the same shared scanning engine and configured via a single .codeguardian.json file.


Features

Feature Details
🔴 Inline diagnostics Red/yellow squiggles directly in the editor
📋 Problems panel Clickable entries navigate to the exact line
🔔 Notifications Popup alerts when issues are found on save
🚫 Push blocker git push is blocked when error-severity rules fail
📁 Shared config One .codeguardian.json – every dev uses the same rules
🖥️ Status bar 🟢 Code Guardian / 🔴 N Issues always visible
⚡ CLI codeguardian scan for CI/CD pipelines
🙈 Inline ignores // codeguardian-ignore-next-line to suppress a rule

Folder Structure

code-guardian/
├── extension/          ← VS Code Extension
│   ├── extension.js    ← Entry point (activate/deactivate)
│   ├── scanner.js      ← VS Code ↔ engine bridge
│   ├── diagnostics.js  ← DiagnosticCollection manager
│   ├── statusBar.js    ← Status bar item
│   ├── commands.js     ← Command palette registrations
│   ├── config.js       ← .codeguardian.json loader + watcher
│   └── package.json    ← Extension manifest
│
├── git-hooks/
│   ├── pre-push        ← Shell hook (copied to .git/hooks/)
│   └── checkPush.js    ← Node.js hook runner
│
├── shared/             ← Framework-agnostic engine (used by ALL components)
│   ├── scannerEngine.js
│   ├── rules.js
│   └── utils.js
│
├── cli/
│   └── index.js        ← CLI: codeguardian scan
│
├── scripts/
│   └── installHooks.js ← Auto-installs the pre-push hook
│
├── examples/
│   ├── .codeguardian.json
│   └── bad-example.js  ← Test file with intentional violations
│
├── .codeguardian.json  ← Default project config
└── package.json

Quick Start

1. Clone & Install

git clone <your-repo-url>
cd code-guardian
npm install
# ↑ This also runs `npm run setup-hooks` to install the git pre-push hook

2. Install the VS Code Extension

cd extension
npx @vscode/vsce package --no-dependencies
# Produces: code-guardian-1.0.0.vsix

In VS Code:

  • Open Extensions panel (Ctrl+Shift+X)
  • Click ··· → Install from VSIX…
  • Select code-guardian-1.0.0.vsix

3. Add Config to Your Project

Copy .codeguardian.json to any project root:

{
  "ignore": ["node_modules", "dist", "build"],
  "rules": [
    {
      "id": "NO500",
      "pattern": "500",
      "type": "text",
      "severity": "error",
      "message": "HTTP 500 status code is forbidden before push.",
      "enabled": true
    },
    {
      "id": "NO_CONSOLE",
      "pattern": "console\\.log",
      "type": "regex",
      "severity": "warning",
      "message": "console.log found – remove before pushing.",
      "enabled": true
    }
  ]
}

How It Works

VS Code saves a file
        │
        ▼
  scannerEngine.js
  (scans file text)
        │
     Issues?
    /       \
  NO         YES
   │           │
 ✅ Clean    🔴 Diagnostics
              🔔 Notification
              📋 Problems Panel

git push
   │
   ▼
pre-push hook
   │
checkPush.js
   │
scannerEngine.js
   │
 Errors?
  /    \
YES     NO
 │       │
🚫      ✅
Block  Push OK

Rule Configuration

Each rule in .codeguardian.json supports:

Field Type Description
id string Unique rule identifier (shown in Problems panel)
pattern string Text to search for
type "text" | "regex" | "function" Match strategy
severity "error" | "warning" | "info" error blocks push; warning does not
message string Message shown in editor and terminal
enabled boolean Set to false to disable without removing

Rule Types

Text match (default) – exact substring:

{ "id": "NO_DEBUGGER", "pattern": "debugger", "type": "text", "severity": "error" }

Regex – JavaScript regular expression:

{ "id": "NO_CONSOLE", "pattern": "console\\.log", "type": "regex", "severity": "warning" }

Function – Inline JS function (advanced):

{ "id": "CUSTOM", "pattern": "return line.includes('TODO') && line.includes('hack')", "type": "function", "severity": "warning" }

Inline Ignores

Suppress a rule for a single line:

// codeguardian-ignore-next-line
console.log('This is intentional debug output');

VS Code Commands

Open the Command Palette (Ctrl+Shift+P) and search for:

Command Description
Code Guardian: Scan Workspace Scan every file in the workspace
Code Guardian: Scan Current File Scan the active editor file
Code Guardian: Reload Rules Re-read .codeguardian.json from disk
Code Guardian: Open Configuration Open (or create) .codeguardian.json
Code Guardian: Clear All Diagnostics Remove all underlines and problem entries

VS Code Settings

Setting Default Description
codeGuardian.enabled true Master on/off switch
codeGuardian.scanOnSave true Auto-scan on file save
codeGuardian.scanOnOpen true Auto-scan on file open
codeGuardian.showNotifications true Show popup alerts
codeGuardian.configFileName .codeguardian.json Config file name

CLI Usage

# Scan current directory
node cli/index.js scan

# Scan a specific folder
node cli/index.js scan src/

# Scan a single file
node cli/index.js scan src/api.js

Exit codes:

  • 0 – No errors (push safe)
  • 1 – Errors found (CI build fails)
  • 2 – Tool error (missing config, bad args)

CI/CD Integration (GitHub Actions)

name: Code Guardian

on: [push, pull_request]

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: node cli/index.js scan

Git Hook – Manual Install

If the postinstall script didn't run automatically:

npm run setup-hooks

This copies git-hooks/pre-push into .git/hooks/pre-push with executable permission.


Development

# Test the scanner on example files
npm test

# Package the extension
npm run package:ext

License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft