Skip to main content

Require Undefined Init

Require = undefined when declaring uninitialized variables because an explicit initializer distinguishes intentionally empty declarations from accidental omissions.

Summary

The require-undefined-init rule reports any let declaration that has no initializer. The opposite of ESLint's built-in no-undef-init.

const declarations always require an initializer by the language, so they are not checked.

Why Use This Rule?

  1. Makes the intent of an empty variable declaration explicit — let x = undefined shows the developer chose to leave it empty.
  2. Distinguishes intentional emptiness from a forgotten assignment.
  3. Keeps variable declarations consistent — every let has =.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
ignoreFilesstring[][]File patterns to skip.

Autofix

This rule provides automatic fixes. Run ESLint with the --fix flag:

npx eslint --fix . --rule '@cbnventures/nova/require-undefined-init: error'

Troubleshooting

  • Conflicts with no-undef-init — This rule is the inverse of the built-in no-undef-init. Disable no-undef-init when using this rule.
  • const declarations are not checkedconst requires an initializer by the JavaScript language specification. Only let is checked.