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

See original GitHub issue

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 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Jul 27, 2016

@ljharb please open new issues, they’re much easier for us to track.

1reaction
ljharbcommented, Jul 27, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I add a trailing comma after the last argument in a ...
So yes, there are many situations where you can expect your list of functions arguments to grow and where it should be acceptable...
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 >
10. Trailing commas in function parameter lists and calls
The ECMAScript 2017 feature “Trailing commas in function parameter lists and calls” was proposed by Jeff Morrison. 10.1 Overview #. Trailing commas in...
Read more >
PHP 7.3: Trailing Commas in Function Calls - Laravel News
In PHP 7.3, trailing commas in function calls will be valid syntax. That is to say, you can use trailing commas when calling...
Read more >
Best practices for using trailing commas in JavaScript
Using trailing commas in parameter lists and function calls ... Even experienced developers do not always remember to add a comma to the...
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