Javascript: no-unused-expressions ?

Created on 12 Jul 2018  路  4Comments  路  Source: airbnb/javascript

In zepto.js :

window.$ === undefined && (window.$ = Zepto);

I'm using vscode + eslint + eslint-config-airbnb-base@latest, then show

[eslint] Expected an assignment or function call and instead saw an expression. (no-unused-expressions)

and I change .eslintrc:

"extends": "standard",

the warning disappeared.

Is this a bug or improper grammar ?

question

Most helpful comment

The issue is that you鈥檙e abusing value selection operators for control flow (and also conflating assignment with expressions). Use an if.

All 4 comments

Alright, I found this:
packages/eslint-config-airbnb-base/rules/best-practices.js

// disallow usage of expressions in statement position
    'no-unused-expressions': ['error', {
      allowShortCircuit: false,
      allowTernary: false,
      allowTaggedTemplates: false,
    }],

And this :
eslint-config-standard/eslintrc.json

no-unused-expressions": ["error", { 
"allowShortCircuit": true, 
"allowTernary": true, 
"allowTaggedTemplates": true 
}],

but I don't know which is better, in this circumstance ?
change it to if..else.. statement ?

The issue is that you鈥檙e abusing value selection operators for control flow (and also conflating assignment with expressions). Use an if.

The issue is that you鈥檙e abusing value selection operators for control flow (and also conflating assignment with expressions). Use an if.

Hi, could you elaborate why using value selection operators in this case is a bad practice? Just personally interested in the topic.

@fleksin because their purpose is to select a value. Using them for control flow is using them for something other than their intended purpose - abusing them.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olalonde picture olalonde  路  3Comments

ryankask picture ryankask  路  3Comments

golopot picture golopot  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

ar
mbifulco picture mbifulco  路  3Comments