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-return-assign` behavior changed with arrow functions

See original GitHub issue

Using 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:closed
  • Created 8 years ago
  • Reactions:20
  • Comments:35 (20 by maintainers)

github_iconTop GitHub Comments

68reactions
despairbluecommented, Feb 9, 2016

No idea if that is important for this, but using brackets also suppresses the warning, although it’s still returning the assignment.

// Arrow function should not return assignment
const a = (v) => v.b = 1
// passes
const a = (v) => (v.b = 1)
62reactions
nzakascommented, Feb 10, 2016

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.)

Read more comments on GitHub >

github_iconTop 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 >

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