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?
- Makes the intent of an empty variable declaration explicit —
let x = undefinedshows the developer chose to leave it empty. - Distinguishes intentional emptiness from a forgotten assignment.
- Keeps variable declarations consistent — every
lethas=.
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.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | 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-inno-undef-init. Disableno-undef-initwhen using this rule. constdeclarations are not checked —constrequires an initializer by the JavaScript language specification. Onlyletis checked.