Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rule proposal: Disallow literals where enums are expected #308

Open
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
@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
enumFoo{ONE,TWO}functiongetFoo(f:Foo){if(f===Foo.ONE){// Good}if(f===1){// Bad}letff:Foo;ff=Foo.TWO// Goodff=1// Bad}getFoo(Foo.ONE)// GoodgetFoo(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


      [8]ページ先頭

      ©2009-2025 Movatter.jp