Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 1.8 KB

File metadata and controls

56 lines (41 loc) · 1.8 KB

max-function-lines

Enforce a maximum number of lines per function body.

Rule Details

Property Value
Type suggestion
Fixable No
Recommended warn (max: 30)
Strict error (max: 25)

Rationale

Long functions are harder to understand, test, and maintain. Keeping functions small forces a single-responsibility design: each function does one thing, has a clear name, and can be tested in isolation. This rule counts the lines of a function's block body (inclusive of opening and closing braces) and reports any function that exceeds the configured limit. Arrow functions with concise expression bodies (no block) are not checked.

Examples

✅ Correct

/**
 * Validates a user registration payload.
 */
function validateRegistration(payload: IRegistrationPayload): IValidationResult {
  const errors: string[] = [];
  if (!payload.email) errors.push('Email is required');
  if (!payload.password) errors.push('Password is required');
  return { valid: errors.length === 0, errors };
}

❌ Incorrect (exceeds limit)

function doEverything(user: IUser) {
  // 35+ lines of mixed concerns...
}

Options

Option Type Default Description
max number 30 Maximum allowed lines in a function body

The standalone default is 30 lines. The recommended preset keeps this at 30 and the strict preset sets it to 25.

// Use the recommended preset value (30 lines)
'zero-tolerance/max-function-lines': 'warn'

// Custom limit
'zero-tolerance/max-function-lines': ['error', { max: 50 }]