ihordiachenko / eslint-plugin-chai-friendly

Makes eslint friendly towards Chai.js 'expect' and 'should' statements.
MIT License
53 stars 10 forks source link

Throws an error on some ternary expressions #1

Closed eTorAken closed 7 years ago

eTorAken commented 7 years ago

Hi,

First of all, thanks for your plugin! We integrated it to our project and it works like a charm 👍

However, we are experiencing a difference with the native ESLint no-unused-expressions. It seems to throw an error with that kind of ternary expressions:

this.refInput ? this.refInput.focus() : this.refInner.focus(); 
// => throws "Expected an assignment or function call and instead saw en expression.
// (chai-friendly/no-unused-expressions)"

We have to write it that way to make it pass:

if(this.refInput) {
  this.refInput.focus();
}
else {
  this.refInner.focus();
}

but it's way less easier to read and write.

FYI, this is not a problem when using native rule from eslint@3.17.0.

ihordiachenko commented 7 years ago

Hi, thanks for your feedback!

You can use the allowTernary option to allow this pattern:

{
  "rules": {
    "chai-friendly/no-unused-expressions": ["error", {"allowTernary": true}]
  }
}

Plugin supports all original rule's options. I'll add them to readme too.

eTorAken commented 7 years ago

Thanks for this precision. Indeed, I think it might be important to speak about it in the readme as I did not find it that obvious.