Skip to content

Fix specifier sorting inserting semicolons #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-jars-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-import-sorting': patch
---

Fix semicolons being added to end of import specifiers after sorting
1 change: 1 addition & 0 deletions src/rules/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default createRule<unknown[], MessageId>({
isEslintDisabled: isNodeEslintDisabled(node, eslintDisabledLines),
name,
node,
shouldAddSafetySemicolonWhenInline: true,
size: rangeToDiff(node, sourceCode),
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/make-fixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function makeFixes({
let sortingNode = nodes.at(index)!
let sortedSortingNode = sortedNodes.at(index)!
let { node } = sortingNode
let { node: sortedNode } = sortedSortingNode
let { shouldAddSafetySemicolonWhenInline, node: sortedNode } = sortedSortingNode
let isNodeFirstNode = node === nodes.at(0)!.node
let isSortedNodeFirstNode = sortedNode === nodes.at(0)!.node

Expand All @@ -50,6 +50,7 @@ export function makeFixes({
let isNextTokenOnSameLineAsNode = nextToken?.loc.start.line === node.loc.end.line
let isNextTokenSafeCharacter = nextToken?.value === ';' || nextToken?.value === ','
if (
shouldAddSafetySemicolonWhenInline &&
isNextTokenOnSameLineAsNode &&
!willSortedNextNodeEndWithSafeCharacter &&
!isNextTokenSafeCharacter
Expand Down
1 change: 1 addition & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface SortingNode<Node extends TSESTree.Node = TSESTree.Node> {
group?: string
isEslintDisabled: boolean
hasMultipleImportDeclarations?: boolean
shouldAddSafetySemicolonWhenInline?: boolean
}

export interface MemberSortingNode extends SortingNode<TSESTree.ImportClause> {
Expand Down
Loading