`no-return-assign` behavior changed with arrow functions
See original GitHub issueUsing the latest eslint (2.0.0-rc.0).
Rule:
{
"no-return-assign": 2
}
Code:
var data = ''
process.stdin.on('data', buffer => data += buffer.toString())
Produces the error:
2:26 error Arrow function should not return assignment no-return-assign
The rule is functioning correctly, because there’s an implicit return with arrow functions. But I’m wondering if there isn’t a way to keep the rule enabled but accommodate this kind of usage with arrow functions.
The intent of the rule is, primarily, to catch cases where the user intended a comparison but accidentally did an assignment. There’s no chance of that in this example because it’s +=
not =
, yet this is still considered an error because there’s an assignment happening.
Possible ways to accommodate this:
- add an
except-arrow-function
option, to disable checking on arrow functions - add a way to specify only checking for assignments with
=
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 8 years ago
- Reactions:20
- Comments:35 (20 by maintainers)
Top Results From Across the Web
Arrow function should not return assignment? - Stack Overflow
You're implicitly returning an assignment. this.myCustomEl = el is an assignment. You could fix this linting error by changing your arrow ...
Read more >Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >Anomalies in JavaScript arrow functions - LogRocket Blog
Arrow functions behave differently from regular JS functions — think of them as functions with anomalies. Learn how you can use this to...
Read more >Understanding Arrow Functions in JavaScript | DigitalOcean
Arrow functions are a new way to write anonymous function expressions in JavaScript, and are similar ... Arrow Function Behavior and Syntax.
Read more >5 Differences Between Arrow and Regular Functions
The behavior of this inside of an arrow function differs ... or myArrowFunc.apply(thisVal) doesn't change the value of this : the context ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No idea if that is important for this, but using brackets also suppresses the warning, although it’s still returning the assignment.
At the moment, it doesn’t seem like there’s much support for adding an exception to the rule, so closing (as always, we’ll monitor to see if similar issues pop up in the future.)