Add support for comma in function call and function declaration after the last argument
See original GitHub issueI’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 8 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
@ljharb please open new issues, they’re much easier for us to track.
This proposal advanced today to stage 4 at the July TC39 meeting (https://github.com/tc39/proposals/commit/6826a1927393fb3771de1425167a8b694291c8f8) - can this and https://github.com/eslint/eslint/issues/4352#issuecomment-232404631 be reopened?