@mesteche/eslint-plugin-neat-ternaries

format ternaries to optimize readability

Usage no npm install needed!

<script type="module">
  import mestecheEslintPluginNeatTernaries from 'https://cdn.skypack.dev/@mesteche/eslint-plugin-neat-ternaries';
</script>

README

eslint-plugin-neat-ternaries

npm

format chained ternaries to optimize readability

  • Each line correspond to a case (condition/value pair)
  • The chained ternary is formatted in two columns:
    • The left column is for conditions
    • The right column is for the matching values (including the default value)

Like this:

const neatTernary = someCondition       ? someValue :
                    someOtherCondition  ? someOtherValue :
                    yetAnotherCondition ? yetAnotherValue :
                                          defaultValue

Installation

You'll first need to install ESLint:

$ npm i -D eslint

Next, install @mesteche/eslint-plugin-neat-ternaries:

$ npm i -D @mesteche/eslint-plugin-neat-ternaries

Usage

Add @mesteche/neat-ternaries to the plugins section of your .eslintrc configuration file:

{
    "plugins": [
        "@mesteche/neat-ternaries"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "@mesteche/neat-ternaries/rule-name": 2
    }
}

Supported Rules