Skip to content

[array-callback-return] False positive when in a map that uses a switch case without default because all possibilities are handled but ESLint isn't aware of that #2841

Closed as not planned
@MaximeCheramy

Description

@MaximeCheramy
  • 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

playground link

The rule array-callback-return is enabled with default settings. There are no TypeScript equivalent (that's what would fix the issue).

    const l = [{ type: 'a' }, { type: 'b' }] as {type: 'a' | 'b'}[]
    l.map(el => {
      switch (el.type) {
        case 'a': return 'type a'
        case 'b': return 'type b'
      }
    })
{
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "lib": [
      "dom",
      "es2018",
      "es2018.regexp"
    ],
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "dist",
    "sourceMap": true,
    "target": "es5",
    "types": [
      "jest",
      "node"
    ]
  },
  "include": [
    "src/**/*",
    "tests/**/*"
  ]
}

Versions

package version
@typescript-eslint/eslint-plugin 4.9.0
@typescript-eslint/parser 4.9.0
TypeScript 4.1.2
ESLint 7.14.0
node 12.19.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new base rule extensionNew base rule extension required to handle a TS specific caselocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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