question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-unused-expressions : sequence expressions

See original GitHub issue

Tell us about your environment

  • ESLint Version: v3.15.0
  • Node Version: v7.3.0
  • npm Version: v3.10.8

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration: .eslintrc.js

module.exports = {
    root: true,
    parserOptions: {
        ecmaVersion: 8,
    },
    rules: {
        'no-unused-expressions': [2, { 'allowShortCircuit': true, 'allowTernary': true }]
    }
};

What did you do? Please include the actual source code causing the issue. test.js

let readFile = function (filePath, encoding, cb) {
    if (typeof encoding === 'function')
      cb = encoding, encoding = 'utf8';
    // ...
    return [encoding, cb];
};

What did you expect to happen? As the rule name says “no unused expressions”, I wouldn’t expect an error for the example above.

There is an example in the docs: c = a, b; This is obviously an unused expression and the rule should error in this case. But I can’t see something unused in this one: cb = encoding, encoding = ‘utf8’; It’s just 2 AssignmentExpression inside of a SequenceExpression. So, I am wondering if I’m right and this rule can be changed slightly.

What actually happened? Please include the actual, raw output from ESLint. $ eslint ./test.js > output.txt

C:\nodejs\test\test.js
  3:7  error  Expected an assignment or function call and instead saw an expression  no-unused-expressions

✖ 1 problem (1 error, 0 warnings)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Mar 5, 2017

It’s true that expression isn’t technically useless, but it is confusing to read and there exists a more conventional equivalent:

cb = encoding;
encoding = "utf8";
0reactions
ilyavolodincommented, Mar 7, 2017

I’m going to lock this thread. This is not a right venue for this type of conversation.

P.S. @nemoxps You are having a discussion about knowledge of JS with one of the members of TC39. I don’ t think the argument is on your side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-unused-expressions - ESLint - Pluggable JavaScript Linter
This rule aims to eliminate unused expressions which have no effect on the state of the program. This rule does not apply to...
Read more >
Nice way to get rid of no-unused-expressions linter error with ...
I've made a small plugin called eslint-plugin-chai-friendly that overrides the default no-unused-expressions rule and makes it friendly towards chai.
Read more >
Rule no-unused-expressions - ESLint中文
Disallow Unused Expressions (no-unused-expressions) ... Note: Sequence expressions (those using a comma, such as a = 1, b = 2 ) are always...
Read more >
Disallow Use of the Comma Operator (no-sequences) - ESLint
Disallow Use of the Comma Operator (no-sequences). The comma operator includes multiple expressions where only one is expected. It evaluates each operand ...
Read more >
no-unused-expressions - Rules - ESLint中文文档
禁止未使用过的表达式(no-unused-expressions) ... 对程序状态没有影响的未使用表达式往往是个逻辑错误。 ... 例如, n + 1; 不是语法错误,但它可能是程序员的书写错误,原本 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found