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

update spaceWithinParensRule to always allow empty parens #3513

Merged
merged 3 commits into from
Dec 2, 2017

Conversation

jbsingh
Copy link
Contributor

@jbsingh jbsingh commented Nov 24, 2017

PR checklist

Overview of change:

Updated spaceWithinParensRule to always allow empty parentheses (). Also removed use of a hard coded character code.

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

CHANGELOG.md entry:

[enhancement] space-within-parens updated to always allow empty parentheses ().

} else if (token.kind === ts.SyntaxKind.CloseParenToken) {
this.checkCloseParenToken(token);
if (sourceFile.text.charAt(token.end - 2) !== ts.tokenToString(ts.SyntaxKind.OpenParenToken)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ts.tokenToString(ts.SyntaxKind.OpenParenToken) just returns (. Consider comparing with the string directly.
Same for CloseParenToken above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, I updated to compare directly with the corresponding strings.

*/
if (!ts.isLineBreak(currentChar) && currentChar !== 40) {
if (!ts.isLineBreak(currentChar) && this.sourceFile.text.charAt(currentPos) !== ts.tokenToString(ts.SyntaxKind.OpenParenToken)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason to replace the char code. If you don't like the magic number, you can add a const enum (because they are inlined by the compiler) with the charcode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, I put back the previous code.

new Foo( );

// empty parens are always allowed
new Foo();
Copy link
Contributor

Choose a reason for hiding this comment

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

The current implementation adds an error for new Foo( ), because 1 space !== 2 spaces.
If that is intended, please add a test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. My understanding is that the existing test was checking for no spaces i.e. new Foo() and the corresponding error "Needs 2 whitespaces..." was appearing. Since the empty parens should no longer error I just originally removed that error expectation and added a test to make sure 2 spaces work as expected. There were existing tests covering the missing single and double space as well as extra spaces, so I didn't originally add more missing space checks. Based on the review feedback I have added a test for new Foo( ); that covers 1 missing space.

@ajafff ajafff merged commit 5e50a7a into palantir:master Dec 2, 2017
@ajafff
Copy link
Contributor

ajafff commented Dec 2, 2017

Thanks @jbsingh

@jbsingh jbsingh deleted the always-allow-empty-parens branch December 4, 2017 04:22
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this pull request Apr 9, 2018
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

2 participants