Skip to content

[Fix] newline-after-import: preserve comments between imports - #3281

Merged
ljharb merged 1 commit into
import-js:mainfrom
raisulchowdhury:agent/fix-newline-after-import-comments
Aug 20, 2026
Merged

[Fix] newline-after-import: preserve comments between imports#3281
ljharb merged 1 commit into
import-js:mainfrom
raisulchowdhury:agent/fix-newline-after-import-comments

Conversation

@raisulchowdhury

Copy link
Copy Markdown
Contributor

Summary

When newline-after-import runs with considerComments, comments between two
imports are part of the import group and should not trigger a blank-line error.
The rule now checks the following import declaration before evaluating the
intervening comment, with a regression test for consecutive imports.

Fixes #2673.

Validation

  • full test suite: 3,121 passing, 2 pending
  • lint and Markdown checks
  • git diff --check

AI assistance

AI assistance was used for investigation and drafting. I reviewed the rule,
test contract, and complete diff, then independently ran the full validation.

The early return also skips comments before a following non-export `import x = require(..)`,
and keeps checking when the next statement is an `export import`;
neither half had coverage.
Both tests are mutation-verified:
removing the TSImportEqualsDeclaration early return fails the new valid test,
and removing the `!isExport` guard fails the new invalid one.

The combined condition is also split into two early returns,
since the repo's `no-extra-parens` setting forbids clarifying the mixed `||`/`&&` precedence with parentheses.

Also brings the changelog entry in line with conventions:
defines the previously dangling `[import-js#2673]` link ref
(markdownlint skips CHANGELOG.md, so CI never catches those),
adds contributor attribution, and moves the entry to the end of the Fixed list.
Copilot AI review requested due to automatic review settings July 31, 2026 23:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ljharb ljharb reopened this Aug 17, 2026
@ljharb
ljharb force-pushed the agent/fix-newline-after-import-comments branch from 9a87957 to 46fa43b Compare August 20, 2026 07:32
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.57%. Comparing base (bd78468) to head (46fa43b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/newline-after-import.js 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3281      +/-   ##
==========================================
- Coverage   79.58%   79.57%   -0.01%     
==========================================
  Files          98       98              
  Lines        4535     4539       +4     
  Branches     1567     1569       +2     
==========================================
+ Hits         3609     3612       +3     
- Misses        926      927       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ljharb
ljharb merged commit 46fa43b into import-js:main Aug 20, 2026
422 checks passed
@ljharb ljharb changed the title fix(newline-after-import): preserve comments between imports [Fix] newline-after-import: preserve comments between imports Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[newline-after-import] Ignore comments between imports

4 participants