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

Block-style formatting for integer literal arrays #191

Open
jgardn3r opened this issue Mar 12, 2025 · 1 comment
Open

Block-style formatting for integer literal arrays #191

jgardn3r opened this issue Mar 12, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@jgardn3r
Copy link
Collaborator

Continuing the discussion from #168.

Sometimes large quantities of arguments are a necessity. For example, a constant array construction:

const
  Log2DeBruijn: array[0..31] of Byte = (
    00, 09, 01, 10, 13, 21, 02, 29, //
    11, 14, 16, 18, 22, 25, 03, 30, //
    08, 12, 20, 28, 15, 17, 24, 07, //
    19, 27, 23, 06, 26, 05, 04, 31 //
  );

With the current formatting, each element in the array would be wrapped onto its own line. With large element quantities, this can easily explode a unit's line count and degrade readability.

A proposed solution is to:

  • Using some heuristics, enter a "block" mode for elements. Suggestions include:
    • If all elements are integer literals
    • If all elements are shorter than a configured length
    • If the element count is over some threshold
  • Continue placing elements inline until over the line length, then break
    • Allow users to use // to break the line, as seen above (don't force 1-per-line like prettier though)
@sglienke
Copy link

sglienke commented Mar 18, 2025

I don't know what you have changed but now it turns this code:

  const
    ObjectFinalizerVtable: array[0..3] of Pointer =
    (
      @NopQueryInterface,
      @RecAddRef,
      @TObjectFinalizer._Release,
      @TObjectFinalizer.Invoke
    );
    RecordFinalizerVtable: array[0..3] of Pointer =
    (
      @NopQueryInterface,
      @RecAddRef,
      @TRecordFinalizer._Release,
      @TRecordFinalizer.Invoke
    );

into this:

    const
      ObjectReferenceVtable: array[0..2] of Pointer = (@NopQueryInterface, @RecAddRef, @TReference._Release_Obj);

      InterfaceReferenceVtable: array[0..2] of Pointer = (@NopQueryInterface, @RecAddRef, @TReference._Release_Intf);

I get the opinionated part of the formatter but it should behave in a way where it allows different styles of some code structures to exist. If the code exists in one of the valid ways - fine, don't touch it. If it's not in a valid format then it can opt for one way to turn it into. I don't want a plethora of options to choose from to make the formatter produce some certain style but it should not only stick to one correct way and reformat another correct way. And the formatting of arrays or sets is one of them.

Especially since in this particular case I showed above just a few lines above there was a similar array with just 2 elements more and it left them in their own lines because it could not fit them all into one line. (well except the fact that it did eqyptian parentheses there which I absolutely loathe)

This is probably similar to the wrapping of parameters when the signature does not fit into one line. If I decide the "every parameter in its own line" style for all my methods the formatter will still touch that code and put all signatures into one line if they fit. And that's a bad behavior imo.

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

No branches or pull requests

2 participants