Skip to main content

require-i18n-default-locale-in-locales

Require i18n.locales to include i18n.defaultLocale when i18n config is declared.

Targeted pattern scopeโ€‹

This rule targets docusaurus.config.* files and inspects the top-level i18n object.

What this rule reportsโ€‹

This rule reports when:

  • i18n.defaultLocale is missing or statically empty, or
  • i18n.locales does not include i18n.defaultLocale.

Why this rule existsโ€‹

Locale routing and fallback behavior assume the default locale is part of the supported locale set. Keeping defaultLocale and locales aligned avoids hard-to-debug locale routing mismatches.

โŒ Incorrectโ€‹

export default {
i18n: {
defaultLocale: "en",
locales: ["fr"],
},
};

โœ… Correctโ€‹

export default {
i18n: {
defaultLocale: "en",
locales: ["en", "fr"],
},
};

Behavior and migration notesโ€‹

This rule autofixes static-array cases by appending defaultLocale to locales.

When locales is identifier-backed but statically resolvable, it reports and provides a suggestion to replace the property value with an explicit array literal that includes defaultLocale.

When not to use itโ€‹

Do not use this rule if your locale configuration is intentionally dynamic and enforced outside ESLint checks.

Rule catalog ID: R051

Further readingโ€‹