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 triggers an error on a function expression constructor #6824

Closed
swang opened this issue Aug 2, 2016 · 5 comments · Fixed by #6827
Closed

no-invalid-this triggers an error on a function expression constructor #6824

swang opened this issue Aug 2, 2016 · 5 comments · Fixed by #6827
Assignees
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

@swang
Copy link

swang commented Aug 2, 2016

What version of ESLint are you using?
v3.2.2
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:

https://gist.github.com/swang/ab31cd9d11593568a6ada2d8badeb92c

What did you do? Please include the actual source code causing the issue.
this is smallest reproduced code that generates this error.

'use strict';

var TestClass;

TestClass = function() {
    this.x = 1;
};

What did you expect to happen?
no-invalid-this should not trigger since TestClass begins with an uppercase letter.

What actually happened? Please include the actual, raw output from ESLint.
I get an error from the no-invalid-this rule

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 2, 2016
@mysticatea mysticatea added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Aug 2, 2016
@mysticatea mysticatea self-assigned this Aug 2, 2016
@mysticatea
Copy link
Member

mysticatea commented Aug 2, 2016

Thank you for this issue.

I confirmed it.

@vitorbal
Copy link
Member

vitorbal commented Aug 2, 2016

It seems like the rule does not check anything for anonymous functions. I was able to confirm as well with the following code on the demo page:

'use strict';

var Foo;

// this is valid
function Foo() {
    this.foo = 'foo';
}

// this is invalid
Foo = function() {
    this.bar = 'bar';
};

@mysticatea
Copy link
Member

mysticatea commented Aug 2, 2016

Yup. Currently, the rule checks whether the destination of assignments is a property or not. But it does not check whether the destination of assignments is an ES5 style constructor (i.e. starts with upper case) or not.

@michaelficarra
Copy link
Member

Who uses this pattern? Why don't you just use a function declaration?

@mysticatea
Copy link
Member

@michaelficarra At least, we can use this to avoid conflict with (func-style: expression & func-names: never).

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 Feb 6, 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.

5 participants