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.

Rule-change (`no-return-assign`) - allow assignment in side effect position of comma operator

See original GitHub issue

Update: @platinumazure suggested I filled out the change-rule template:

What rule do you want to change? no-return-assign

Does this change cause the rule to produce more or fewer warnings? Fewer

How will the change be implemented? (New option, new default behavior, etc.)? Change current default behavior (except-parens)

Please provide some example code that this change will affect:

1. return (x = y, x)
2. return ((x = y), x)
3. return (x = y)
4. return x = y
5. return (x, x = y)
6. return (x, (x = y))

What does the rule currently do for this code?

  1. Reports error
  2. Does not report error
  3. Does not report error
  4. Reports error
  5. Reports error
  6. Does not report error

What will the rule do after it’s changed?

Only 1. will change, 1. will no longer report an error because the assignment is in a position of a sequence (comma operator) that is designed for side effects (see MDN example).


Original issue: no-return-assign - false positive in combination with comma operator

The assignment in the code below is not in ‘return’ position:

[].map(result => (result['x'] = 'y', result))

Example in the online demo

What did you expect to happen?

To have no lint error.

What actually happened? Please include the actual, raw output from ESLint.

It said: Arrow function should not return assignment. (no-return-assign)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Oct 12, 2017

I’m mildly opposed to changing the rule for this case, but I’m not going to stand in the way if others on the team believe this is a worthwhile change.

Would you mind editing your original post to reflect this rule change proposal template? And in exchange, I’ll relabel this issue as a rule change proposal. Thanks!

1reaction
EECOLORcommented, Oct 12, 2017

@platinumazure I don’t think there is a need to apologize. It might have been my prejudice (coming from other interactions about software) that mistakenly took the “However, this is still a case of an assignment in a return statement (the return statement is implicit due to being a concise arrow body)” as closing the door on the subject.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-return-assign - ESLint - Pluggable JavaScript Linter
This rule aims to eliminate assignments from return statements. As such, it will warn whenever an assignment is found as part of return...
Read more >
c++ - How does the Comma Operator work - Stack Overflow
Just a slight comment on the comma-separated initialization list in a class constructor, order is not determined by position in the list. Order...
Read more >
Comma operator (,) - JavaScript - MDN Web Docs
The comma (,) operator evaluates each of its operands (from left to right) and returns the value of the last operand.
Read more >
The GNU C Reference Manual
3.20.1 Side Effects; 3.20.2 Sequence Points; 3.20.3 Sequence Points Constrain ... changing the position of the operator would make no difference.
Read more >
The Walrus Operator: Python 3.8 Assignment Expressions
There's a subtle—but important—difference between the two types of assignments seen earlier with the walrus variable. An assignment expression returns the value ...
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