import/namespace
eslint-plugin-import
No autofixRecommended
eslint.config.js
import importPlugin from "eslint-plugin-import";
export default [
{
plugins: { import: importPlugin },
rules: {
"import/namespace": "error",
},
},
];Ensure imported namespaces contain dereferenced properties as they are dereferenced.
The documentation shows no incorrect example for this rule.
// @module ./foo
import * as names from './named-exports'
function great() {
return names.a + names.b // so great https://youtu.be/ei7mb8UxEl8
}
function notGreat() {
doSomethingWith(names.c) // Reported: 'c' not found in imported namespace 'names'.
const { a, b, c } = names // also reported, only for 'c'
}
// also tunnels through re-exported namespaces!
function deepTrouble() {
doSomethingWith(names.deep.e) // fine
doSomethingWith(names.deep.f) // Reported: 'f' not found in deeply imported namespace 'names.deep'.
}Examples from the ESLint documentation.
import/namespace
eslint-plugin-import
import importPlugin from "eslint-plugin-import";
export default [
{
plugins: { import: importPlugin },
rules: {
"import/namespace": "error",
},
},
];import/namespace
import plugin · correctness
{
"plugins": [
"import"
],
"rules": {
"import/namespace": "error"
}
}nursery/useValidNamespaceImports
nursery · since 2.6.8
{
"linter": {
"rules": {
"nursery": {
"useValidNamespaceImports": "error"
}
}
}
}Ensure a default export is present, given a default import.
Forbid repeated import of the same module in multiple places.
Forbid any invalid exports, i.e. re-export of the same name.
Forbid use of exported name as identifier of default export.
Forbid use of exported name as property of default export.
Ensure named imports correspond to a named export in the remote file.