Skip to content
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

upgrade no-sync-fn-in-async-fn #1198

Open
sigmaSd opened this issue Oct 2, 2023 · 4 comments · May be fixed by #1199
Open

upgrade no-sync-fn-in-async-fn #1198

sigmaSd opened this issue Oct 2, 2023 · 4 comments · May be fixed by #1199
Labels
bug Something isn't working

Comments

@sigmaSd
Copy link
Contributor

sigmaSd commented Oct 2, 2023

currently no-sync-fn-in-async-fn can't catch this:

async function a() {
   b() // b is blocking, but its hidden from us, we only warn if we see Deno. Sync syntax
}

function b() {
 Deno.xxxxxSync()
}

I thought maybe its possible to catch even this: for example we can consider each function that have inside it a deno Sync api a blocking function, and save it on a list and now each time we see it we also consider the parent blocking and so on, and now if we see one of these in an async context we emit a warning.

Do you think this is a reasonable idea ?

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Oct 2, 2023

I wrote the code for this, check it out here https://github.com/denoland/deno_lint/compare/main...sigmaSd:lintup?expand=1

It seems I hit a fatal flow unfortantnly

this gets linted correctly

     function foo() {
        Deno.readTextFileSync("");
      }"
      async function foo2() {
        foo()
      }

but this doesn't

      async function foo2() {
        foo()
      }
     function foo() {
        Deno.readTextFileSync("");
      }"

because the parsing is done from top to bottom, when we reach foo inside foo2 we don't know its a blocking call yet.

Any ideas ? can I somehow parse twice ?

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Oct 2, 2023

Ofc I can just traverse the ast twice.

@sigmaSd sigmaSd linked a pull request Oct 2, 2023 that will close this issue
@bartlomieju
Copy link
Member

@sigmaSd yes, you can traverse the AST twice in this specific rule

@bartlomieju bartlomieju added the bug Something isn't working label May 10, 2024
@sigmaSd
Copy link
Contributor Author

sigmaSd commented May 10, 2024

Thanks @bartlomieju I already do that in this pr #1199 (comment)

It seems to work but I'm not really confortable with the code base, would be great if you review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants