Skip to content

Rule Change: allow expression type annotation in func-style #19719

@remcohaszing

Description

@remcohaszing

What rule do you want to change?

func-style

What change do you want to make?

Generate fewer warnings

How do you think the change should be implemented?

A new option

Example code

type Fn = () => undefined

/* eslint func-style: ["error", "declaration"] */

const expression: Fn = function () {}

const arrow: Fn = () => {}


[playground](https://typescript-eslint.io/play/#code=C4TwDgpgBAYgdlAvFAFASiQPigVzgEwgDMBLOCfAKEoHoAqCAZwBszgoi8BjAWkdGYQAXFADaAIggAnKQHsp4gDRRxhLswCGUjcBKy44gLp0a1Lvv5QIADzBSmjPXBHwkHbrv2oMAbygBfMwt2LTkAdxcEZHQsKD9AoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA)

What does the rule currently do for this code?

It reports both expression and arrow should be declared as a function declaration.

What will the rule do after it's changed?

I suggest to add a new option allowTypeAnnotation. If the function style is set to declaration, and allowTypeAnnotation is true, then the rule will not report expression-style functions if the variable declarator has a type annotation.

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

I reported this a while back as typescript-eslint/typescript-eslint#8488. But I understand ESLint core rules now also accept some TypeScript specific options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions