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

Compact arguments with object literal #5249

Open
andrey-shostik opened this issue Oct 11, 2018 · 1 comment
Open

Compact arguments with object literal #5249

andrey-shostik opened this issue Oct 11, 2018 · 1 comment
Labels
area:function calls help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program

Comments

@andrey-shostik
Copy link

andrey-shostik commented Oct 11, 2018

Prettier 1.14.3
Playground link

Input:

export default handleAction({
    ['MOCK_ACTION']: state => ({ ...state, counter: state.counter + 1 })
}, initialState.mockReducer);

Output:

export default handleAction(
  {
    ["MOCK_ACTION"]: state => ({ ...state, counter: state.counter + 1 })
  },
  initialState.mockReducer
);

Expected behavior:
Input shouldn't be changed. I don't like output format, its takes more lines and looks worse for me.

@j-f1 j-f1 added type:bug Issues identifying ugly output, or a defect in the program lang:javascript Issues affecting JS help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! labels Oct 12, 2018
@nmussy
Copy link
Contributor

nmussy commented Jan 11, 2019

It seems this would be solved by the --pure option (#2068), as Prettier respected this hard line break:

export default handleAction({
                             ^

Without any line breaks, there is a cleaner output:

Input:

export default handleAction({['MOCK_ACTION']: state => ({ ...state, counter: state.counter + 1 })}, initialState.mockReducer);

Output:

export default handleAction(
  { ["MOCK_ACTION"]: state => ({ ...state, counter: state.counter + 1 }) },
  initialState.mockReducer
);

Which is consistent with other function calls with long arguments:

Input:

export default handleAction(justACoupleOfArgumentsButWithLongContents, andAnotherLongVariableName);

Output:

export default handleAction(
  justACoupleOfArgumentsButWithLongContents,
  andAnotherLongVariableName
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:function calls help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

4 participants