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

Wrong types for eslint-utils' ReferenceTracker #4159

Closed
3 tasks done
roikoren755 opened this issue Nov 15, 2021 · 3 comments · Fixed by #4173
Closed
3 tasks done

Wrong types for eslint-utils' ReferenceTracker #4159

roikoren755 opened this issue Nov 15, 2021 · 3 comments · Fixed by #4173
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: utils Issues related to the @typescript-eslint/utils package

Comments

@roikoren755
Copy link
Contributor

roikoren755 commented Nov 15, 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.

Information

First off, I'd like to thank everyone involved in this project, I couldn't imagine myself linting any TS project without this wonderful set of packages.

I recently started writing a personal ESLint plugin in TypeScript, using many of the tools exported by this package.
In one of the rules I am working on, I use eslint-utils' ReferenceTracker, re-exported under @typescript-eslint/experimental-utils' ASTUtils export. I kept getting { ..., entry: undefined }, no matter what I tried to track.
Comparing the type given to ReferenceTracker in this package with the source code in eslint-utils, it looks like a change was made a long time ago to the return value, such that any info saved in the TraceMap was returned on the info field, rather than the entry one. Could it be that the types are simply out of date? From what I see the type was changed around v1 of eslint-utils, in my case, using v3 of eslint-utils, the types declared by this package don't match the types of eslint-utils.

Repro

import { ASTUtils, ESLintUtils, TSESLint } from '@typescript-eslint/experimental-utils';

const rule = ESLintUtils.RuleCreator((x) => x)({
  name: 'test',
  defaultOptions: [],
  meta: { docs: { description: 'test', recommended: false }, messages: {}, schema: [], type: 'problem' },
  create(context) {
    return {
      'Program:exit'() {
        const referenceTracker = new ASTUtils.ReferenceTracker(context.getScope(), { mode: 'legacy' });
        const results = referenceTracker.iterateGlobalReferences({
          Buffer: { [ASTUtils.ReferenceTracker.READ]: { some: 'information' } },
        });

        for (const result of results) {
          console.log(result);
          console.log(result.entry);
          console.log(result['info']);
        }
      },
    };
  },
});

new TSESLint.RuleTester().run('test', rule, { valid: [{ code: 'Buffer;', env: { node: true } }], invalid: [] });

Expected Result

Logging result.entry to the console should output {some: 'information'}, logging result['info'] should output undefined, as the types suggest.

Actual Result

The reverse, result.entry is empty, result['info'] isn't.

Additional Info

As can be seen in JSDoc comments here, here and here, and in tests for the same file, the information stored in the trace map is returned under the info field of the object, and not the entry field.

Versions

package version
@typescript-eslint/experimental-utils 5.3.1
TypeScript 4.4.4
node 14.18.0
eslint-utils 3.0.0
@roikoren755 roikoren755 added package: utils Issues related to the @typescript-eslint/utils package triage Waiting for maintainers to take a look labels Nov 15, 2021
@bradzacher
Copy link
Member

bradzacher commented Nov 15, 2021

could you please provide some example code so that I can reproduce this locally?

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Nov 15, 2021
@roikoren755
Copy link
Contributor Author

@bradzacher I updated the initial issue with code sample, and added links to some of the relevant places in eslint-utils' source code. I'd be more than happy to open a PR to update the types, if you want :)

@bradzacher
Copy link
Member

The types were added in #294 and they were just assumed to be correct back then as they were authored for us by the owner of the package! But they've been wrong since the beginning ha!

Happy to accept a PR to correct them.

@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 and removed awaiting response Issues waiting for a reply from the OP or another party labels Nov 16, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2021
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 bug Something isn't working good first issue Good for newcomers package: utils Issues related to the @typescript-eslint/utils package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants