commitsTableStore.setCommitRows(data.commits.map(commit =>
new CommitRow(commit) // missing trailing comma reported here
));
with tslint.json configuration:
"trailing-comma": [true, {"multiline": "always"}]
Missing trailing comma reported.
No linting error reported.
It's caused by the "functions" checker – TSLint thinks that this is a multiline function call.
huh, you're right, that is a false positive. accepting bugfix PRs
Cross posting my comment from https://github.com/palantir/tslint/pull/2988#issuecomment-312840722:
IMO this is not a bug or false positive.
The above example is considered "multiline" for a reason. The docs are very clear on that:
An array is considered “multiline” if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To avoid this, you can simply rewrite it as follows:
commitsTableStore.setCommitRows(data.commits.map(commit =>
new CommitRow(commit)));
//or
commitsTableStore.setCommitRows(data.commits.map((commit =>
new CommitRow(commit)
))); // note the extra parens around the arrow function
If we want to implement an exception for such cases, this would need a proposal what exacltly should be handled different. And it should be implemented behind an option.
ah, I see your point @ajafff, and I now agree, this is not a bug or false positive. as per https://github.com/palantir/tslint/issues/2909#issuecomment-307898234, we don't have plans to to check the arity of the function being called in the trailing-comma implementation. your proposed workarounds are good 👍
Thanks for all the context. I have to say it's quite unintuitive at first but follows some internal logic. And I didn't know you can put trailing commas in function calls just like that :)
For reference, this is how Prettier handles the situation with --trailing-comma=es5 configuration: https://goo.gl/Juay94
commitsTableStore.setCommitRows(
data.commits.map(
commit => new CommitRow(commit) // missing trailing comma reported here
)
);
Most helpful comment
Thanks for all the context. I have to say it's quite unintuitive at first but follows some internal logic. And I didn't know you can put trailing commas in function calls just like that :)
For reference, this is how Prettier handles the situation with
--trailing-comma=es5configuration: https://goo.gl/Juay94