Skip to content

eggmun98/eslint-plugin-ternary-depth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-ternary-depth

ESLint plugin to limit the depth of nested ternary expressions

Installation

npm install eslint-plugin-ternary-depth --save-dev

Usage

Add ternary-depth to the plugins section of your .eslintrc configuration file:

{
  "plugins": ["ternary-depth"]
}

Then configure the rules you want to use:

{
  "rules": {
    "ternary-depth/max-depth": ["error", { "maxDepth": 2 }]
  }
}

Or use the recommended configuration:

{
  "extends": ["plugin:ternary-depth/recommended"]
}

Rules

ternary-depth/max-depth

This rule limits the depth of nested ternary expressions.

Options

  • maxDepth: Maximum allowed depth of nested ternary expressions (default: 2)

Examples

// Valid with maxDepth: 2
const value = condition1 ? (condition2 ? valueA : valueB) : valueC;

// Invalid with maxDepth: 2
const value = condition1 
  ? (condition2 
    ? (condition3 ? valueA : valueB) 
    : valueC) 
  : valueD;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published