Add support for comma in function call and function declaration after the last argument (re-submitted)
See original GitHub issueThis 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:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
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.
Work to integrate Acorn is happening here: https://github.com/eslint/espree/issues/287