Customize lint of agent mode

Try some of this – take the terminology from here and have it provide prompt snips for linting directives:

I took my original post above and had Composer add some additional info, which you may enjoy:


---
title: "AI Agent Linting Directives and Examples"
author: "Claude"
date: "`r Sys.Date()`"
output: html_document
---

## Core Linting Directives

### 1. Style Enforcement

ENFORCE: style=[guide] indent=[2|4] line_max=[80|120] case=[camel|snake|pascal] quotes=[single|double]


### 2. Error Prevention

CHECK: unused=true unreachable=true types=strict null_safety=true memory_leaks=true

3. Code Organization

ORGANIZE: group_methods=true sort_imports=true max_length=[function:20|class:100] extract_duplicates>3

4. Documentation

DOCUMENT: public=required private=recommended todos=flag format=[jsdoc|numpy|google]

5. Type Safety

TYPES: annotations=required null_check=strict generics=enforce interfaces=validate

Example Prompts & Expected Outcomes

1. Basic Style Enforcement

Input Prompt:

Review this code with:
ENFORCE: style=pep8 indent=4 line_max=80 case=snake

Sample Code:

def calculateUserScore(userName,     userAge):
    userScore=userAge*2+len(userName)*3
    return userScore

Expected Output:

def calculate_user_score(user_name, user_age):
    """Calculate user score based on age and name length."""
    user_score = user_age * 2 + len(user_name) * 3
    return user_score

2. Error Detection

Input Prompt:

Analyze with:
CHECK: unused=true unreachable=true types=strict

Sample Code:

function processData(data: any) {
    const temp = "unused";
    if (false) {
        return "never";
    }
    return data;
}

Expected Output:

// Violations:
// 1. Unused variable 'temp'
// 2. Unreachable code in if block
// 3. Unsafe 'any' type

function processData(data: unknown) {
    return data;
}

3. Code Organization

Input Prompt:

Refactor using:
ORGANIZE: group_methods=true sort_imports=true max_length=20

Sample Code:

import { z } from 'zod';
import { useState } from 'react';
import { query } from './db';

function validateAndProcessAndTransformAndStoreDataInMultipleSteps(data) {
    // ... 50 lines of code ...
}

Expected Output:

import { query } from './db';
import { useState } from 'react';
import { z } from 'zod';

function validateData(data) {
    // ... validation logic
}

function processData(validData) {
    // ... processing logic
}

function transformData(processedData) {
    // ... transformation logic
}

function storeData(transformedData) {
    // ... storage logic
}

Extended Linting Rules

Performance Optimization

OPTIMIZE: complexity=[O(n)] memory=[linear] async=true cache=recommended

Security Checks

SECURE: input=sanitize sql=parameterize auth=validate csrf=check

Testing Requirements

TEST: coverage=80 unit=required integration=recommended e2e=optional

Integration with Common Tools

ESLint Configuration

{
    "extends": ["eslint:recommended"],
    "rules": {
        "max-len": ["error", { "code": 80 }],
        "indent": ["error", 4],
        "quotes": ["error", "single"]
    }
}

Prettier Configuration

{
    "printWidth": 80,
    "tabWidth": 4,
    "singleQuote": true,
    "trailingComma": "es5"
}

Best Practices for AI Agent Prompting

  1. Be Explicit
"Apply strict linting with: ENFORCE + CHECK + ORGANIZE directives"
  1. Prioritize Rules
"Focus on type safety and error prevention first, then style"
  1. Specify Exceptions
"Apply all standard linting rules EXCEPT line length limits"
  1. Request Explanations
"Provide violation explanations with line numbers and severity levels"

Common Linting Scenarios

1. Legacy Code Modernization

ENFORCE: modern=[es6|py3] deprecate=warn upgrade=suggest

2. Team Onboarding

DOCUMENT: verbose=true examples=required context=full

3. Production Readiness

CHECK: all=strict security=high performance=required

4. Code Review

REVIEW: style=strict logic=analyze complexity=flag duplication=warn

Conclusion

Effective linting directives should be:

  • Clear and unambiguous
  • Easily combinable
  • Version-aware
  • Tool-agnostic
  • Performance-conscious

And here is:

Linting Directive Cheatsheet

Table of Common Linting Instructions by Project Type

| Project Type | Linting Focus | Directive Example | Expected Outcome |

|-------------|---------------|-------------------|------------------|

| Production Web App |

| React Frontend | Type Safety & Performance | ENFORCE: types=strict jsx=recommended bundle=optimize | - Strict TypeScript checking
- Optimized React patterns
- Bundle size warnings |

| Node.js Backend | Security & Error Handling | CHECK: security=high async=strict error=comprehensive | - Security vulnerability checks
- Proper async/await usage
- Complete error handling |

