Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Rename no-let-undefined to no-unnecessary-initializer #2106

Merged
merged 4 commits into from Jan 25, 2017

Conversation

andy-hanson
Copy link
Contributor

  • And handle 'var', destructuring, and parameter initializers

PR checklist

  • Addresses an existing issue: #0000
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update

What changes did you make?

Handled more things in no-let-undefined, so changing the name too. See comments on #2100.

* And handle 'var', destructuring, and parameter initializers

const e = undefined;

function f(x: string | undefined = undefined) {}
Copy link
Contributor

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) {}
Copy link
Contributor

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.

@nchen63 nchen63 mentioned this pull request Jan 23, 2017
3 tasks
/* 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'.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

statementor -> statement or

@nchen63 nchen63 merged commit f53ec35 into palantir:master Jan 25, 2017
@nchen63
Copy link
Contributor

nchen63 commented Jan 25, 2017

@andy-hanson thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants