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

feat: add no-sync-fn-in-async-fn rule #1178

Merged
merged 17 commits into from
Jul 21, 2023

Conversation

sigmaSd
Copy link
Contributor

@sigmaSd sigmaSd commented Jul 16, 2023

fix #1177

@CLAassistant
Copy link

CLAassistant commented Jul 16, 2023

CLA assistant check
All committers have signed the CLA.

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Jul 16, 2023

image

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Jul 16, 2023

I add a suggestion for the async variant

image

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Jul 16, 2023

seems like there is a lot of code like this https://github.com/search?q=%2Fasync.*%5Cn.*Deno.*Sync%2F+language%3ATypeScript&type=code

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Jul 17, 2023

couple of notes

src/rules/no_sync_fn_in_async_fn.rs Outdated Show resolved Hide resolved
src/rules/no_sync_fn_in_async_fn.rs Outdated Show resolved Hide resolved
docs/rules/no_sync_fn_in_async_fn.md Outdated Show resolved Hide resolved
Comment on lines 23 to 37
### Valid:

```javascript
function foo() {
Deno.readTextFileSync("");
}

const fooFn = function foo() {
Deno.readTextFileSync("");
};

const fooFn = () => {
Deno.readTextFileSync("");
};
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be even better to also show valid examples with async functions containing async version of built-in functions, because we prefer async functions in general. Something like:

async function foo() {
  await Deno.readTextFile("");
}

Copy link
Member

@magurotuna magurotuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks so much!

@magurotuna magurotuna merged commit 71edb29 into denoland:main Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

warn about sync usage inside async function
3 participants