Mmohebifar

javascript-no-undef-init-variable-declarations

Remove redundant bare `= undefined` initializers from `var` and `let` declarations in JavaScript and TypeScript source files.

javascripttypescripteslintno-undef-initcode-quality
Public
0 executions

Run locally

npx codemod javascript-no-undef-init-variable-declarations

javascript-no-undef-init-variable-declarations

Remove redundant bare = undefined initializers from var and let declarations so code matches ESLint no-undef-init without changing runtime behavior.

Installation

bash

Usage

This codemod updates JavaScript and TypeScript source files and removes only declarator initializers where all of the following are true:

  • The declaration kind is var or let
  • The declarator name is a plain identifier
  • The initializer is the bare identifier undefined

Examples:

js

becomes:

js

The codemod intentionally leaves these cases unchanged:

  • const x = undefined
  • let x = void 0
  • let x = globalThis.undefined
  • Destructuring declarations such as let { a = undefined } = obj
  • Ambient TypeScript declarations such as declare let x = undefined
  • Declarations inside with (...) blocks

workflow.yaml excludes common generated, vendored, and test locations such as node_modules, dist, build, vendor, tests, and __tests__, skips .d.ts files, and includes TSX files.

Development

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.