Rules that enforce consistent import formatting, organization, and style conventions across your codebase.
Enforces or bans the use of inline type-only markers for named imports.
/**
* Enforce or ban the use of inline type-only markers for named imports
* @type {Rule.RuleModule}
*/
"import/consistent-type-specifier-style": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Enforce or ban the use of inline type-only markers for named imports.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/consistent-type-specifier-style.md"
},
schema: [{
type: "string",
enum: ["prefer-inline", "prefer-top-level"],
default: "prefer-inline"
}],
fixable: "code"
},
create: (context) => Rule.RuleListener
}Usage Examples:
// With "prefer-inline" (default)
// ✅ Valid - inline type specifiers
import { type User, type Config, getData } from "./api";
// ❌ Invalid - top-level type import
import type { User, Config } from "./api"; // Error: Use inline type specifiers
import { getData } from "./api";
// With "prefer-top-level"
// ✅ Valid - top-level type import
import type { User, Config } from "./api";
import { getData } from "./api";
// ❌ Invalid - inline type specifiers
import { type User, type Config, getData } from "./api"; // Error: Use top-level type importEnforces a leading comment with the webpackChunkName for dynamic imports.
/**
* Enforce a leading comment with the webpackChunkName for dynamic imports
* @type {Rule.RuleModule}
*/
"import/dynamic-import-chunkname": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Enforce a leading comment with the webpackChunkName for dynamic imports.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/dynamic-import-chunkname.md"
},
schema: [{
type: "object",
properties: {
importFunctions: {
type: "array",
uniqueItems: true,
items: { type: "string" }
},
allowEmpty: { type: "boolean", default: false },
webpackChunknameFormat: {
type: "string",
default: "[0-9a-zA-Z-_/.]+"
}
},
additionalProperties: false
}],
hasSuggestions: true
},
create: (context) => Rule.RuleListener
}Usage Examples:
// ✅ Valid - with webpackChunkName comment
const LazyComponent = lazy(() =>
import(/* webpackChunkName: "lazy-component" */ "./LazyComponent")
);
// ❌ Invalid - missing webpackChunkName
const LazyComponent = lazy(() =>
import("./LazyComponent") // Error: Missing webpackChunkName comment
);
// ✅ Valid - multiple webpack comments
const LazyComponent = lazy(() =>
import(
/* webpackChunkName: "lazy-component" */
/* webpackMode: "lazy" */
"./LazyComponent"
)
);Ensures all exports appear after other statements.
/**
* Ensure all exports appear after other statements
* @type {Rule.RuleModule}
*/
"import/exports-last": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Ensure all exports appear after other statements.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/exports-last.md"
},
schema: []
},
create: (context) => Rule.RuleListener
}Usage Examples:
// ❌ Invalid - exports before other statements
export const foo = "bar";
import { helper } from "./helper"; // Error: Export should come after imports
const value = calculate();
// ✅ Valid - exports after other statements
import { helper } from "./helper";
const value = calculate();
const foo = "bar";
export { foo, value };Ensures consistent use of file extension within the import path.
/**
* Ensure consistent use of file extension within the import path
* @type {Rule.RuleModule}
*/
"import/extensions": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Ensure consistent use of file extension within the import path.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/extensions.md"
},
schema: {
anyOf: [
{
type: "array",
items: [
{
type: "string",
enum: ["always", "ignorePackages", "never"]
}
],
additionalItems: {
type: "object",
patternProperties: {
".*": {
type: "string",
enum: ["always", "ignorePackages", "never"]
}
}
}
},
{
type: "array",
items: [
{
type: "object",
patternProperties: {
".*": {
type: "string",
enum: ["always", "ignorePackages", "never"]
}
}
}
],
additionalItems: {
type: "object",
patternProperties: {
".*": {
type: "string",
enum: ["always", "ignorePackages", "never"]
}
}
}
}
]
}
},
create: (context) => Rule.RuleListener
}Ensures all imports appear before other statements.
/**
* Ensure all imports appear before other statements
* @type {Rule.RuleModule}
*/
"import/first": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Ensure all imports appear before other statements.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/first.md"
},
schema: [{
type: "string",
enum: ["absolute-first", "disable-absolute-first"],
default: "absolute-first"
}],
fixable: "code"
},
create: (context) => Rule.RuleListener
}Usage Examples:
// ❌ Invalid - imports after other statements
const foo = "bar";
import { helper } from "./helper"; // Error: Import should come first
// ✅ Valid - imports before other statements
import { helper } from "./helper";
import express from "express";
const foo = "bar";
const app = express();Prefers named exports to be grouped together in a single export declaration.
/**
* Prefer named exports to be grouped together in a single export declaration
* @type {Rule.RuleModule}
*/
"import/group-exports": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Prefer named exports to be grouped together in a single export declaration.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/group-exports.md"
},
schema: []
},
create: (context) => Rule.RuleListener
}Usage Examples:
// ❌ Invalid - multiple export statements
export const foo = "foo";
export const bar = "bar";
export function baz() {}
// ✅ Valid - grouped exports
const foo = "foo";
const bar = "bar";
function baz() {}
export { foo, bar, baz };Replaced by import/first. (DEPRECATED)
/**
* Replaced by import/first (DEPRECATED)
* @type {Rule.RuleModule}
* @deprecated Use import/first instead
*/
"import/imports-first": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Replaced by `import/first`.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/imports-first.md"
},
schema: [{
type: "string",
enum: ["absolute-first", "disable-absolute-first"],
default: "absolute-first"
}],
fixable: "code",
deprecated: true
},
create: (context) => Rule.RuleListener
}Enforces the maximum number of dependencies a module can have.
/**
* Enforce the maximum number of dependencies a module can have
* @type {Rule.RuleModule}
*/
"import/max-dependencies": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Enforce the maximum number of dependencies a module can have.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/max-dependencies.md"
},
schema: [{
type: "object",
properties: {
max: { type: "integer", minimum: 0, default: 10 },
ignoreTypeImports: { type: "boolean", default: false }
},
additionalProperties: false
}]
},
create: (context) => Rule.RuleListener
}Enforces a newline after import statements.
/**
* Enforce a newline after import statements
* @type {Rule.RuleModule}
*/
"import/newline-after-import": {
meta: {
type: "layout",
docs: {
category: "Style guide",
description: "Enforce a newline after import statements.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/newline-after-import.md"
},
schema: [{
type: "object",
properties: {
count: { type: "integer", minimum: 1, default: 1 },
exactCount: { type: "boolean", default: false },
considerComments: { type: "boolean", default: false }
},
additionalProperties: false
}],
fixable: "whitespace"
},
create: (context) => Rule.RuleListener
}Forbids anonymous values as default exports.
/**
* Forbid anonymous values as default exports
* @type {Rule.RuleModule}
*/
"import/no-anonymous-default-export": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Forbid anonymous values as default exports.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-anonymous-default-export.md"
},
schema: [{
type: "object",
properties: {
allowArray: { type: "boolean", default: false },
allowArrowFunction: { type: "boolean", default: false },
allowAnonymousClass: { type: "boolean", default: false },
allowAnonymousFunction: { type: "boolean", default: false },
allowCallExpression: { type: "boolean", default: true },
allowNew: { type: "boolean", default: false },
allowLiteral: { type: "boolean", default: false },
allowObject: { type: "boolean", default: false }
},
additionalProperties: false
}]
},
create: (context) => Rule.RuleListener
}Forbids default exports.
/**
* Forbid default exports
* @type {Rule.RuleModule}
*/
"import/no-default-export": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Forbid default exports.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-default-export.md"
},
schema: []
},
create: (context) => Rule.RuleListener
}Forbids repeated import of the same module in multiple places.
/**
* Forbid repeated import of the same module in multiple places
* @type {Rule.RuleModule}
*/
"import/no-duplicates": {
meta: {
type: "problem",
docs: {
category: "Style guide",
description: "Forbid repeated import of the same module in multiple places.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-duplicates.md"
},
schema: [{
type: "object",
properties: {
considerQueryString: { type: "boolean", default: false },
"prefer-inline": { type: "boolean", default: false }
},
additionalProperties: false
}],
fixable: "code"
},
create: (context) => Rule.RuleListener
}Forbids named default exports.
/**
* Forbid named default exports
* @type {Rule.RuleModule}
*/
"import/no-named-default": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Forbid named default exports.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-named-default.md"
},
schema: []
},
create: (context) => Rule.RuleListener
}Forbids named exports.
/**
* Forbid named exports
* @type {Rule.RuleModule}
*/
"import/no-named-export": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Forbid named exports.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-named-export.md"
},
schema: []
},
create: (context) => Rule.RuleListener
}Forbids namespace (a.k.a. "wildcard" *) imports.
/**
* Forbid namespace (a.k.a. "wildcard" *) imports
* @type {Rule.RuleModule}
*/
"import/no-namespace": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Forbid namespace (a.k.a. \"wildcard\" `*`) imports.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-namespace.md"
},
schema: [{
type: "object",
properties: {
ignore: {
type: "array",
items: { type: "string" },
default: []
}
},
additionalProperties: false
}],
fixable: "code"
},
create: (context) => Rule.RuleListener
}Forbids unassigned imports.
/**
* Forbid unassigned imports
* @type {Rule.RuleModule}
*/
"import/no-unassigned-import": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Forbid unassigned imports",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-unassigned-import.md"
},
schema: [{
type: "object",
properties: {
devDependencies: {
type: ["boolean", "array"],
default: true
},
optionalDependencies: {
type: ["boolean", "array"],
default: false
},
peerDependencies: {
type: ["boolean", "array"],
default: false
},
allow: {
type: "array",
items: { type: "string" }
}
},
additionalProperties: false
}]
},
create: (context) => Rule.RuleListener
}Enforces a convention in module import order.
/**
* Enforce a convention in module import order
* @type {Rule.RuleModule}
*/
"import/order": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Enforce a convention in module import order.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/order.md"
},
schema: [{
type: "object",
properties: {
groups: {
type: "array",
items: {
oneOf: [
{ type: "string", enum: ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"] },
{
type: "array",
items: { type: "string", enum: ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"] },
minItems: 1
}
]
},
default: ["builtin", "external", "parent", "sibling", "index"]
},
"newlines-between": {
type: "string",
enum: ["ignore", "always", "always-and-inside-groups", "never"],
default: "ignore"
},
pathGroups: {
type: "array",
items: {
type: "object",
properties: {
pattern: { type: "string" },
group: { type: "string", enum: ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"] },
position: { type: "string", enum: ["before", "after"] }
},
additionalProperties: false,
required: ["pattern", "group"]
}
},
pathGroupsExcludedImportTypes: {
type: "array",
items: { type: "string", enum: ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"] },
default: ["builtin"]
},
distinctGroup: { type: "boolean", default: true },
alphabetize: {
type: "object",
properties: {
order: { type: "string", enum: ["ignore", "asc", "desc"], default: "ignore" },
orderImportKind: { type: "string", enum: ["ignore", "asc", "desc"], default: "ignore" },
caseInsensitive: { type: "boolean", default: false }
},
additionalProperties: false
},
warnOnUnassignedImports: { type: "boolean", default: false }
},
additionalProperties: false
}],
fixable: "code"
},
create: (context) => Rule.RuleListener
}Prefers a default export if module exports a single name or multiple names.
/**
* Prefer a default export if module exports a single name or multiple names
* @type {Rule.RuleModule}
*/
"import/prefer-default-export": {
meta: {
type: "suggestion",
docs: {
category: "Style guide",
description: "Prefer a default export if module exports a single name or multiple names.",
url: "https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/prefer-default-export.md"
},
schema: [{
type: "object",
properties: {
target: {
type: "string",
enum: ["single", "any"],
default: "single"
}
},
additionalProperties: false
}]
},
create: (context) => Rule.RuleListener
}Style guide rules can be configured in your ESLint configuration:
// ESLint flat config
export default [{
plugins: { import: importPlugin },
rules: {
"import/consistent-type-specifier-style": ["error", "prefer-inline"],
"import/dynamic-import-chunkname": "error",
"import/exports-last": "error",
"import/extensions": ["error", "ignorePackages", { "js": "never", "ts": "never" }],
"import/first": "error",
"import/group-exports": "error",
"import/max-dependencies": ["error", { "max": 15 }],
"import/newline-after-import": "error",
"import/no-anonymous-default-export": "error",
"import/no-default-export": "off",
"import/no-duplicates": "error",
"import/no-named-default": "error",
"import/no-named-export": "off",
"import/no-namespace": "error",
"import/no-unassigned-import": ["error", { "allow": ["**/*.css"] }],
"import/order": ["error", {
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
"newlines-between": "always",
"alphabetize": { "order": "asc", "caseInsensitive": true }
}],
"import/prefer-default-export": "off"
}
}];