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-undef] this in typeof this is reported as undefined incorrectly #4364

Closed
3 tasks done
Zzzen opened this issue Dec 30, 2021 · 1 comment · Fixed by #4382
Closed
3 tasks done

[no-undef] this in typeof this is reported as undefined incorrectly #4364

Zzzen opened this issue Dec 30, 2021 · 1 comment · Fixed by #4382
Labels
accepting prs Go ahead, send a pull request that resolves this issue AST PRs and Issues about the AST structure bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@Zzzen
Copy link
Contributor

Zzzen commented Dec 30, 2021

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "no-undef": []
  }
}
// Add code below to valid cases of `packages/eslint-plugin/tests/eslint-rules/no-undef.test.ts`
// and run `yarn test no-undef`
const obj = {
  foo: '',
  bar() {
    let foo: typeof this.foo;
  },
};

Expected Result

No error should be reported.

Actual Result

this in typeof this is reported as undefined.

  ● no-undef › valid › 
const obj = {
  foo: '',
  bar() {
    let foo: typeof this.foo;
  },
};
    

    assert.strictEqual(received, expected)

    Expected value to strictly be equal to:
      0
    Received:
      1
    
    Message:
      Should have no errors but had 1: [
      {
        ruleId: 'no-undef',
        severity: 1,
        message: "'this' is not defined.",
        line: 5,
        column: 21,
        nodeType: 'Identifier',
        messageId: 'undef',
        endLine: 5,
        endColumn: 25
      }
    ]

Additional Info

Versions

Tested on latest commit, a9eb0b9.

package version
@typescript-eslint/eslint-plugin X.Y.Z
@typescript-eslint/parser X.Y.Z
TypeScript X.Y.Z
ESLint X.Y.Z
node X.Y.Z
@Zzzen Zzzen added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Dec 30, 2021
@bradzacher
Copy link
Member

bradzacher commented Jan 1, 2022

repro

This is a bug in our AST conversion logic.
We just straight-up convert the AST TS gives us - and in this instance it's wrong. Right now it's creating an AST like this:

{
  type: "TSQualifiedName"
    left: {
      type: "Identifier"
      name: "this"
    }
    right: {
      type: "Identifier"
      name: "foo"
    }
}

when it should be this:

{
  type: "TSQualifiedName"
    left: {
      type: "ThisExpression"
    }
    right: {
      type: "Identifier"
      name: "foo"
    }
}

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers AST PRs and Issues about the AST structure package: typescript-estree Issues related to @typescript-eslint/typescript-estree and removed triage Waiting for maintainers to take a look package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin labels Jan 1, 2022
@armano2 armano2 assigned armano2 and unassigned armano2 Apr 25, 2022
@armano2 armano2 added the has pr there is a PR raised to close this label Apr 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue AST PRs and Issues about the AST structure bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants