Skip to content

Commit

Permalink
Merge pull request #63 from mskelton/eslint-8
Browse files Browse the repository at this point in the history
ESLint 8
  • Loading branch information
mskelton committed Mar 22, 2024
2 parents b835ea6 + 2d360d9 commit c9e1fec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"index.cjs"
],
"peerDependencies": {
"eslint": ">=6"
"eslint": ">=8"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "^5.54.1",
Expand Down
14 changes: 9 additions & 5 deletions src/rules/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -145,23 +144,28 @@ 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]

// 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.
Expand Down
5 changes: 2 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export function report(
nodes: Node[],
sorted: Node[]
) {
const source = context.getSourceCode()
const firstUnsortedNode = isUnsorted(nodes, sorted)

if (firstUnsortedNode) {
Expand All @@ -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)
)
}
},
Expand Down

0 comments on commit c9e1fec

Please sign in to comment.