max-file-lines
Prevent "god files" by capping the effective line count of a TypeScript file.
Type:
suggestion· Default:warn· Fixable: No
Prevents "god files" by capping the effective line count of a file.
Why This Rule Matters
AI coding assistants tend to keep appending code to the same file rather than creating new modules. This quickly produces 500+ line files that are hard to review, test, and maintain — "god files" that do too many things.
This rule catches file growth early so you can split before it becomes painful.
Options
| Option | Type | Default | Description |
|---|---|---|---|
max | number | 300 | Maximum effective lines per file |
skipBlankLines | boolean | true | Don't count blank lines |
skipComments | boolean | false | Don't count comment-only lines |
{
"rules": {
"ai-guardrails/max-file-lines": ["warn", { "max": 300, "skipBlankLines": true, "skipComments": false }]
}
}Examples
❌ Invalid — file exceeds limit
// A 400-line file with service logic, utilities, types, and constants
// all mixed together. AI tools commonly produce this pattern.
export class UserService { /* ... */ }
export function validateEmail() { /* ... */ }
export function formatPhone() { /* ... */ }
export type UserProfile = { /* ... */ };
export const ROLES = { /* ... */ };
// ...hundreds more lines✅ Valid — properly split modules
// user.service.ts (focused, under 300 lines)
export class UserService {
findById(id: string) { /* ... */ }
create(data: CreateUserDto) { /* ... */ }
}// user.validators.ts (separate module)
export function validateEmail(email: string): boolean { /* ... */ }
export function formatPhone(phone: string): string { /* ... */ }Custom Configuration
Lower the limit for stricter teams:
["warn", { "max": 200, "skipComments": false }]Raise it for legacy codebases you're gradually refactoring:
["warn", { "max": 500 }]When Not To Use This Rule
Add generated files to .eslintignore or the ignores array rather than disabling this rule globally.
- Generated files — GraphQL codegen, Prisma, ORM migrations
- Test files that intentionally need many inline test cases
- Migration files