Imports & Exports Rules
Import/export formatting, absolute paths, index file conventions, and module exports
On This Page
absolute-imports-only
Use alias imports from index files, no relative imports across folders
Why: Absolute imports are cleaner than ../../../components
Options
| Option | Type | Default | Description |
|---|---|---|---|
aliasPrefix | string | "@/" | Path alias prefix |
extraAllowedFolders | string[] | [] | Additional importable folders |
"code-style/absolute-imports-only": ["error", { aliasPrefix: "@/", extraAllowedFolders: [] }]import { Button, Input } from "@/components";import { useAuth } from "@/hooks";import { Button } from "../../components";import { useAuth } from "../../../hooks";"code-style/absolute-imports-only": "error"export-format
Collapse short exports to one line; expand larger ones
Why: Consistent export formatting improves readability
Options
| Option | Type | Default | Description |
|---|---|---|---|
maxSpecifiers | integer | 3 | Maximum specifiers on single line |
"code-style/export-format": ["error", { maxSpecifiers: 3 }]export { Button, Input, Select }; export { Button, Input, Select, Checkbox,};export { Button, Input, Select, Checkbox, Radio };"code-style/export-format": "error"import-format
Collapse short imports to one line; expand larger ones
Why: Consistent import formatting makes diffs cleaner
Options
| Option | Type | Default | Description |
|---|---|---|---|
maxSpecifiers | integer | 3 | Maximum specifiers on single line |
"code-style/import-format": ["error", { maxSpecifiers: 3 }]import { useState } from "react"; import { useState, useEffect, useCallback, useMemo,} from "react";import { useState, useEffect, useCallback, useMemo, useRef } from "react";"code-style/import-format": "error"import-source-spacing
No leading/trailing spaces inside import path strings
Why: Spaces in module paths are almost always typos
import { Button } from "@mui/material";import { Button } from " @mui/material";"code-style/import-source-spacing": "error"index-export-style
Index files: compact re-exports; regular files: blank lines between exports
Why: Index files are aggregators and should be compact
Options
| Option | Type | Default | Description |
|---|---|---|---|
style | string | "shorthand" | Export style: "shorthand" or "import-export" |
"code-style/index-export-style": ["error", { style: "shorthand" }]// index.jsexport { Button } from "./button";export { Input } from "./form";// index.jsexport { Button } from "./button"; export { Input } from "./form";"code-style/index-export-style": "error"index-exports-only
Index files should only contain imports and re-exports, not code definitions. Subfolder indexes must contain component code (not a barrel); a component index must not re-export sibling modules it does not use — those belong in the module root barrel. Redux subfolders (types/, actions/, reducers/, etc.) are each treated as their own module root.
Why: Index files should be barrels that aggregate exports. Redux is an umbrella folder — each subfolder (types, actions, reducers) is conventionally its own module with its own root barrel.
// src/views/index.ts — root barrelexport { Button } from "./Button";export { helper } from "./utils"; // src/redux/types/index.ts — redux subfolder, barrel allowedexport * from "./auth";export * from "./user";// Root index with inline codeexport const CONSTANT = "value";export function helper() {} // Non-redux subfolder index that's a barrel (e.g., views/dashboard/index)export * from "./header";"code-style/index-exports-only": "error"inline-export-declaration
Enforce inline export declarations instead of grouped export statements
Why: Inline exports make it clear which declarations are public
Options
| Option | Type | Default | Description |
|---|---|---|---|
allowGrouped | boolean | false | Allow grouped exports |
"code-style/inline-export-declaration": ["error", { allowGrouped: false }]export const API_URL = "/api"; export const MAX_RETRIES = 3;const API_URL = "/api";const MAX_RETRIES = 3; export { API_URL, MAX_RETRIES };"code-style/inline-export-declaration": "error"module-index-exports
Index files must export all folder contents. A nested folder item is also considered exported when the module root barrel deep-exports it (e.g. export { CopyButton } from "./button/copy"), so a component index need not re-export its own siblings.
Why: Ensures proper module boundaries and folder-level imports
Options
| Option | Type | Default | Description |
|---|---|---|---|
extraModuleFolders | string[] | [] | Additional module folders to check |
extraIgnorePatterns | string[] | [] | Additional file patterns to skip |
"code-style/module-index-exports": ["error", { extraModuleFolders: [], extraIgnorePatterns: [] }]// components/index.jsexport { Button } from "./Button";export { Input } from "./Input";// components/index.js (missing Input export)export { Button } from "./Button";"code-style/module-index-exports": "error"