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

Keep existing line breaks #4131

Closed
farzadmf opened this issue Mar 11, 2018 · 9 comments
Closed

Keep existing line breaks #4131

farzadmf opened this issue Mar 11, 2018 · 9 comments

Comments

@farzadmf
Copy link

Hi,

I'm using the VSCode plugin, so please let me know if it's an issue with the plugin or prettier itself:

I think it is a good idea to have some configuration to tell prettier not to change existing line breaks. For example, if I intentionally break a function call arguments into separate lines, prettier shouldn't put them on a single line just because the total length will be less than (or equal to) print width

Thank you

@ikatyang
Copy link
Member

Are you looking for // prettier-ignore?

@ikatyang ikatyang added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Mar 11, 2018
@farzadmf
Copy link
Author

Thank you @ikatyang. Seems to do the trick. Although to be honest, I think it would be useful to have it as a configuration option so that we don't need to bloat the code with this comment

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Mar 11, 2018
@duailibe
Copy link
Member

That's a difficult thing to implement because sometimes you do want your code to remove the linebreaks so it's kind of difficult to detect when you want or don't want to preserve line breaks.

@farzadmf
Copy link
Author

Thank you @duailibe , I guess you're right. For now, I went for the ignore.

But just wondering: isn't there a setting for something like this: when the number of arguments to a function exceeds a value (e.g., 3), then break the arguments and put each in a separate line.

And maybe this setting can be applied to object destruction and other things too ...

@j-f1
Copy link
Member

j-f1 commented May 13, 2018

Should we keep this open?

@duailibe
Copy link
Member

I guess not.

@Cotspheer
Copy link

I would like to see an option for this. For instance when you work with angular you have to import multiple modules with 2+ symbols. Now every single one gets a line break which bloats the header to an unnecessary number of lines.

Example:
import { MatCardModule, MatGridListModule, MatToolbarModule } from '@angular/material';

Gets transformed to:

import {
  MatCardModule,
  MatGridListModule,
  MatToolbarModule
} from '@angular/material';

The option "// prettier-ignore" won't work here because befor and after this line are more import statements. So I would end up with a not so nice looking zebra-stripped code (comment, statement, comment, statement...).

Is there any chance to implement such an option?

@bnfrnz
Copy link

bnfrnz commented Jul 12, 2018

I realise Prettier is "opinionated" and deliberately has few options to stop wasting time on getting to a style guide. And even though my formatting habits may differ here and there, for the most part I can see how Prettier's opinion makes sense (and is probably based on some sort of best practice).

However, preserving line-breaks is one option you really should add. It's the one thing missing that still keeps me (and many others I know) from using Prettier. Just my two cents...

@suchipi
Copy link
Member

suchipi commented Jul 12, 2018

@bnfrnz if there are specific cases where you think prettier's formatting is not ideal, please open a new issue. However, adding and removing line breaks is core to prettier's formatting algorithm, so preserving them isn't consistently possible.

@prettier prettier locked as spam and limited conversation to collaborators Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants