Skip to content

linter: (no-restricted-imports): rule reports once per named specifier instead of once per import declaration #21920

Description

@pedromtec

What version of Oxlint are you using?

1.62.0

What command did you run?

pnpm run lint

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": [
      "typescript",
      "react"
  ],
  "categories": {
    "correctness": "error"
  },
  "env": {
    "builtin": true
  },
  "ignorePatterns": [
    "dist"
  ],
  "rules": {
    "no-restricted-imports": [
      "error",
      {
         "name": "react",
         "message": "Example: React is not allowed to be imported"
      }
    ]
  }
}

What happened?

Input (src/App.tsx):

import { useState, useEffect, useCallback } from 'react'

Actual behavior — oxlint reports the same diagnostic 3 times (once per named specifier), all pointing to the full ImportDeclaration span:


  × eslint(no-restricted-imports): 'react' import is restricted from being used.
   ╭─[src/App.tsx:1:1]
 1 │ import { useState, useEffect, useCallback } from 'react'
   · ────────────────────────────────────────────────────────
 2 │ import reactLogo from './assets/react.svg'
   ╰────
  help: Example: React is not allowed to be imported

  × eslint(no-restricted-imports): 'react' import is restricted from being used.
   ╭─[src/App.tsx:1:1]
 1 │ import { useState, useEffect, useCallback } from 'react'
   · ────────────────────────────────────────────────────────
 2 │ import reactLogo from './assets/react.svg'
   ╰────
  help: Example: React is not allowed to be imported

  × eslint(no-restricted-imports): 'react' import is restricted from being used.
   ╭─[src/App.tsx:1:1]
 1 │ import { useState, useEffect, useCallback } from 'react'
   · ────────────────────────────────────────────────────────
 2 │ import reactLogo from './assets/react.svg'
   ╰────
  help: Example: React is not allowed to be imported

(repeated 3x)
I don't get that behavior with that rule using eslint: https://eslint.org/docs/latest/rules/no-restricted-imports

Metadata

Metadata

Assignees

Labels

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions