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

Adds multiline formatting for array #2593

Merged
merged 6 commits into from
Aug 20, 2022
Merged

Conversation

eureka-cpu
Copy link
Contributor

@eureka-cpu eureka-cpu commented Aug 19, 2022

Closes #726
Ref #2493

Copy link
Contributor

@Braqzen Braqzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. How come a tuple is being tested in an array PR?
  2. Should there be another test for
[ some, args, here, ...,
and, more,
here ]

and a few variations of that?

@eureka-cpu
Copy link
Contributor Author

  1. How come a tuple is being tested in an array PR?

    1. Should there be another test for
[ some, args, here, ...,
and, more,
here ]

and a few variations of that?

I can add it in another PR, they're both collections and use generally the same logic so I added it while testing to be sure they both functioned

@eureka-cpu
Copy link
Contributor Author

@Braqzen I'm not sure I understand the second part, if you'd like I can add an explicit example though! Currently we have either normal formatting

[some, thing, here, ...]

and once it reaches a threshold it gets vertical formatting

[
    some,
    thing,
    here,
    ...,
]

@Braqzen
Copy link
Contributor

Braqzen commented Aug 19, 2022

@Braqzen I'm not sure I understand the second part, if you'd like I can add an explicit example though! Currently we have either normal formatting

[some, thing, here, ...]

and once it reaches a threshold it gets vertical formatting

[
    some,
    thing,
    here,
    ...,
]

What will the formatter do if it is presented with the input that I have added in the code block?
What would it do if instead of having the ] on the same line, as in my example, it would be on a new line?

@eureka-cpu
Copy link
Contributor Author

@Braqzen I'm not sure I understand the second part, if you'd like I can add an explicit example though! Currently we have either normal formatting

[some, thing, here, ...]

and once it reaches a threshold it gets vertical formatting

[
    some,
    thing,
    here,
    ...,
]

What will the formatter do if it is presented with the input that I have added in the code block? What would it do if instead of having the ] on the same line, as in my example, it would be on a new line?

So, since this is an AST based formatter, it takes the actual items into account but not the white space. You can think of it like this, your example:

[ some, args, here, ...,
and, more,
here ]

gets collected, which you could represent like:
(keep in mind, I'm not sure how this actually looks, this is a rough representation for the purpose of explaining)

[Collection(Var("some"), Var("args"), Var("here"), Var("..."), Var("and"), Var("more"), Var("here"))]

it does not take into account any whitespace, the formatter strips that by design and we inject whitespace and newlines situationally
So the output would look like:

[some, args, here, ..., and, more, here]

@Braqzen
Copy link
Contributor

Braqzen commented Aug 19, 2022

@Braqzen I'm not sure I understand the second part, if you'd like I can add an explicit example though! Currently we have either normal formatting

[some, thing, here, ...]

and once it reaches a threshold it gets vertical formatting

[
    some,
    thing,
    here,
    ...,
]

What will the formatter do if it is presented with the input that I have added in the code block? What would it do if instead of having the ] on the same line, as in my example, it would be on a new line?

So, since this is an AST based formatter, it takes the actual items into account but not the white space. You can think of it like this, your example:

[ some, args, here, ...,
and, more,
here ]

gets collected, which you could represent like: (keep in mind, I'm not sure how this actually looks, this is a rough representation for the purpose of explaining)

[Collection(Var("some"), Var("args"), Var("here"), Var("..."), Var("and"), Var("more"), Var("here"))]

it does not take into account any whitespace, the formatter strips that by design and we inject whitespace and newlines situationally So the output would look like:

[some, args, here, ..., and, more, here]

That sounds really cool. Thanks for letting me know!

@eureka-cpu eureka-cpu enabled auto-merge (squash) August 20, 2022 02:21
@eureka-cpu eureka-cpu merged commit 1bcec29 into master Aug 20, 2022
@eureka-cpu eureka-cpu deleted the eureka-cpu/fmt-array-expr branch August 20, 2022 07:44
@eureka-cpu eureka-cpu mentioned this pull request Aug 23, 2022
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request forc formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

forc fmt doesn't format arrays very well.
3 participants