Skip to content

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

Closed

Description

@hawkrives

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.

Activity

  1. changed the title [-]Wrapping algorithm for callback arrow functions adds a comma[/-] [+]Wrapping algorithm for callback arrow functions adds a comma to the arguments list[/+] on Jan 11, 2017
  2. jlongster commented on Jan 11, 2017

    @jlongster
    Member

    Are you using the trailing comma option? It is still be outputting a comma even though there are no args. If you add parameters is looks better:

    https://vjeux.github.io/prettier-browser/#%7B%22content%22%3A%22%5Cnfunc(%27a%20very%20very%20very%20very%20long%20long%20long%20name%20that%20exceeds%20the%20width%20limit%27%2C%20(a%2C%20b%5Cn%20%20%2C%5Cn)%20%3D%3E%20%5Cn%20%20%7B%5Cn%20%20%20%20return%20true%3B%5Cn%20%20%7D)%3B%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22useFlowParser%22%3Afalse%2C%22singleQuote%22%3Atrue%2C%22trailingComma%22%3Atrue%2C%22bracketSpacing%22%3Atrue%7D%7D

    If you enable the trailing commas option, we output commas for function arg lists too. It is not legal right now, but there is a stage 4 proposal for it, so it will be legal soon: https://github.com/tc39/proposal-trailing-function-commas

    There is a babel extension to strip it out. Are you using babel already? If so you should enable that extension.

    The point is that it's going to be legal soon, and if people want trailing commas they would like them there as well, and we assume your going to use the babel extension for now.

    We should not output the comma though if there are no args. That is a bug.

  3. hawkrives commented on Jan 11, 2017

    @hawkrives
    ContributorAuthor

    Yeah, that's the bug I'm facing – it's adding the comma when an arrow callback function has no arguments. I'm eagerly awaiting the day that I can use trailing function commas! I hadn't realized it was that far along in the process yet. Thanks again!

  4. jlongster commented on Jan 11, 2017

    @jlongster
    Member

    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.

  5. erbridge commented on Jan 13, 2017

    @erbridge

    I think, until trailing function commas are supported natively, it's wrong to assume that people are running their code through babel. I would like trailing commas everywhere they are supported, but I don't run my node code through babel, so I have to turn the option off, which strips trailing commas from objects and arrays.

  6. added 3 commits that reference this issue on Jan 15, 2017
    2820d68
    4107f4e
    1cfdd81
  7. added a commit that references this issue on Jan 15, 2017
    b9d2d1a
  8. erbridge commented on Jan 15, 2017

    @erbridge

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

  9. added
    locked-due-to-inactivity
    on Jul 8, 2018
  10. locked as resolved and limited conversation to collaborators on Jul 8, 2018
  11. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivity

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions