eslint-plugin-react-namespace-import
raw JSON → 1.0.5 verified Sat Apr 25 auth: no javascript
An ESLint plugin that enforces namespace imports (import * as React from 'react') over named or default imports from the React package. Version 1.0.5 is current, with stable API since initial release. Key differentiator: focused solely on a single rule to enforce consistent React import style, unlike broader linting configs. Low maintenance frequency.
Common errors
error ESLint couldn't find the plugin "eslint-plugin-react-namespace-import". ↓
cause Plugin not installed or not in node_modules.
fix
Run npm install --save-dev eslint-plugin-react-namespace-import
error Configuration for rule "react-namespace-import/no-namespace-import" is invalid. ↓
cause Rule referenced incorrectly in plugins or rules section.
fix
Ensure plugin is in 'plugins' array, not 'extends', and rule name is correct.
error Cannot read properties of undefined (reading 'no-namespace-import') ↓
cause Plugin not loaded due to missing or mismatched eslint version.
fix
Ensure eslint version >=0.8.0 and plugin is installed.
Warnings
gotcha The rule only applies to imports from 'react' package; does not check aliases like 'react-dom' or other packages. ↓
fix Only enforces namespace imports for 'react'; other packages ignored.
deprecated Plugin uses 'no-namespace-import' rule name which is confusing (it actually enforces namespace import). ↓
fix No fix available; rule name remains as is. Consider it as 'enforce-namespace-import' mentally.
gotcha When using recommended config, the rule is set to 'warn' by default, not 'error'. ↓
fix Override rule severity in your own .eslintrc if you want errors.
gotcha Plugin does not support customizing the package name to enforce; hardcoded to 'react'. ↓
fix Use another plugin if you need to enforce namespace imports for other packages.
Install
npm install eslint-plugin-react-namespace-import yarn add eslint-plugin-react-namespace-import pnpm add eslint-plugin-react-namespace-import Imports
- plugin wrong
import { rules } from 'eslint-plugin-react-namespace-import'correctimport plugin from 'eslint-plugin-react-namespace-import' - rules wrong
const rules = require('eslint-plugin-react-namespace-import').rulescorrectconst { rules } = require('eslint-plugin-react-namespace-import') - configs.recommended
import { configs } from 'eslint-plugin-react-namespace-import'
Quickstart
// Install plugin
npm install --save-dev eslint eslint-plugin-react-namespace-import
// .eslintrc.json
{
"extends": ["plugin:react-namespace-import/recommended"],
"rules": {
"react-namespace-import/no-namespace-import": "error"
}
}
// Example code that will fail lint:
// import React from 'react';
// Correct: import * as React from 'react';