Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent formatting for object properties with ternaries #12077

Open
bradzacher opened this issue Jan 12, 2022 · 3 comments · May be fixed by #12087
Open

Inconsistent formatting for object properties with ternaries #12077

bradzacher opened this issue Jan 12, 2022 · 3 comments · May be fixed by #12087
Labels
lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program

Comments

@bradzacher
Copy link

Prettier 2.5.1
Playground link

--parser babel
--print-width 25

Input:

const x = {
  prop1: foo == null ? bar : baz,
  prop1: !fooooooooo ? bar : baz,
};

Output:

const x = {
  prop1:
    foo == null
      ? bar
      : baz,
  prop1: !fooooooooo
    ? bar
    : baz,
};

Expected behavior:

Both should look the same - either:

  • the condition is on the same line as the property key, or
  • the condition is on a different lint to the property key
@fisker
Copy link
Member

fisker commented Jan 13, 2022

Should be caused by

return isBinaryish(test) && !shouldInlineLogicalExpression(test);

@sosukesuzuki sosukesuzuki added lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program labels Jan 13, 2022
@islandryu
Copy link

islandryu commented Jan 15, 2022

Should it be the same line in variable declarations?
playground link

actual behavior

input:

const a = foo == null ? bar: baz;
const b = !foooooooo ? bar : baz;

output:

const a =
  foo == null
    ? bar
    : baz;
const b = !foooooooo
  ? bar
  : baz;

@islandryu islandryu linked a pull request Jan 15, 2022 that will close this issue
4 tasks
@thorn0
Copy link
Member

thorn0 commented Feb 22, 2022

Looks like special casing for binaries was added in #2228 to prevent indentation like this:

const x = {
  prop1: foo == null &&
    bar == null
    ? bar
    : baz
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants