Skip to content

Implement slop patterns library (lib/patterns/slop-patterns.js) #4

@avifenesh

Description

@avifenesh

Overview

Create expandable pattern library for detecting and removing AI-generated code slop.

Objective

Implement detection patterns for common code quality issues that AI often introduces.

Pattern Categories

1. Console Debugging

{
  pattern: /console\.(log|debug|info)\(/,
  exclude: ["*.test.*", "*.spec.*"],
  severity: "medium",
  autoFix: "remove"
}

2. Python Debugging

{
  pattern: /(print\(|import pdb|breakpoint\(\))/,
  exclude: ["test_*.py", "*_test.py"],
  severity: "medium",
  autoFix: "remove"
}

3. Old TODOs

{
  pattern: /TODO:|FIXME:|HACK:/,
  filter: (file, line) => getLineAge(file, line) > 90, // >90 days old
  severity: "low",
  autoFix: "none" // Requires human judgment
}

4. Commented Code

{
  pattern: /^\s*\/\/.*\w{5,}|^\s*#.*\w{5,}/,
  minConsecutiveLines: 5,
  severity: "medium",
  autoFix: "remove"
}

5. Placeholder Text

{
  pattern: /(lorem ipsum|test test|asdf|foo bar baz|placeholder)/i,
  severity: "high",
  autoFix: "flag" // Flag for review
}

6. Empty Catch Blocks

{
  pattern: /catch\s*\([^)]*\)\s*\{\s*\}/,
  severity: "high",
  autoFix: "add_logging"
}

7. Magic Numbers

{
  pattern: /(?<![a-zA-Z_])[0-9]{4,}(?![a-zA-Z_0-9])/,
  exclude: ["*.test.*", "*.config.*"],
  severity: "low",
  autoFix: "flag"
}

Pattern Structure

{
  "pattern_name": {
    pattern: RegExp,          // Regex to match
    exclude: [string],        // File patterns to exclude
    severity: "critical"|"high"|"medium"|"low",
    autoFix: "remove"|"replace"|"flag"|"none",
    language: "javascript"|"python"|"rust"|"go"|null, // null = all
    description: string       // Human-readable explanation
  }
}

Auto-Fix Strategies

  • remove: Delete the matching line(s)
  • replace: Replace with suggested fix
  • add_logging: Add proper error logging
  • flag: Mark for manual review
  • none: Report only, no auto-fix

Usage

const patterns = require('./lib/patterns/slop-patterns');

// Get all patterns for a language
const jsPatterns = Object.entries(patterns)
  .filter(([_, p]) => !p.language || p.language === 'javascript');

// Check if line matches any pattern
function checkLine(line, file, lineNumber) {
  for (const [name, pattern] of Object.entries(patterns)) {
    if (pattern.pattern.test(line)) {
      // Check exclusions
      if (pattern.exclude?.some(ex => file.match(ex))) continue;
      
      return { name, pattern };
    }
  }
  return null;
}

Acceptance Criteria

  • Comprehensive pattern coverage
  • Language-specific patterns
  • Clear auto-fix strategies
  • Extensible structure
  • Well-documented examples

Priority

MEDIUM - Required for /deslop-around command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions