-
Notifications
You must be signed in to change notification settings - Fork 887
Conversation
public static metadata: Lint.IRuleMetadata = { | ||
ruleName: "no-let-undefined", | ||
description: "Forbids a 'let' statement to be initialized to 'undefined'.", | ||
optionsDescription: "Not configurable.", |
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.
hasFix: true
@@ -0,0 +1,9 @@ | |||
let 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.
add arg initializer test?
add const x = undefined;
which shouldn't fail lint
ef701d8
to
c384109
Compare
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.
lgtm, thanks!
IMO this rule is a bit too specialized. |
Yeah, this could work for It can't be extended to parameters, though: For destructuring you mean to warn on this? declare function f(): { x?: number };
const { x = undefined } = f(); // Could be `const { x } = f()` |
Didn't know there is this difference for parameters. So the checking would be limited to optional parameters only ... Yes, that's what I had in mind for destructuring. All of the following examples should result in a failure: let {foo = undefined} = someObject; // doesn't need initializer, always defaults to undefined
let [foo = undefined] = someArray; // same as above
let {foo = undefined} = {}; // is valid only if there is an initializer, but this is either by mistake or really bad practice to declare variables
let [foo = undefined] = []; // same as above |
PR checklist
What changes did you make?
Added the
no-let-undefined
rule, which forbidslet x = undefined;
, preferringlet x;
.