Prettier: Comment inside multiline ternary moves after `?`

Created on 9 Jun 2017  路  3Comments  路  Source: prettier/prettier

Prettier 1.15.2
Playground link

--parser babylon

Input:

const resolver = options.resolver
  /* $FlowFixMe */
  ? require(options.resolver)
  : defaultResolver;

Output:

const resolver = options.resolver
  ? /* $FlowFixMe */
    require(options.resolver)
  : defaultResolver;

Expected behavior:
For output to remain unchanged

Ref facebook/jest#3780

comments javascript bug

Most helpful comment

@lydell I think no-inline-comments is not a styling rule, and it does not come up with eslint-config-prettier.

It can catch something unrelated to styling.
or at least Prettier is not supposed to touch it, unless I'm mistaken.

const obj = {
  foo: 123 // inline comment here
};

All 3 comments

This is still an issue.

Before running Prettier:

this.chromeInstances = CONSTANTS.paralleliseChrome
  // I am running in paralel, add a chromeLauncher.launch() command for each required
  // instance of Chrome to run in paralell
  ? await Promise.all([
      chromeLauncher.launch(chromeLauncherOptions),
      chromeLauncher.launch(chromeLauncherOptions),
      chromeLauncher.launch(chromeLauncherOptions)
    ])
  // Every test run will be in the same instance of Chrome
  : await chromeLauncher.launch(chromeLauncherOptions);

After running Prettier:

this.chromeInstances = CONSTANTS.paralleliseChrome
  ? // I am running in paralel, add a chromeLauncher.launch() command for each required
    // instance of Chrome to run in paralell
    await Promise.all([
      chromeLauncher.launch(chromeLauncherOptions),
      chromeLauncher.launch(chromeLauncherOptions),
      chromeLauncher.launch(chromeLauncherOptions)
    ])
  : // Every test run will be in the same instance of Chrome
    await chromeLauncher.launch(chromeLauncherOptions);

Keeps failing on my ESLint rule no-inline-comments.
Had to change to if else:

if (CONSTANTS.paralleliseChrome) {
  // I am running in parallel, add a chromeLauncher.launch() command for each required
  // instance of Chrome to run in parallel
  this.chromeInstances = await Promise.all([
    chromeLauncher.launch(chromeLauncherOptions),
    chromeLauncher.launch(chromeLauncherOptions),
    chromeLauncher.launch(chromeLauncherOptions)
  ])
} else {
  // Every test run will be in the same instance of Chrome
  this.chromeInstances = await chromeLauncher.launch(chromeLauncherOptions);
}

Please give this issue some attention.

@alexilyaev We recommend turning off all ESLint rules that conflict with Prettier (or are redundant when using Prettier). https://prettier.io/docs/en/next/integrating-with-linters.html#eslint

(This is still a bug, though.)

@lydell I think no-inline-comments is not a styling rule, and it does not come up with eslint-config-prettier.

It can catch something unrelated to styling.
or at least Prettier is not supposed to touch it, unless I'm mistaken.

const obj = {
  foo: 123 // inline comment here
};
Was this page helpful?
0 / 5 - 0 ratings

Related issues

fingermark picture fingermark  路  3Comments

jitendravyas picture jitendravyas  路  3Comments

grgur picture grgur  路  3Comments

thezanke picture thezanke  路  3Comments

jasonkuhrt picture jasonkuhrt  路  3Comments