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

linter: eslint/no-undef fails on ts type NodeListOf #7008

Open
Sysix opened this issue Oct 29, 2024 · 3 comments
Open

linter: eslint/no-undef fails on ts type NodeListOf #7008

Sysix opened this issue Oct 29, 2024 · 3 comments
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers

Comments

@Sysix
Copy link
Contributor

Sysix commented Oct 29, 2024

What version of Oxlint are you using?

0.10.3

What command did you run?

oxlint -c .oxlint.json

What does your .oxlint.json config file look like?

{
  "env": {
    "browser": true
  },
  "categories": {
    "correctness": "off"
  },
  "rules": {
    "no-undef": "error"
  }
}

What happened?

It does not know about this specific types:

  × eslint(no-undef): 'NodeListOf' is not defined.
    ╭─[src/index.ts:11:12]
 10 │ 
 11 │ const xyz: NodeListOf<HTMLElement> = document.querySelectorAll('.xxxx');
    ·            ──────────
 12 │ 
    ╰────

Others lines like: const abc: Element | null = document.querySelector('.xxx'); are working

@Sysix Sysix added A-linter Area - Linter C-bug Category - Bug labels Oct 29, 2024
@Boshen Boshen added the good first issue Experience Level - Good for newcomers label Oct 30, 2024
@Boshen
Copy link
Member

Boshen commented Oct 30, 2024

no-undef is still under nurser, PRs welcome!

The fix should be checking for symbol flags.

@shulaoda
Copy link
Contributor

Actually, this will also report an error, and I think this is expected behavior? See typescript-eslint

  ⚠ eslint(no-undef): 'Element' is not defined.
   ╭─[no_undef.tsx:1:12]
 1 │ const abc: Element | null = document.querySelector('.xxx');
   ·            ───────
   ╰────

  ⚠ eslint(no-undef): 'document' is not defined.
   ╭─[no_undef.tsx:1:29]
 1 │ const abc: Element | null = document.querySelector('.xxx');
   ·                             ────────
   ╰────

@mimbrown
Copy link

mimbrown commented Nov 1, 2024

I think the issue here is that NodeListOf is a typescript-only type, it's not a runtime global. Oxlint also warns on standard Typescript helper types like Partial:

  ⚠ eslint(no-undef): 'Partial' is not defined.
   ╭─[test.ts:5:10]
 4 │ 
 5 │ const a: Partial<Name> = {}
   ·          ───────
   ╰────

So I think the options are:

  1. Add support for TypeScript globals, not just JS ones
  2. Skip TS types completely for this lint rule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@Boshen @Sysix @mimbrown @DonIsaac @shulaoda and others