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

Reorder elements inside arrays #338

Closed
xamgore opened this issue Oct 22, 2022 · 1 comment
Closed

Reorder elements inside arrays #338

xamgore opened this issue Oct 22, 2022 · 1 comment

Comments

@xamgore
Copy link
Contributor

xamgore commented Oct 22, 2022

Hi! I would like to implement a PR that would allow sorting arrays. How I expect it to work:

# before
teloxide = { version = "0.11", features = ["macros", "auto-send", "rocksdb-storage"] }

# after
teloxide = { version = "0.11", features = ["auto-send", "macros", "rocksdb-storage"] }

What do you think about the idea? Are you ready to help me?

@xamgore xamgore changed the title Reorder elements of arrays Reorder elements inside arrays Oct 22, 2022
@tamasfe
Copy link
Owner

tamasfe commented Oct 24, 2022

Hi, thanks! This is a duplicate of #158, and the feature is welcome! I will close this in favour of the other issue.

Are you ready to help me?

Yes, I will try, although in very limited ways.

The array formatting code can be found here.

The code collects the values into groups that are separated by blank lines, so in theory sorting the rows before format_rows is called should get what you are looking for. The only issue is that at that point we only know about the formatted text, and we lose all other information, such as whether a value is a string or an integer, but I think a naive implementation could suffice.

So going by that implementation the sorting of multi-line arrays would look something like this:

# unformatted
foo = [
  "b",
  "a",
  "c",

  3,
  1,
  2,
]

# formatted
foo = [
  "a",
  "b",
  "c",

  1,
  2,
  3,
]

If we want absolute order without the groupings, this will get a bit more complicated.

After the formatting code is implemented, following are needed:

  • add an option for it in the formatter options
  • add tests for it
  • documentation on the website
  • add a vscode extension setting in package.json

@tamasfe tamasfe closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2022
@xamgore xamgore mentioned this issue Oct 29, 2022
5 tasks
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

2 participants