-
Notifications
You must be signed in to change notification settings - Fork 887
Rename no-let-undefined
to no-unnecessary-initializer
#2106
Rename no-let-undefined
to no-unnecessary-initializer
#2106
Conversation
* And handle 'var', destructuring, and parameter initializers
|
||
const e = undefined; | ||
|
||
function f(x: string | undefined = undefined) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not recommend making a parameter optional if it is followed by a required parameter:
function f(foo: string|undefined = undefined, bar: number) {} // no error, parameter foo cannot be optional
function f2(foo: string|undefined = undefined, bar: number = 1) {} // foo can be optional
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [1]
|
||
const e = undefined; | ||
|
||
function f(x: string | undefined = undefined, bar: number) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, on this function the = undefined
should lead to failure [0].
If parameter bar
is required, you need to pass a value for x
. So is makes no sense to set a default of undefined
, because the default value is only used when the passed value for that parameter is undefined
.
/* tslint:disable:object-literal-sort-keys */ | ||
public static metadata: Lint.IRuleMetadata = { | ||
ruleName: "no-unnecessary-initializer", | ||
description: "Forbids a 'var'/'let' statementor destructuring initializer to be initialized to 'undefined'.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statementor
-> statement or
@andy-hanson thanks! |
PR checklist
What changes did you make?
Handled more things in
no-let-undefined
, so changing the name too. See comments on #2100.