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 false flags usage in ES2015 static methods #4669

Closed
aparajita opened this Issue Dec 11, 2015 · 6 comments

Comments

Projects
None yet
5 participants
@aparajita
Copy link
Contributor

aparajita commented Dec 11, 2015

What version are you using?

1.10.3

What did you do?

Use this in a static class method, like this:

'use strict';

/* eslint-env node, es6 */
/* eslint no-invalid-this: 2 */

class Foo
{
    static foo()
    {
        console.log('foo');
        this.bar();
    }

    static bar()
    {
        console.log('bar');
    }
}

const f = new Foo();
f.constructor.foo();

// console output
foo
bar

What happened?

When I run eslint --no-eslintrc on this code, I get this error:

  11:9  error  Unexpected `this`  no-invalid-this

What did you expect to happen?

There shouldn't be an error, this code works fine. Using this in a static function to refer to the class is valid in node, Safari and Chrome.

@eslintbot

This comment has been minimized.

Copy link

eslintbot commented Dec 11, 2015

@aparajita Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@eslintbot eslintbot added the triage label Dec 11, 2015

@ilyavolodin

This comment has been minimized.

Copy link
Member

ilyavolodin commented Dec 11, 2015

ESLint doesn't really support experimental features. You might need to make an issue for https://github.com/babel/eslint-plugin-babel

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Dec 11, 2015

@ilyavolodin this is ES6, not experimental.

This is a bug.

@nzakas nzakas added bug rule accepted and removed triage labels Dec 11, 2015

@ilyavolodin

This comment has been minimized.

Copy link
Member

ilyavolodin commented Dec 11, 2015

Ahh.. sorry about that. I was under the impression that static was not part of ES6 spec.

@mysticatea mysticatea self-assigned this Dec 12, 2015

@aparajita

This comment has been minimized.

Copy link
Contributor Author

aparajita commented Dec 12, 2015

It's actually a wrong design decision. The docs for that rule explicitly show this use case as being invalid.

mysticatea added a commit to mysticatea/eslint that referenced this issue Dec 12, 2015

mysticatea added a commit to mysticatea/eslint that referenced this issue Dec 12, 2015

@aparajita

This comment has been minimized.

Copy link
Contributor Author

aparajita commented Dec 13, 2015

Thanks!

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.