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

False Positive Error with 'this' and object literal shorthand #6013

Closed
jbcpollak opened this issue Apr 29, 2016 · 4 comments
Closed

False Positive Error with 'this' and object literal shorthand #6013

jbcpollak opened this issue Apr 29, 2016 · 4 comments
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

@jbcpollak
Copy link

What version of ESLint are you using?

2.9.0

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

Node v5.7.1, server side code, not using Babel

Please show your full configuration:

// Based on the awesome config from walmart labs:
//https://github.com/walmartlabs/eslint-config-defaults
{
    "extends": "defaults/configurations/google",
    "rules": {
        "max-len": [2, 110, 2],
        "indent": [2, "tab"],
        "dot-location": [2, "property"],
        "no-mixed-spaces-and-tabs": [2, "smart-tabs"],
        "no-console": [2],
        "no-var": [2]
    },
    "env": {
        "node": true,
        "es6": true,
        "mocha": true
    },
    "ecmaFeatures": {
        "modules": true,
        "classes": true,
        "arrowFunctions": true,
        "blockBindings": true,
        "templateStrings": true
    }
}

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

    myFunc() {

        let that = 1;

        log.debug({
            that,
            this
        }, 'log message here');
    }

What did you expect to happen?

No error should be returned

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

  52:4  error  'this' is not defined  no-undef

This code works as expected:

    myFunc() {

        let that = 1;

        log.debug({
            that,
            this: this
        }, 'log message here');
    }

Probably a rare usecase, but in this case we wanted to log 'this' in our logger and have it appear as 'this'.

I think this is a regression, as I think this code has been in place for a while without throwing an error and with the same eslint config. We've just upgraded eslint.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Apr 29, 2016
@mysticatea mysticatea added bug ESLint is working incorrectly rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Apr 30, 2016
@mysticatea
Copy link
Member

mysticatea commented Apr 30, 2016

Thank you for this issue.

let foo = {this};

This is a syntax error.
If you use shorthand properties, you cannot use keywords there.

https://tc39.github.io/ecma262/2016/#prod-ObjectLiteral

PropertyDefinition -> IdentifierReference -> Identifier -> IdentifierName but not ReserevedWord

I will open an issue on Acorn later.

@jbcpollak
Copy link
Author

Interesting. I see it doesn't work in Chrome - either Node accepted it or I never hit that log condition, which seems unlikely. Thanks.

@mysticatea mysticatea self-assigned this Apr 30, 2016
@nzakas nzakas added the blocked This change can't be completed until another issue is resolved label Apr 30, 2016
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 2, 2016
@mysticatea
Copy link
Member

This has been fixed in Acorn.
I'm waiting for the next release.

@mysticatea
Copy link
Member

Now Acorn v3.2.0 has been released: https://github.com/ternjs/acorn/releases/tag/3.2.0

@mysticatea mysticatea removed the blocked This change can't be completed until another issue is resolved label Jun 7, 2016
mysticatea added a commit that referenced this issue Jun 11, 2016
This syntax error came to be raised since Acorn 3.2.0.
This syntax error prevents a false positive of `no-undef` rule.
mysticatea added a commit that referenced this issue Jun 16, 2016
This syntax error came to be raised since Acorn 3.2.0.
This syntax error prevents a false positive of `no-undef` rule.
nzakas pushed a commit that referenced this issue Jun 17, 2016
This syntax error came to be raised since Acorn 3.2.0.
This syntax error prevents a false positive of `no-undef` rule.
@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

No branches or pull requests

4 participants