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

Feat Request: Option to set and enforce a specific number of line breaks #210

Open
badrobit opened this issue Sep 25, 2024 · 3 comments
Open

Comments

@badrobit
Copy link

badrobit commented Sep 25, 2024

The current formatter will allow you to keep as many or as few line breaks if they already exist between entries. I was hoping by setting retain_line_breaks_single: true it would also add line breaks if they didn't exist already.

The output of the tool would be more uniform (but cause bigger diffs) if it were to set the number of line breaks and add/remove them until at the user defined (or default) setting.

e.g.

formatter:
  type: basic
  line_breaks: 1 # <-- New Suggested setting

it could default to zero which would remove them all which is the current behavior then when a value is set it would add/trim the found line breaks to align with the user defined value.

Example:

Input:

a: 
    b_a: value
    b_b: value2
    a-b: 
      - x
      - y
      - z
    a-c: 
      - x
      - y
      - z
      -

output:

a:  # I am unsure if a newline after this but before (b_a) makes sense 

    b_a: value
    b_b: value2 # I am unsure if a newline after this but before (a_b) makes sense 

    a_b: 
      - x
      - y
      - z

    a_c: 
      - x
      - y
      - z
@braydonk
Copy link
Collaborator

braydonk commented Sep 25, 2024

Hi @badrobit thanks for the feature request.

I have had requests for similar features before, but your version sounds a bit different and if I'm understanding correctly is the first I've ever heard of anyone having a use case like this.
Do you mean you'd like a feature Like this?
Before:

a: 1
b: 2
c: 3

After:

a: 1

b: 2

c: 3

If so, I suppose I could add something like that but it's definitely the first I've heard of someone wanting something like this.

I have had requests for a feature like retain_max_line_breaks such that with a setting like retain_max_line_breaks: 2 this:

a: 1



b: 2

Would become:

a: 1


b: 2

That feature would be relatively easy to implement, but it sounds different than what you're asking for so I want to make sure.

@badrobit
Copy link
Author

badrobit commented Sep 25, 2024

I think it is a weird mix (I know why can it not just be simple). I think it would be based on parent grouping so if say you had the following:

a: 
    b_a: value
    b_b: value2
    a-b: 
      - x
      - y
      - z
    a-c: 
      - x
      - y
      - z

you would get the following out (assuming line separation is set to 1:

a:  # I am unsure if a newline after this but before (b_a) makes sense 
    b_a: value
    b_b: value2 # I am unsure if a newline after this but before (a_b) makes sense 
    a_b: 
      - x
      - y
      - z

    a_c: 
      - x
      - y
      - z

Adding in the option with the newlines just to see how it looks (I think I like it more)

a:  # I am unsure if a newline after this but before (b_a) makes sense 

    b_a: value
    b_b: value2 # I am unsure if a newline after this but before (a_b) makes sense 

    a_b: 
      - x
      - y
      - z

    a_c: 
      - x
      - y
      - z

I think what I am asking for is if at each level (with children) it is separated. I think the key part is the children as it would be a bit weird and less readable if you put a line between every entry. The most common example I can think of that I tend to do this with is the .pre-commit-config.yaml where I will add a new line between each repo listed.

Seeing the second option I can see my background from python is clearly having an impact here. I did try to find justification in the YAML spec and this setup would flow with their guide for indentation being a strong indicator of grouping but I couldn't find anything on recommendations for newline spacing.

@z2oh
Copy link

z2oh commented Dec 10, 2024

I'd like to echo this feature request. I'm looking to format some GitHub actions workflows with lengthy, multi-line values; added whitespace makes them much easier to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants