fix: noWrapBeforeImport must wrap first import if no code is before#141
Merged
petermuessig merged 1 commit intomainfrom May 13, 2025
Merged
fix: noWrapBeforeImport must wrap first import if no code is before#141petermuessig merged 1 commit intomainfrom
petermuessig merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the wrapping behavior in noWrapBeforeImport mode so that the first import is correctly processed when there is no code before it.
- Adjusts the conditional logic in visitor.js to handle the first import and its preceding node more explicitly.
- Adds a check in wrapper.js to set the reachedFirstImport flag when no node is marked with lastBeforeWrapping.
- Updates tests and snapshots to validate the updated wrapping behavior.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/plugin/src/modules/visitor.js | Revised conditional logic for marking the previous sibling when applicable. |
| packages/plugin/src/modules/helpers/wrapper.js | Introduced logic to set reachedFirstImport based on lastBeforeWrapping presence. |
| packages/plugin/test/fixtures/... | Added/updated tests and snapshots to cover the new import wrapping behavior. |
Comments suppressed due to low confidence (1)
packages/plugin/src/modules/helpers/wrapper.js:96
- Ensure that the variable 'reachedFirstImport' is declared in the appropriate scope before being assigned; currently, the diff does not show its declaration, which could lead to a runtime ReferenceError.
if (!fullBody.find((item) => item.lastBeforeWrapping)) {
Comment on lines
+207
to
+208
| // for the first element there is a special case as we can't mark the previous one | ||
| // therefore we do not mark anything to make clear that there's nothing to exclude |
There was a problem hiding this comment.
[nitpick] Consider clarifying in the comment that when path.key equals 0 no marking takes place because there is no valid previous node, to improve maintainability and ease of understanding of this special case.
Suggested change
| // for the first element there is a special case as we can't mark the previous one | |
| // therefore we do not mark anything to make clear that there's nothing to exclude | |
| // For the first element, there is a special case: when path.key === 0, we can't mark the previous node | |
| // because there is no valid previous node. Therefore, we do not mark anything to make clear that there's nothing to exclude. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.