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.

Wrapping algorithm for callback arrow functions adds a comma to the arguments list

See original GitHub issue

Version: 0.0.5 (npm@latest); also 0.0.4, and prettier-browser.

Example: (prettier-browser)

func('a very very very very long long long name that exceeds the width limit', () => {
  return true;
})

// becomes 

func('a very very very very long long long name that exceeds the width limit', (
  ,
) => 
  {
    return true;
  });

Where did the comma in the arguments list come from?

It doesn’t happen with shorter functions that don’t exceed the line length limit, nor with a function callback.

// input
func('a short name', () => {
  return true;
})

// output
func('a short name', () => {
  return true;
});
// input
func('a very very very very long long long name that exceeds the width limit', function() {
  return true;
})

// output
func(
  'a very very very very long long long name that exceeds the width limit',
  function() {
    return true;
  },
);

Side-note: The output for the incorrect function causes prettier to throw an error: prettier-browser. Is the comma actually illegal there, or should I file that as a separate bug?


This looks like a wonderful tool. I’m really excited to see where it leads.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jlongstercommented, Jan 11, 2017

I think we might allow the trailingComma option to have two types, one where it prints them everywhere and another that doesn’t print them in function args.

0reactions
erbridgecommented, Jan 15, 2017

If I understand #210 correctly, it resolves the zero argument case, but what about the trailing comma on argument lists?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arrow function expressions - JavaScript - MDN Web Docs
Arrow functions don't have their own bindings to this , arguments , or super , and should not be used as methods. ·...
Read more >
Arrow functions in JavaScript - GeeksforGeeks
The reason that we get undefined outputs instead of the proper info as output happens because the function() defined as the callback for ......
Read more >
Arrow functions, the basics - The Modern JavaScript Tutorial
If we have only one argument, then parentheses around parameters can be omitted, making that even shorter. For example: · If there are...
Read more >
Google JavaScript Style Guide
Import statements must not be line wrapped and are therefore an exception to the ... When declaring an anonymous function in the list...
Read more >
A Practical Guide to ES6 Arrow Functions - Bits and Pieces
In Arrow functions, the parameter list and the function body is separated by a => symbol. That is, the function keyword is effectively ......
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