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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy