close

no-anonymous-default-export

Added in v0.9.4

Configuration

rslint.config.ts
import { defineConfig, importPlugin } from '@rslint/core';

export default defineConfig([
  importPlugin.configs.recommended,
  {
    rules: {
      'import/no-anonymous-default-export': 'error',
    },
  },
]);

Rule Details

Require a name for default exports of arrays, arrow functions, anonymous function and class declarations, literals, objects, and class instances. Naming these values makes their declarations and imports easier to find.

Examples of incorrect code for this rule:

export default [];
export default () => {};
export default function () {}
export default class {}
export default 123;
export default `hello ${name}`;
export default {};
export default new Service();

Examples of correct code for this rule:

const config = {};
export default config;

export default function initialize() {}
export default class Service {}

// Function calls are allowed by default.
export default createService();

Named exports and re-exports are allowed. Like upstream, the rule also allows expressions such as export default -1, export default (class {}), and export default ({} as Config).

Dynamic imports such as export default import('module') and optional calls such as export default factory?.() are allowed even when allowCallExpression is false.

The rule does not provide automatic fixes or suggestions.

Options

Each option allows its corresponding default export when set to true.

OptionDefaultAllowed export
allowArrayfalseArray expressions
allowArrowFunctionfalseArrow functions
allowAnonymousClassfalseAnonymous class declarations
allowAnonymousFunctionfalseAnonymous function declarations
allowCallExpressiontrueFunction calls
allowNewfalseClass instances created with new
allowLiteralfalseLiterals and templates, including substitutions
allowObjectfalseObject expressions

allowCallExpression defaults to true for compatibility with upstream. With { "allowCallExpression": false }, assign the call result to a variable before exporting it:

// Incorrect
export default createService();

// Correct
const service = createService();
export default service;

Original Documentation