Skip to main content
interlace
Plugin: react-featuresRules

no-namespace

no-namespace rule

no-namespace rule

Prevent namespace imports in React applications. This rule is part of eslint-plugin-react-features.

Quick Summary

AspectDetails
SeverityWarning (optimization)
Auto-Fix❌ No (requires import conversion)
CategoryReact
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForBundle optimization, tree shaking

Rule Details

Namespace imports (import * as X from 'module') prevent effective tree shaking and increase bundle size. Use named imports instead for better optimization.

Why This Matters

IssueImpactSolution
🔄 No tree shakingLarger bundle sizeUse named imports
🐛 Unclear dependenciesHard to see what's usedExplicit imports
🔍 Analysis difficultyStatic analysis less effectiveNamed imports enable tooling

Examples

❌ Incorrect

// BAD: Namespace import imports everything
import * as React from 'react';
import * as utils from './utils';
import * as lodash from 'lodash';

function MyComponent() {
  const value = lodash.get(data, 'nested.value');
  return <React.Fragment>{value}</React.Fragment>;
}

✅ Correct

// GOOD: Named imports enable tree shaking
import React, { Fragment, useState, useEffect } from 'react';
import { formatDate, parseQuery } from './utils';
import get from 'lodash/get';

function MyComponent() {
  const value = get(data, 'nested.value');
  return <Fragment>{value}</Fragment>;
}

// Even better: Use JSX shorthand
function MyComponent() {
  const value = get(data, 'nested.value');
  return <>{value}</>;
}

Configuration Examples

Basic Usage

{
  rules: {
    'react-features/no-namespace': 'warn'
  }
}

Further Reading

Known False Negatives

  • Dynamic imports: const utils = await import('./utils') also yields the whole module namespace and is not reported.

Not reported by design: import type * as T from '...' (erased by TypeScript, nothing is bundled) and export * as ns from '...' (a re-export).

Use this rule

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

oxlint-plugin-react-features re-exports eslint-plugin-react-features/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.