These rules enforce consistent import/export style and organization patterns to improve code readability and maintainability. They handle import ordering, grouping, spacing, and export preferences.
Enforces convention in module import order with configurable grouping and sorting.
const order: RuleModule<'order', [
{
groups?: ImportType[][];
pathGroups?: PathGroup[];
pathGroupsExcludedImportTypes?: ImportType[];
distinctGroup?: boolean;
'newlines-between'?: 'ignore' | 'always' | 'always-and-inside-groups' | 'never';
alphabetize?: AlphabetizeOptions;
warnOnUnassignedImports?: boolean;
}?
]>;Options:
groups (ImportType[][]): Order of import groups (default: [builtin, external, internal, parent, sibling, index])pathGroups (PathGroup[]): Custom path groupingsnewlines-between (string): Newline policy between groups (default: ignore)alphabetize (AlphabetizeOptions): Alphabetical sorting optionswarnOnUnassignedImports (boolean): Warn about unassigned imports (default: false)Example:
// ✓ GOOD - properly ordered imports
// 1. Built-in modules
import fs from 'fs';
import path from 'path';
// 2. External modules
import React from 'react';
import lodash from 'lodash';
// 3. Internal modules
import config from '@/config';
import utils from '@/utils';
// 4. Parent modules
import parent from '../parent';
// 5. Sibling modules
import sibling from './sibling';Ensures all imports appear before other statements.
const first: RuleModule<'absolute', [
'absolute-first'?
]>;Options:
'absolute-first' (string): Require absolute imports to come firstExample:
// ✗ BAD - imports after other statements
const config = { debug: true };
import utils from './utils';
// ✓ GOOD - imports first
import utils from './utils';
const config = { debug: true };Enforces having one or more empty lines after the last top-level import statement or require call.
const newlineAfterImport: RuleModule<'newline', [
{
count?: number;
exactCount?: boolean;
considerComments?: boolean;
}?
]>;Options:
count (number): Number of empty lines required (default: 1)exactCount (boolean): Require exact count (default: false)considerComments (boolean): Consider comments between imports and code (default: false)Example:
// ✗ BAD - no newline after imports
import utils from './utils';
const result = utils.process();
// ✓ GOOD - newline after imports
import utils from './utils';
const result = utils.process();Ensures all exports appear after other statements.
const exportsLast: RuleModule<'last', []>;Example:
// ✗ BAD - exports before other statements
export const CONSTANT = 'value';
const helper = () => {};
// ✓ GOOD - exports last
const helper = () => {};
export const CONSTANT = 'value';Prefers named exports to be grouped together in a single export declaration.
const groupExports: RuleModule<'ExportsAtTop', []>;Example:
// ✗ BAD - scattered export declarations
export const foo = 1;
const bar = 2;
export const baz = 3;
export const bar = bar;
// ✓ GOOD - grouped exports
const foo = 1;
const bar = 2;
const baz = 3;
export { foo, bar, baz };Prefers a default export if module exports a single name.
const preferDefaultExport: RuleModule<'single', [
{
target?: 'single' | 'any';
}?
]>;Options:
target (string): When to prefer default export (default: 'single')Example:
// ✗ BAD - single named export (if target: 'single')
export const onlyFunction = () => {};
// ✓ GOOD - default export for single export
const onlyFunction = () => {};
export default onlyFunction;Forbids default exports.
const noDefaultExport: RuleModule<'noDefault', [
{
disallowArrowFunction?: boolean;
}?
]>;Options:
disallowArrowFunction (boolean): Also disallow arrow function default exportsExample:
// ✗ BAD - default export
export default function helper() {}
// ✓ GOOD - named export
export function helper() {}Forbids named exports.
const noNamedExport: RuleModule<'noNamed', []>;Example:
// ✗ BAD - named export
export const helper = () => {};
// ✓ GOOD - default export
const helper = () => {};
export default helper;Forbids unassigned imports (side-effect imports).
const noUnassignedImport: RuleModule<'unassigned', [
{
devDependencies?: boolean | string[];
optionalDependencies?: boolean | string[];
peerDependencies?: boolean | string[];
allow?: string[];
}?
]>;Options:
devDependencies (boolean|string[]): Allow unassigned imports for dev dependenciesallow (string[]): Patterns to allowExample:
// ✗ BAD - unassigned import (unless in allow list)
import './polyfill';
// ✓ GOOD - assigned import
import polyfill from './polyfill';
// ✓ GOOD - if './styles.css' is in allow patterns
import './styles.css';Forbids anonymous default exports.
const noAnonymousDefaultExport: RuleModule<'anonymous', [
{
allowArray?: boolean;
allowArrowFunction?: boolean;
allowLiteral?: boolean;
allowObject?: boolean;
allowNew?: boolean;
}?
]>;Options:
allowArray (boolean): Allow anonymous array exports (default: false)allowArrowFunction (boolean): Allow anonymous arrow functions (default: false)allowLiteral (boolean): Allow anonymous literals (default: false)allowObject (boolean): Allow anonymous objects (default: false)allowNew (boolean): Allow anonymous new expressions (default: false)Example:
// ✗ BAD - anonymous default exports
export default function() {}
export default () => {};
export default class {}
// ✓ GOOD - named default exports
export default function helper() {}
export default () => helper;
const MyClass = class {};
export default MyClass;Limits the maximum number of dependencies a module can have.
const maxDependencies: RuleModule<'max', [
{
max?: number;
ignoreTypeImports?: boolean;
}?
]>;Options:
max (number): Maximum number of dependencies allowed (default: 10)ignoreTypeImports (boolean): Ignore TypeScript type-only imports (default: false)Example:
// ✗ BAD - too many dependencies (if max: 3)
import fs from 'fs';
import path from 'path';
import url from 'url';
import crypto from 'crypto';
// ✓ GOOD - within dependency limit
import fs from 'fs';
import path from 'path';
import url from 'url';interface AlphabetizeOptions {
caseInsensitive: boolean;
order: 'ignore' | 'asc' | 'desc';
orderImportKind: 'ignore' | 'asc' | 'desc';
}
interface PathGroup {
pattern: string;
group: ImportType;
patternOptions?: MinimatchOptions;
position?: 'before' | 'after';
}
type ImportType = 'builtin' | 'external' | 'internal' | 'parent' | 'sibling' | 'index' | 'object' | 'type';
interface NewlineOptions {
count: number;
exactCount: boolean;
considerComments: boolean;
}