Skip to content

Commit

Permalink
fix: ReferenceTracker usage (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Mar 8, 2023
1 parent 5c4a7c6 commit 7b0d70b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-books-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-svelte": patch
---

fix: `ReferenceTracker` usage
8 changes: 6 additions & 2 deletions src/rules/infinite-reactive-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { traverseNodes } from "svelte-eslint-parser"
function extractTickReferences(
context: RuleContext,
): { node: TSESTree.CallExpression; name: string }[] {
const referenceTracker = new ReferenceTracker(context.getScope())
const referenceTracker = new ReferenceTracker(
context.getSourceCode().scopeManager.globalScope!,
)
const a = referenceTracker.iterateEsmReferences({
svelte: {
[ReferenceTracker.ESM]: true,
Expand All @@ -35,7 +37,9 @@ function extractTickReferences(
function extractTaskReferences(
context: RuleContext,
): { node: TSESTree.CallExpression; name: string }[] {
const referenceTracker = new ReferenceTracker(context.getScope())
const referenceTracker = new ReferenceTracker(
context.getSourceCode().scopeManager.globalScope!,
)
const a = referenceTracker.iterateGlobalReferences({
setTimeout: { [ReferenceTracker.CALL]: true },
setInterval: { [ReferenceTracker.CALL]: true },
Expand Down
4 changes: 3 additions & 1 deletion src/rules/reference-helpers/svelte-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export function* extractStoreReferences(
context: RuleContext,
storeNames: StoreName[] = ["writable", "readable", "derived"],
): Generator<{ node: TSESTree.CallExpression; name: string }, void> {
const referenceTracker = new ReferenceTracker(context.getScope())
const referenceTracker = new ReferenceTracker(
context.getSourceCode().scopeManager.globalScope!,
)
for (const { node, path } of referenceTracker.iterateEsmReferences({
"svelte/store": {
[ReferenceTracker.ESM]: true,
Expand Down
4 changes: 3 additions & 1 deletion src/rules/require-event-dispatcher-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default createRule("require-event-dispatcher-types", {
if (!isTs) {
return
}
const referenceTracker = new ReferenceTracker(context.getScope())
const referenceTracker = new ReferenceTracker(
context.getSourceCode().scopeManager.globalScope!,
)
for (const { node: n } of referenceTracker.iterateEsmReferences({
svelte: {
[ReferenceTracker.ESM]: true,
Expand Down

0 comments on commit 7b0d70b

Please sign in to comment.