import/no-namespace
Disallow import * as name in favor of named imports
fixable
Also called import-x/no-namespace
import * as utils doesn't tell you which exports a file uses. You have to search for every utils. to find out. A typo such as utils.clmap is only undefined at runtime, while a named import of a name that doesn't exist is an error when the module loads.
--fix turns the namespace into named imports if it's only used as utils.name. If you pass the namespace object itself around, or never use it, --fix leaves it alone.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"import/no-namespace" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"import/no-namespace" = ["error", {
ignore = [], # list of strings
}]Examples#
example.js1 problem
import * as utilsUnexpected namespace import. from "./utils";
const width = utils.clamp(utils.sum(sizes), 0, 100);example.jsNo problems
import { clamp, sum } from "./utils";
const width = clamp(sum(sizes), 0, 100);Options#
| Option | Default | What it does |
|---|---|---|
ignore | [] | Globs for import paths you can import as a namespace. A glob without a / is matched against the last part of the path. |
example.jswith
{ "ignore": ["*.css"] }No problemsimport * as styles from "./components/button.module.css";example.jswith
{ "ignore": ["*.css"] }1 problemimport * as utilsUnexpected namespace import. from "./utils";