Skip to content

v.2.0.0

Latest
Compare
Choose a tag to compare
@luisadame luisadame released this 27 Sep 22:41
· 6 commits to main since this release

This release contains a breaking change.

If you were using the prefer-and-operator mode it would look for conditional expressions where the alternates were nullish and report an error in such case

So before, this code was valid:

<>{propA ? <span>Something</span> : <span>Else</span>}</>

And it would not be auto fixed, because the alternate of the condition (the else in the ternary) was not null or undefined.

In this version (now) that code is considered invalid and it would get auto fixed to following code:

<>
  {propA && <span>Something</span>}
  {!propA && <span>Else</span>}
</>

If you preferred the previous behavior where the not nullish alternates were ignored in prefer-and-operator mode, an additional property called exceptNotNullishAlternates has been added to the rule configuration.

An example of the configuration for that would be:

// .eslintrc.js
module.exports = {
  extends: [...],
  plugins: [..., 'jsx-conditional'],
  rules: {
    ...
    'jsx-conditional/jsx-conditional': ['error', 'prefer-and-operator', { exceptNotNullishAlternates: true }]
    ...
  }
}