Skip to content

Rule proposal: Disallow literals where enums are expected #308

@mohsen1

Description

@mohsen1

Do not allow number literals to be used instead of enums. I could think of three places that this can happen:

  • Function arguments
  • Binary expressions
  • Assignment expressions
enum Foo {
    ONE,
    TWO
}

function getFoo(f: Foo) {

    if (f === Foo.ONE) { // Good

    }

    if (f === 1) { // Bad

    }

    let ff: Foo;

    ff = Foo.TWO // Good
    ff = 1 // Bad

}

getFoo(Foo.ONE) // Good
getFoo(1) // Bad

Rule name

I need help with naming it according to conventions

Options

I don't think this rule needs any options. I don't see why anyone wants to use number literals for enums.

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