Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 496943

Summary: [eslint] no-self-assign rule doesn't handle assignment operators like +=
Product: [ECD] Orion Reporter: Curtis Windatt <curtis.windatt.public>
Component: JS ToolsAssignee: Curtis Windatt <curtis.windatt.public>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Michael_Rennie, Olivier_Thomann
Version: 12.0   
Target Milestone: 13.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Curtis Windatt CLA 2016-06-28 11:40:45 EDT
var a = 2;
a += a;

The second line is marked as a problem.  Assigning to itself is pointless.  This is obviously not correct.
Comment 1 Olivier Thomann CLA 2016-06-28 12:16:44 EDT
This is less clear than a = a;
a += a; really means: a = a + a;
So this means the same as: a *= 2;

So I would not include this check for no-self-assign rule. Am I missing something ?
Comment 2 Curtis Windatt CLA 2016-06-28 12:26:11 EDT
(In reply to Olivier Thomann from comment #1)
> So I would not include this check for no-self-assign rule. Am I missing
> something ?

The check is included today.  a **= a, a -= a, a *= a are all marked as 'assigning to itself is pointless'.  What the code is doing could be expressed more clearly, but the error message is wrong.  I am suggesting we don't mark these as errors.
Comment 3 Michael Rennie CLA 2016-06-28 14:32:39 EDT
(In reply to Curtis Windatt from comment #2)
> (In reply to Olivier Thomann from comment #1)
> > So I would not include this check for no-self-assign rule. Am I missing
> > something ?
> 
> The check is included today.  a **= a, a -= a, a *= a are all marked as
> 'assigning to itself is pointless'.  What the code is doing could be
> expressed more clearly, but the error message is wrong.  I am suggesting we
> don't mark these as errors.

We should only be marking an assignment with the '=' operator. All the info is in the node itself.

We should also try to support default values, spread elements and update the warning message to match upstream eslint: "'{{name}}' is assigned to itself."