Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"no-invalid-this" gives false-negative result #9126

Closed
vitalymak opened this issue Aug 18, 2017 · 3 comments · Fixed by #9258
Closed

"no-invalid-this" gives false-negative result #9126

vitalymak opened this issue Aug 18, 2017 · 3 comments · Fixed by #9258
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@vitalymak
Copy link

vitalymak commented Aug 18, 2017

  • ESLint Version: 4.4.1
  • Node Version: 8.2.1
  • npm Version: 5.3.0

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

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

../node_modules/.bin/eslint --no-eslintrc no-invalid-this-test.js 

no-invalid-this-test.js file contents:

/*eslint no-invalid-this: "error"*/
/*eslint-env es6*/

let o = {
    name: "O name",
    f: function() {
        console.log(this.name)
    }
};

o.f = ((func, arg) => function() {
    console.log('Executing wrapper with arg ' + arg);
    func.call(this);
})(o.f, 'blah');

o.f();

What did you expect to happen?
No error.

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

/Users/vitaly/Work/n/build/no-invalid-this-test.js
  13:15  error  Unexpected 'this'  no-invalid-this

✖ 1 problem (1 error, 0 warnings)
@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 18, 2017
@not-an-aardvark
Copy link
Member

Thanks for the report. However, this is working as intended -- the rule documentation defines what it means for a use of this to be "valid", and your code does not meet that definition.

@not-an-aardvark not-an-aardvark added works as intended The behavior described in this issue is working correctly and removed triage An ESLint team member will look at this issue soon labels Aug 18, 2017
@vitalymak
Copy link
Author

But this doesn't give an error:

/*eslint no-invalid-this: "error"*/
/*eslint-env es6*/

let o = {
    name: "O name",
    f: function() {
        console.log(this.name)
    }
};

o.f = ((func, arg) => {return function() {
    console.log('Executing wrapper with arg ' + arg);
    func.call(this);
}})(o.f, 'blah');

o.f();

diff lines:

--- o.f = ((func, arg) => function() {
+++ o.f = ((func, arg) => {return function() {
--- })(o.f, 'blah');
+++ }})(o.f, 'blah');

@not-an-aardvark
Copy link
Member

Hmm, it looks like there's some special logic being used for return statements to check for method assignments (relevant code). We should probably update that to check for arrow function returns as well.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed works as intended The behavior described in this issue is working correctly labels Aug 23, 2017
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 10, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants