-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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 and default values are only used if the parameter or property is undefined
(either because its value is undefined
or because it is missing). So if we know that a function parameter or property can never be undefined
, then we also know that the default is never actually used. This can be used to detect useless defaults.
Fail Cases
// React props destructuring
function Bar({ foo = "" }: { foo: string }) { /* ... */ }
// destructuring assignment
const { foo = "" } = { foo: "bar" }
// default parameter
[1, 2, 3].map((a = 42) => a + 1)
Pass Cases
// React props destructuring
function Bar({ foo }: { foo: string }) { /* ... */ }
function Bar({ foo = "" }: { foo?: string }) { /* ... */ }
// destructuring assignment
const { 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.
JoshuaKGoldberg, EvgenyOrekhov, jroru, timrobinson33, dartess and 2 more
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin