Skip to content

Preserve pre-comment newlines in long chained method calls #1957

@mafredri

Description

@mafredri

I believe this falls under the feature request category. Sometimes I use newlines to break long chained method calls into logical groups for (IMO) added clarity. I would like for prettier to preserve these newlines.

EDIT: I apologize if this has been discussed or reported before, I tried to search the issues but there are quite a few to go through.

Input:

angular.module('AngularAppModule')
  // Constants.
  .constant('API_URL', 'http://localhost:8080/api')
  
  // App configuration.
  .config(appConfig)
  .run(appRun);

Output:

angular
  .module('AngularAppModule')
  // Constants.
  .constant('API_URL', 'http://localhost:8080/api')
  // App configuration.
  .config(appConfig)
  .run(appRun);

Expected:

angular
  .module('AngularAppModule')
  // Constants.
  .constant('API_URL', 'http://localhost:8080/api')

  // App configuration.
  .config(appConfig)
  .run(appRun);

As far as I see it, there are two ways to go about this:

  1. Only allow a newline before a comment
  2. Always allow one newline between chained method calls

Arguably, this is not a make-it-or-break-it feature, but one I would like to see implemented.

Reproduction link

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions