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

[no-misused-promises] Suggestion: check more AST positions #4523

Closed
3 tasks done
uhyo opened this issue Feb 7, 2022 · 3 comments · Fixed by #4541
Closed
3 tasks done

[no-misused-promises] Suggestion: check more AST positions #4523

uhyo opened this issue Feb 7, 2022 · 3 comments · Fixed by #4541
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look

Comments

@uhyo
Copy link
Contributor

uhyo commented Feb 7, 2022

Hello, I think the no-misused-promises rule could be improved to perform the checks in a few more positions, so here is proposal:

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/no-misused-promises": "error"
  }
}
declare function doSomething(value: unknown): Promise<void>;

// Function argument: current version of the rule emits error
[1, 2, 3].forEach(async value => {
  await doSomething(value);
});

// variable: current version of the rule does NOT emit error
const func: () => void = async () => {
  await doSomething(123);
};

type Obj = {
  func: () => void
};

// Contextually typed property: current version of the rule does NOT emit error
const obj: Obj = {
  func: async () => {
    await doSomething(123);
  }
};

const Component = (obj: Obj) => null;

// JSX prop: current version of the rule does NOT emit error
<Component func={async () => {
  await doSomething(123);
}} />;

Expected Result

The rule reports error for all cases above.

Actual Result

Error is reported only for the first case.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 5.10.2
@typescript-eslint/parser 5.10.2
TypeScript 4.5.5
ESLint 8.8.0
node 16.13.1
@uhyo uhyo added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 7, 2022
@bradzacher
Copy link
Member

Duplicate of #4015

@bradzacher bradzacher marked this as a duplicate of #4015 Feb 7, 2022
@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for maintainers to take a look labels Feb 7, 2022
@uhyo
Copy link
Contributor Author

uhyo commented Feb 11, 2022

@bradzacher Hmm, I don't really think that this is a duplicate. The linked issue only discusses function arguments while this issue is about positions that are not function arguments. Fixes would be different too.

Let me try implementing this anyway.

@JoshuaKGoldberg
Copy link
Member

Indeed, I think we can consider this issue as separate from #4015.

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for maintainers to take a look accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request and removed duplicate This issue or pull request already exists labels Feb 23, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement New feature or request package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look
Projects
None yet
3 participants