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

Add new object/array-destructuring options to typedef rule #2146

Merged

Conversation

shlomiassaf
Copy link
Contributor

PR checklist

What changes did you make?

This PR adds support for opting in to object-destructuring and array-destructuring in typedef rule.

Current variable-declaration option, if on, will fail if:

const [ paramA, paramB ] = [15, 'test'];

With this PR it wont, variable-declaration only fails on simple non-binding declarations.

Tests samples:

const { paramA, paramB } = { paramA: "test", paramB: 15 };
                        ~    [expected object-destructuring: '{ paramA, paramB }' to have a typedef]

const { paramA, paramB }: { paramA: string, paramB: number } = { paramA: "test", paramB: 15 };

const [ paramA, paramB ] = [15, 'test'];
                        ~    [expected array-destructuring: '[ paramA, paramB ]' to have a typedef]

const [ paramA3, paramB3 ]: { number: string, paramB1: string } = [15, 'test'];

Is there anything you'd like reviewers to focus on?

variable-declaration now has it's own test directory.

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @shlomiassaf! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@@ -77,3 +77,7 @@ try {
for (let i of [1, 2, 3]) {

}

const [ paramA3, paramB3 ]: { number: string, paramB1: string } = [15, 'test'];
Copy link
Contributor

Choose a reason for hiding this comment

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

add destructuring cases without typedefs. Also this typedef doesn't match

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nchen63 good catch, copy/paste :)
updated.

@shlomiassaf shlomiassaf force-pushed the rule/typedef/object-array-destructing branch from 59e8fb4 to 2334e20 Compare January 28, 2017 01:30
@nchen63 nchen63 merged commit 26700c0 into palantir:master Jan 28, 2017
@nchen63
Copy link
Contributor

nchen63 commented Jan 28, 2017

@shlomiassaf thanks!

@shlomiassaf
Copy link
Contributor Author

@nchen63 I think now it is required in typedef-whitespace
not sure I will have the time for this...

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