diff --git a/bun.lockb b/bun.lockb index 4b8554c..2f59a50 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 62f1f06..e01eaf2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "index.cjs" ], "peerDependencies": { - "eslint": ">=6" + "eslint": ">=8" }, "dependencies": { "@typescript-eslint/experimental-utils": "^5.54.1", diff --git a/src/rules/imports.ts b/src/rules/imports.ts index 86f5f68..f4d1117 100644 --- a/src/rules/imports.ts +++ b/src/rules/imports.ts @@ -92,7 +92,6 @@ export default { const groups = options?.groups ?? [] const separator = options?.separator ?? "" const sorter = getSorter(options) - const source = context.getSourceCode() return { Program(program) { @@ -145,15 +144,19 @@ export default { *fix(fixer) { for (const [node, complement] of enumerate(nodes, sorted)) { yield fixer.replaceTextRange( - getNodeRange(source, node, !isFirst(node)), - getNodeText(source, complement, !isFirst(complement)) + getNodeRange(context.sourceCode, node, !isFirst(node)), + getNodeText( + context.sourceCode, + complement, + !isFirst(complement) + ) ) } }, }) } - const text = source.getText() + const text = context.sourceCode.getText() for (let i = 1; i < nodes.length; i++) { const node = nodes[i] const prevNode = nodes[i - 1] @@ -161,7 +164,8 @@ export default { // If the node has preceding comments, we want to use the first // comment as the starting position for both determining what the // current separator is as well as the location for the report. - const nodeOrComment = source.getCommentsBefore(node)[0] ?? node + const nodeOrComment = + context.sourceCode.getCommentsBefore(node)[0] ?? node // Find the range between nodes (including comments) so we can pull // the text and apply fixes to newlines between imports. diff --git a/src/utils.ts b/src/utils.ts index 5f97357..23c20bc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -138,7 +138,6 @@ export function report( nodes: Node[], sorted: Node[] ) { - const source = context.getSourceCode() const firstUnsortedNode = isUnsorted(nodes, sorted) if (firstUnsortedNode) { @@ -148,8 +147,8 @@ export function report( *fix(fixer) { for (const [node, complement] of enumerate(nodes, sorted)) { yield fixer.replaceTextRange( - getNodeRange(source, node), - getNodeText(source, complement) + getNodeRange(context.sourceCode, node), + getNodeText(context.sourceCode, complement) ) } },