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: Detect useless default in function parameters and object destructuring #6106

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
@RunDevelopment

Description

@RunDevelopment

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Default parameters anddefault values are only used if the parameter or property isundefined (either because its value isundefined or because it is missing). So if we know that a function parameter or property can never beundefined, then we also know that the default is never actually used. This can be used to detect useless defaults.

Fail Cases

// React props destructuringfunctionBar({ foo=""}:{foo:string}){/* ... */}// destructuring assignmentconst{ foo=""}={foo:"bar"}// default parameter[1,2,3].map((a=42)=>a+1)

Pass Cases

// React props destructuringfunctionBar({ foo}:{foo:string}){/* ... */}functionBar({ foo=""}:{foo?:string}){/* ... */}// destructuring assignmentconst{ foo}={foo:"bar"}// default parameter[1,2,3].map((a)=>a+1)[1,2,3,undefined].map((a=42)=>a+1)

Additional Info

This rule requires strict null checks to be enabled.

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