-
Notifications
You must be signed in to change notification settings - Fork 889
Trailing comma rule now encompasses function decls, exprs and types #1486
Conversation
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. |
The following currently do not work:
I am working on another commit to address those cases. |
cool; what's the "methods in classes" case look like? |
Gave it a brief glance over, looking good so far 👍 |
@adidahiya methods in a class or interface declaration have |
There is are a couple more issues that I have to address:
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) { | ||
/* |
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.
need to be removed
6bc4acc
to
603db30
Compare
This is now ready for review. |
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! |
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]; |
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
};
} |
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. |
Ah yes, you're right. Just the first one needs to get fixed, second one is fine 👍 |
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
as the base behavior. It just so happens that in this case,
I think after this change,
might be clearer. Thoughts? |
…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)
I updated the base branch to master. Let me know if you require anything else :) |
Looks good, thanks @markwongsk! |
Is there workaround to skip that check? I like trailing comma in multiline "objects", but function calls it is awful. IMHO |
Fixes #1409