Skip to content

Block-style formatting for integer literal arrays #191

Description

@jgardn3r

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions