Configuration
Configuration Files
AI Guard looks for configuration in the following order:
- ai-guard.config.ts
- ai-guard.config.js
- ai-guard.config.mjs
- aiGuard field in package.json
Configuration Interface
The full configuration interface with default values:
typescript
interface AiGuardConfig { // Maximum ratio of comment lines to code lines (0-1) maxCommentsRatio: number; // Default: 0.15 (15%)
// List of forbidden generic variable/function names forbidGenericNames: string[]; // Default: ['data', 'result', 'item', 'temp', ...]
// Maximum allowed lines per function maxFunctionLines: number; // Default: 60
// AI-typical phrases to detect aiPatterns: { forbid: string[]; // Default: ['this function', 'we will', ...] };
// Architecture rules (file path patterns to allowed imports) architecture: Record<string, string[]>;
// Glob patterns for files to include include: string[]; // Default: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx']
// Glob patterns for files to exclude exclude: string[]; // Default: ['**/node_modules/**', '**/dist/**', ...]}Example Configuration File
Create ai-guard.config.ts in your project root:
typescript
import { defineConfig } from "@promise-inc/ai-guard";
export default defineConfig({ // Allow up to 12% comments maxCommentsRatio: 0.12,
// Add custom generic names to detect forbidGenericNames: [ 'data', 'result', 'item', 'temp', 'value', 'obj', 'arr', 'info', 'content', 'response', 'payload', ],
// Increase max function lines for complex business logic maxFunctionLines: 80,
// Add custom AI patterns aiPatterns: { forbid: [ 'this function', 'we will', 'we need to', 'let\'s', 'in order to', 'going to', ], },
// Architecture rules: components can only import from these paths architecture: { 'src/components/**': [ 'src/components/**', 'src/hooks/**', 'src/utils/**', 'react', '@/types', ], },
// Include patterns include: [ 'src/**/*.ts', 'src/**/*.tsx', ],
// Exclude patterns exclude: [ '**/node_modules/**', '**/dist/**', '**/build/**', '**/*.test.ts', '**/*.spec.ts', ],});Package.json Configuration
Alternatively, add configuration to package.json:
json
{ "name": "my-project", "version": "1.0.0", "aiGuard": { "maxCommentsRatio": 0.12, "maxFunctionLines": 80, "include": ["src/**/*.ts"], "exclude": ["**/*.test.ts"] }}Default Values
If no configuration file is found, AI Guard uses these defaults:
- maxCommentsRatio: 0.15 (15% of lines can be comments)
- maxFunctionLines: 60 (functions longer than 60 lines are flagged)
- forbidGenericNames: 10+ common generic names
- aiPatterns.forbid: 8+ common AI phrases
- include: All .ts, .tsx, .js, .jsx files
- exclude: node_modules, dist, build, coverage
Start with default settings and adjust thresholds based on your team's code style and tolerance for AI patterns.