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

Trailing comma rule now encompasses function decls, exprs and types #1486

Merged
merged 3 commits into from
Sep 12, 2016

Conversation

markwongsk
Copy link
Contributor

Fixes #1409

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @markwongsk! 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.

@markwongsk
Copy link
Contributor Author

markwongsk commented Aug 16, 2016

The following currently do not work:

  • Typed parameters in class declarations, interface declarations, function declarations
  • Methods in classes

I am working on another commit to address those cases.

@adidahiya
Copy link
Contributor

cool; what's the "methods in classes" case look like?

@jkillian
Copy link
Contributor

Gave it a brief glance over, looking good so far 👍

@markwongsk
Copy link
Contributor Author

markwongsk commented Aug 17, 2016

@adidahiya methods in a class or interface declaration have node.kind of MethodDeclaration and SignatureDeclaration respectively, which aren't covered by the walker yet.

@markwongsk
Copy link
Contributor Author

markwongsk commented Aug 17, 2016

There is are a couple more issues that I have to address:

  • ObjectType literals do not currently work
  • Enums do not work

I also have a couple of test cases left. I've combed through the grammar but have no confidence on how thorough I've been. Please point out any remaining cases that you think we should support.

if (children[i].kind === ts.SyntaxKind.OpenBraceToken &&
children[i + 1].kind === ts.SyntaxKind.SyntaxList &&
children[i + 2].kind === ts.SyntaxKind.CloseBraceToken) {
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to be removed

@markwongsk
Copy link
Contributor Author

This is now ready for review.

@jkillian jkillian changed the base branch from next to master September 1, 2016 00:55
@jkillian jkillian changed the base branch from master to next September 1, 2016 00:55
@jkillian
Copy link
Contributor

jkillian commented Sep 1, 2016

I'm gonna test this out on our codebase, but I don't anticipate you having to change much. Do you mind actually making this PR against master? Next release is going to be TSLint 4.0 which will only support >= TS 2.

And sorry for the slow turnarounds!

@jkillian
Copy link
Contributor

jkillian commented Sep 1, 2016

I think this might be a bug:

const colon = node.getChildren().filter((child) =>
    child.kind === ts.SyntaxKind.ColonToken //warning for missing trailing comma here
)[0];

@jkillian
Copy link
Contributor

jkillian commented Sep 1, 2016

Requests a comma here as well - thoughts?

export interface TestResult {
    directory: string;
    results: {
        [fileName: string]: {
            errorsFromLinter: LintError[];
            errorsFromMarkup: LintError[];
            fixesFromLinter: string;
            fixesFromMarkup: string;
            markupFromLinter: string;
            markupFromMarkup: string;
        } // missing comma
    };
}

@markwongsk
Copy link
Contributor Author

For the first one, it's a bug. For the second one, this PR makes it such that a comma is indeed necessary there (it compiles with the comma) -- similar to how if it was an object, you would need a comma there.

@jkillian
Copy link
Contributor

Ah yes, you're right. Just the first one needs to get fixed, second one is fine 👍

@markwongsk
Copy link
Contributor Author

markwongsk commented Sep 12, 2016

So I took a further look into the first example, and I think it is expected after this change. This is because the lambda happens to be an argument to a function, and multilined arguments to a function need to have a trailing comma. Consider

foo(
   arg1,
);

as the base behavior. It just so happens that in this case, arg1 is a lambda. Thus,

foo(a =>
    doSomethingWithA(a),
);

I think after this change,

foo(
    a => doSomethingWithA(a),
);

might be clearer. Thoughts?

Mark Wong Siang Kai added 2 commits September 12, 2016 03:09
…set accessor, function calls

-- Untested:
   1. ctor calls (should be handled by callSignature)
   2. set accessor calls (should be handled by callSignature)
   3. tuple/function/ctor/parameterized return types (should be
      handled syntax walker recursion and should hit one of
      vist...[TupleType, FunctionType, ConstructorType, TypeReference, TypeLiteral])
   4. Enums (I think this will fail)

-- Known not working:
   1. comma separated object literal types (object literals can
      be semicolon delineated, so need a good way to only cry
      about trailing commas if they aren't semicolon delineated)

-- Known won't fix:
   1. iface/class extension list (tsc does not support trailing
      commas)
@markwongsk
Copy link
Contributor Author

I updated the base branch to master. Let me know if you require anything else :)

@jkillian jkillian merged commit 4df4a2e into palantir:master Sep 12, 2016
@jkillian
Copy link
Contributor

Looks good, thanks @markwongsk!

@timocov
Copy link
Contributor

timocov commented Feb 18, 2017

Is there workaround to skip that check? I like trailing comma in multiline "objects", but function calls it is awful. IMHO

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

Successfully merging this pull request may close these issues.

5 participants