Content-Length: 297461 | pFad | https://github.com/typescript-eslint/typescript-eslint/issues/2988

3E Rule proposal: warn against passing a non-void returning callback in a position accepting a void returning callback · Issue #2988 · typescript-eslint/typescript-eslint · GitHub
Skip to content

Rule proposal: warn against passing a non-void returning callback in a position accepting a void returning callback #2988

@ArnaudBarre

Description

@ArnaudBarre

Repro

{
  "rules": {
    "@typescript-eslint/no-confusing-void-expression": [
      "warn",
      { ignoreArrowShorthand: true },
    ],
  }
}
// setState return void, this is ok and shorter
<Modal onClose={() => setState(undefined)} /> 
// We are returning a number to a void callback. This is probably a mistake
<Counter onChange={(value) => Math.abs(value)}   /> 

Expected Result

Warn in the second case.

I would like the rule to report on return type mismatch like no-misused-promises, while keeping the the possibility to use arrow function when callback returns nothing. Would an option for this be accepted? I can work on it next week if I have a green light

We could also change the default behaviour of ignoreArrowShorthand, but it would be a breaking change

Actual Result

Warn in both cases by default, non with { ignoreArrowShorthand: true }

Versions

package version
@typescript-eslint/eslint-plugin 4.14.1
@typescript-eslint/parser 4.14.1
TypeScript 4.0.5
ESLint 7.19.0
node 4.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/typescript-eslint/typescript-eslint/issues/2988

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy