Mmohebifar

javascript-enforce-newline-after-imports

Add exactly one empty line after the final top-level `import` declaration block in JavaScript-family files to standardize module preamble formatting and align with `eslint-plugin-import`’s `import/newline-after-import` rule.

eslintimportsformattingjavascripttypescript
Public
0 executions

Run locally

npx codemod javascript-enforce-newline-after-imports

javascript-enforce-newline-after-imports

Add exactly one empty line after the final top-level import declaration block in JavaScript-family files to standardize module preamble formatting and align with eslint-plugin-import’s import/newline-after-import rule.

Installation

bash

Usage

The codemod scans JavaScript and TypeScript module files and normalizes the separator immediately after the final contiguous top-level import block.

  • Targets: *.js, *.jsx, *.mjs, *.cjs, *.ts, *.tsx, *.mts, and *.cts
  • Rewrites only top-level ES module import declarations at the start of the file
  • Preserves shebangs, comments, import ordering, and the file's existing line ending style
  • Keeps line-sensitive pragma comments such as eslint-disable-next-line and @ts-ignore attached to the following statement
  • Treats import type the same as other imports
  • Leaves files unchanged when they already have exactly one blank line after the import preamble, contain no top-level imports, contain only imports, or use only require(...) / dynamic import()
  • Parser failures are reported by the workflow and left unchanged

Example:

ts

becomes:

ts

Run the local package with:

bash

Development

bash

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.