| Express API | Input Validation & Documentation | VALIDATE: params=strict docs=openapi security=high | - Route parameter validation
- OpenAPI compliance
- Security headers |

| Project Type | Linting Focus | Directive Example | Expected Outcome |

|-------------|---------------|-------------------|------------------|

| Data Science |

| Jupyter Notebooks | Reproducibility & Documentation | ENFORCE: imports=top docs=cells memory=optimize | - Organized imports
- Documented cells
- Memory usage warnings |

| ML Pipeline | Type Hints & Error Handling | CHECK: types=numpy tensor=validate data=sanitize | - NumPy type validation
- Tensor shape checking
- Data validation |

| Data Processing Scripts | Performance & Memory | OPTIMIZE: memory=strict parallel=suggest io=efficient | - Memory leak detection
- Parallelization hints
- I/O optimization |

| Project Type | Linting Focus | Directive Example | Expected Outcome |

|-------------|---------------|-------------------|------------------|

| Mobile Development |

| iOS/Swift | Memory & UI Performance | CHECK: memory=arc ui=main_thread lifecycle=validate | - ARC compliance
- UI thread validation
- Lifecycle checks |

| Android/Kotlin | Null Safety & Coroutines | ENFORCE: null=strict coroutines=best_practice compose=recommended | - Null safety warnings
- Coroutine pattern checks
- Compose optimization |

| React Native | Cross-Platform & Performance | OPTIMIZE: platform=both bundle=size battery=efficient | - Platform-specific code checks
- Bundle optimization
- Battery usage warnings |

| Project Type | Linting Focus | Directive Example | Expected Outcome |

|-------------|---------------|-------------------|------------------|

| DevOps & Infrastructure |

| Terraform | Security & Best Practices | SECURE: iam=strict secrets=encrypt state=validate | - IAM policy validation
- Secrets handling
- State file checks |

| Docker | Security & Efficiency | OPTIMIZE: layer=minimal security=rootless size=compress | - Layer optimization
- Security best practices
- Image size reduction |

| GitHub Actions | Security & Efficiency | CHECK: secrets=mask parallel=optimize timeout=suggest | - Secrets usage validation
- Parallel job suggestions
- Timeout recommendations |

| Project Type | Linting Focus | Directive Example | Expected Outcome |

|-------------|---------------|-------------------|------------------|

| Testing Projects |

| Unit Tests | Coverage & Isolation | TEST: coverage=90 mock=pure isolation=strict | - Coverage requirements
- Pure mock usage
- Test isolation |

| E2E Tests | Reliability & Performance | TEST: flaky=detect parallel=enable retry=smart | - Flaky test detection
- Parallel execution
- Smart retry logic |

| Integration Tests | Configuration & Setup | TEST: setup=isolated env=validate cleanup=required | - Isolated test setup
- Environment validation
- Cleanup verification |

| Project Type | Linting Focus | Directive Example | Expected Outcome |

|-------------|---------------|-------------------|------------------|

| Legacy Code |

| Modernization | Compatibility & Deprecation | MODERNIZE: syntax=target deprecate=warn upgrade=suggest | - Modern syntax checks
- Deprecation warnings
- Upgrade suggestions |

| Migration | Breaking Changes & Types | MIGRATE: breaking=detect types=add compatibility=check | - Breaking change detection
- Type addition suggestions
- Compatibility validation |

| Maintenance | Documentation & Stability | MAINTAIN: docs=update stability=strict deps=audit | - Documentation updates
- Stability checks
- Dependency audits |

Usage Tips

  • Combining Directives

ENFORCE: style=standard

CHECK: security=high

OPTIMIZE: performance=strict

  • Setting Priorities

PRIORITY: security=1 performance=2 style=3

  • Excluding Rules

ENFORCE: all=standard

EXCLUDE: line_length max_params

  • Environment-Specific Rules

ENV: development

ENFORCE: strict=false

ENV: production

ENFORCE: strict=true

Common Modifiers

  • strict: Highest level of enforcement

  • recommended: Standard best practices

  • warn: Issue warnings instead of errors

  • suggest: Provide suggestions only

  • auto: Attempt automatic fixes

  • validate: Check without fixing

  • ignore: Skip specific rules

Best Practices

  • Start with standard rules:

ENFORCE: style=standard

  • Add project-specific requirements:

ENFORCE: style=standard

CHECK: project=custom_rules

  1. Adjust based on development phase:

PHASE: development

ENFORCE: style=relaxed

PHASE: production

ENFORCE: style=strict

  • Include documentation requirements:

DOCUMENT: public=required private=recommended

This cheatsheet can be expanded based on specific needs and technologies. Always consider:

  • Project requirements

  • Team preferences

  • Performance implications

  • Maintenance overhead