Course contentsShow
← Web Development
Lesson 1431 of 2,98226. Code Quality ToolsFree lesson

Rule Options and Customization

Passing options to rules to fine-tune behavior like quote styles, indentation, and spacing.

Rule Options and Customization

You'll learn how to pass specific options to ESLint rules to fine-tune their behavior and match your project's coding standards.

Why Rules Need Options

When you set a rule to "error" or "warn", many rules accept additional configuration to specify how they should enforce that rule. Think of it like ordering coffee: you don't just say "yes" to coffee—you specify size, milk type, and sugar level. Similarly, rules can be customized to match your team's exact preferences.

The Configuration Syntax

In your .eslintrc file, instead of just setting a rule level, you pass an array where the first element is the level and subsequent elements are the options:

{
  "rules": {
    "quotes": ["error", "single"],
    "indent": ["error", 2],
    "comma-dangle": ["warn", "always-multiline"]
  }
}

Common Customizable Rules

Quotes: The quotes rule can enforce "single", "double", or "backtick" quotes throughout your code.

Indentation: The indent rule accepts a number (spaces) or "tab", and can include options for specific scenarios like SwitchCase indentation.

Spacing: Rules like space-before-function-paren let you specify whether you want spaces before function parentheses in different contexts (anonymous functions, named functions, arrow functions).

{
  "rules": {
    "space-before-function-paren": ["error", {
      "anonymous": "always",
      "named": "never",
      "asyncArrow": "always"
    }]
  }
}

Finding Rule Options

Every ESLint rule's documentation page lists available options with examples. These options let you enforce consistency exactly how you want it, rather than accepting one-size-fits-all defaults.

Key Takeaway: Rule options transform ESLint from a blunt enforcement tool into a precision instrument that reflects your exact coding standards—simply pass configuration values as additional array elements after the rule level.