Skip to content

require and define calls are formatted differently #3829

@salemhilal

Description

@salemhilal

Prettier 1.10.2
Playground link

Input:

/*
 * It looks like "require" and "define" calls are formatted differently,
 * all else being equal. (fwiw, I think require's formatting here looks 
 * way better)
 */
require(
    [
        'jquery',
        'common/global.context',
        'common/log.event',
        'some_project/square',
        'some_project/rectangle',
        'some_project/triangle',
        'some_project/circle',
        'some_project/star',
    ],
    function($, Context, EventLogger, Square, Rectangle, Triangle, Circle, Star) {

        console.log('some code')
    }
);

define(
    [
        'jquery',
        'common/global.context',
        'common/log.event',
        'some_project/square',
        'some_project/rectangle',
        'some_project/triangle',
        'some_project/circle',
        'some_project/star',
    ],
    function($, Context, EventLogger, Square, Rectangle, Triangle, Circle, Star) {

        console.log('some code')
    }
);


/*
 * This only seems to happen when the array of imports is sufficiently long
 */

require(["ohkay", "another_imported_thing", "and also this one here"], function(ok) {
  console.log(ok);
})

define(["ohkay", "another_imported_thing", "and also this one here"], function(ok) {
  console.log(ok);
})

Output:

/*
 * It looks like "require" and "define" calls are formatted differently,
 * all else being equal. (fwiw, I think require's formatting here looks 
 * way better)
 */
require([
  "jquery",
  "common/global.context",
  "common/log.event",
  "some_project/square",
  "some_project/rectangle",
  "some_project/triangle",
  "some_project/circle",
  "some_project/star"
], function(
  $,
  Context,
  EventLogger,
  Square,
  Rectangle,
  Triangle,
  Circle,
  Star
) {
  console.log("some code");
});

define(
  [
    "jquery",
    "common/global.context",
    "common/log.event",
    "some_project/square",
    "some_project/rectangle",
    "some_project/triangle",
    "some_project/circle",
    "some_project/star"
  ],
  function($, Context, EventLogger, Square, Rectangle, Triangle, Circle, Star) {
    console.log("some code");
  }
);

/*
 * This only seems to happen when the array of imports is sufficiently long
 */

require(["ohkay", "another_imported_thing", "and also this one here"], function(
  ok
) {
  console.log(ok);
});

define(["ohkay", "another_imported_thing", "and also this one here"], function(
  ok
) {
  console.log(ok);
});

Expected behavior:

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.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions