Skip to main content
interlace
Plugin: import-nextRules

no-named-as-default

Forbid use of exported name as identifier of default export

💼 This rule is enabled in the following configs: recommended, typescript.

Rule Details

A default import bound to the name of a named export of the same module is reported: after import foo from './m', a reader cannot tell whether foo is the module's default or its named foo.

The rule does not read the other module. The evidence that ./m has a named export foo is this file taking that name from the same module: in the same declaration (import foo, { foo as bar } from './m'), in another import (import { foo as bar } from './m'), or in a re-export (export { foo } from './m'). The default can be spelled import foo or import { default as foo }.

Not reported: a default bound to any other name, the name taken from a different module, and evidence that is only a type (import type { foo }, { type foo }), since a type and a default value sharing a name is a judgment call.

❌ Incorrect

import foo, { foo as namedFoo } from './m';

import { default as bar } from './m';
export { bar } from './m';

✅ Correct

import foo from './m';
import { bar } from './m';

import foo2, { type foo2 as Foo } from './m';

Options

[]

Implementation

OWASP Foundation

  • Category: A00:2021 - General Security

Use this rule

npm install -D oxlint-plugin-import-next
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-import-next"],  "rules": {    "import-next/no-named-as-default": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-import-next'],    rules: {      'import-next/no-named-as-default': 'error',    },  },});

oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.