question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for comma in function call and function declaration after the last argument (re-submitted)

See original GitHub issue

This is a re-submission of #208


I’d like to give an example with AngularJS-centerd code, where function arguments have different meaning then the rest of JS world.

To ensure the diff to be as meaningful as possible I’d like to be able to declare dependency injection arguments line-by-line and make sure adding another won’t modify the line history on any other line than the one I’m adding/modifying:

angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3
) {
  // service logic
})

(I’m not using array DI syntax for the sake of brevity)

If I want to add fourth dependency as the last argument (I’d probably do exactly that if I want my dependencies to be organised alphabetically or by some custom logic - whatever) I get this:

angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3, // changed line: added comma
  dependencyService4 // added line
) {
  // service logic
})

With last comma the example looks almost exactly the same:

angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3, // please notice the last comma
) {
  // service logic
})
angular.module('myModule', []).service('myService', function (
  dependencyService1,
  dependencyService2,
  dependencyService3, // please notice: no change in this line
  dependencyService4, // added line: the change I've made is a one-liner, by diff is more meaningful!
) {
  // service logic
})

What I’d like to do is to be able to use last comma syntax and still use eslint, but it’s not possible since code using commas after last function argument are not parsed by espree yet.

Line 5: Unexpected token 

I know this syntax is not yet production ready, but for transpilers (namely: babel) stripping this one comma is not a problem

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
nzakascommented, Jul 29, 2016

I started work on this and trailing commas turned out to be pretty easy. This is the Acorn fork I’m using: https://github.com/nzakas/acorn/tree/issue441

Just need to wait to hear back on Acorn’s position.

1reaction
nzakascommented, Sep 14, 2016

Work to integrate Acorn is happening here: https://github.com/eslint/espree/issues/287

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add support for comma in function call and function declaration after ...
I'd like to give an example with AngularJS-centerd code, where function arguments have different meaning then the rest of JS world.
Read more >
Should I add a trailing comma after the last argument in a ...
There's no technical reason to avoid trailing commas in function calls, but some people might find them distracting. Some may wonder: Hmmm, ...
Read more >
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >
Function arguments - Manual - PHP
Information may be passed to functions via the argument list, which is a comma-delimited list of expressions. The arguments are evaluated from left...
Read more >
Passing comma-delimited values into SAS macros and macro ...
Passing comma-delimited value as an argument to a SAS macro function. Let's say you want to extract the first word from the following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found