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, except for-in and for-of loop variables (see Troubleshooting). 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 names to skip. Supports a leading-* suffix (*.test.ts), an exact path, or a trailing path segment; ** globs are not supported.

Autofix

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

bash
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.
  • for-in / for-of loop variables are not checked — A let binding used as the loop variable in for (let key in obj) or for (let item of arr) is exempt, since adding = undefined there would be invalid syntax.