Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

Some modules export many unrelated utilities (like util), where named imports keep the code clear about what is being used. Other modules (like path) group closely related functions under a single namespace, making a default import more practical. This rule lets you enforce the right import style per module.
Recommendedrecommended · ☑️ unopinionated
Fixable
Suggestions
The rule defines four import styles:
  • unassignedimport 'foo' or require('foo')
  • defaultimport path from 'path' or const path = require('path')
  • namespaceimport * as path from 'path'
  • namedimport {inspect} from 'util' or const {inspect} = require('util')
Built-in defaults:
ModuleRequired style
util / node:utilnamed
path / node:pathdefault
chalkdefault
// node:util requires named imports
const util = require('node:util');

// node:util requires named imports
import util from 'node:util';

// node:util requires named imports
import * as util from 'node:util';

Configuration options

styles

Type: object Extend or override the default import styles per module. Each key is a module name; the value is either false (disable all restrictions) or an object mapping style names to true/false.
"unicorn/import-style": [
  "error",
  {
    "styles": {
      "util": false,
      "path": { "named": true }
    }
  }
]
The example above removes all restrictions on util and additionally allows named imports from path (keeping the existing default style allowed too).

extendDefaultStyles

Type: boolean
Default: true
When true, your styles config merges with the built-in defaults. Set to false to replace the defaults entirely.

checkImport

Type: boolean
Default: true
Set to false to skip linting of static import statements.

checkDynamicImport

Type: boolean
Default: true
Set to false to skip linting of dynamic import() expressions.

checkExportFrom

Type: boolean
Default: false
Set to true to also lint export … from re-export statements.

checkRequire

Type: boolean
Default: true
Set to false to skip linting of require() calls.
When the default style is required and you use require(), both const path = require('path') (namespace assignment) and const { default: path } = require('path') (default destructuring) are accepted, because require() has no automatic ES module interop.

Build docs developers (and LLMs) love