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

Option to control threshold of amount of attributes to be put on separate lines #118

Closed
lehni opened this issue Sep 29, 2020 · 6 comments · Fixed by #119
Closed

Option to control threshold of amount of attributes to be put on separate lines #118

lehni opened this issue Sep 29, 2020 · 6 comments · Fixed by #119
Labels
type: feature request Functionality that introduces a new feature

Comments

@lehni
Copy link
Collaborator

lehni commented Sep 29, 2020

Request / Idea

It would be nice if there was an option with which I could set a threshold of the amount of attributes that should always be put on separate lines, regardless of wether they fit into printWidth chars or not, .e.g.

attributesOnNewLineThreshold: 2

Input

.container-with-one-attribute(attribute1='foo')

.container-with-two-attributes(attribute1='foo' attribute2='bar')

Expected Output

.container-with-one-attribute(attribute1='foo')

.container-with-two-attributes(
  attribute1='foo'
  attribute2='bar'
)

Would you consider the addition of such an option? I am happy to work on it. Not sure what it should be called though…

@Shinigami92 Shinigami92 added the type: feature request Functionality that introduces a new feature label Sep 29, 2020
@Shinigami92
Copy link
Member

Shinigami92 commented Sep 29, 2020

I would also want this to be kept to a minimum
So if there are only 2 attributes => don't break even if they are 240 columns long

But if they are 5? or more always break, even if they are below my configured 120 printWitdh


This could be solved via a int array: true range option 🤔 (tuple of 1-2 ints)
Or just two new options: min and max 🤷‍♂️


I would suggest just start with an implementation and also write tests
Then while coding you possible find a good solution
I'm always open for such options (I don't need to stick to prettier's core philosophy ^^)
The only thing to keep in mind is performance, so we just need to write the code in a performant way

@lehni
Copy link
Collaborator Author

lehni commented Sep 29, 2020

Great to hear, and good points! I'll play around with this a bit and see where I end up. So happy to hear about your opinion regarding the core philosophy. I do share that view ;)

@lehni
Copy link
Collaborator Author

lehni commented Sep 29, 2020

Perhaps as simple as this: maxAttributesOnSingleLine: 1

@Shinigami92
Copy link
Member

I more and more thing about that it was a bad idea to introduce options like attributeSeparator, closingBracketPosition and commentPreserveSpaces (I think I will deprecate these 3 and instead use their pug* equivalents)

So we directly should use pugMaxAttributesOnSingleLine

@lehni
Copy link
Collaborator Author

lehni commented Sep 29, 2020

Agreed! I only use those anyway. BTW, I noticed there is no mention of pugAttributeSeparator, pugClosingBracketPosition, pugCommentPreserveSpaces in the README. It only states:

All these six Prettier options have an alias e.g. pugSingleQuote

But those six aren't actually any of the three I mentioned above.

@Shinigami92
Copy link
Member

Yeah I know, I meant the alias equivalents and not the own options
But now you have also introduced pugArrowParens etc
So yes if you like you can update the README.md in a dedicated PR and check it entirely of out of date things 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request Functionality that introduces a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants