Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_formatter): Heuristic for fill arrays #3126

Merged
merged 5 commits into from
Aug 29, 2022

Commits on Aug 29, 2022

  1. Configuration menu
    Copy the full SHA
    8ccc97f View commit details
    Browse the repository at this point in the history
  2. feat(rome_js_formatter): Heuristic for flat arrays

    Align Rome's heuristic with Prettier's of when use `fill` vs a group.
    
    There's one difference that I intend not to fix because I believe it is a bug in Prettier.
    
    Rome's printer automatically inserts a `group` around `fill` elements so that `fits` returns `false` if it encounters any hard line break.
    Prettier doesn't do so and any hard line break will result in `fits` return true.
    
    This difference is meaningful for
    
    ```javascript
    [
    // comment2
    -380014,
    -253951682
      ]
    
    ```
    
    where the first element contains hard line breaks because of the `//comment`. Prettier assumes that the content fits and, thus, prints `-253...` on the same line. Rome does not and istead, prints a line break after `-3800..`.
    
    I can demonstrate that this leads to issues where Prettier incorrectly exceeds the line widths: [example](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBtAOlA9FgBJAWwIRgCZMBaAZgA4AGOgRgBYq32POvufe-+ANJVIBWKgE4RjAGw1yUXLgC6mEAJAQADjACW0AM7JQAQwBOpiAHcACmYSGUxgDaXjAT0PqARqeNgA1nAwAMrGxAAyOlBwyABmzvpw3r4BQcGaflEA5sgwpgCuSSBwBF5wACblFeHGUFn5xllwAGIQpgTGMLp1yCDG+TAQaiAAFjAETgDqIzrw+hlgcMH2szoAbrNuvWD6niBRiaYw1r5ZHXEJRQBW+gAewdlOcACK+RDwF06J6hmmh70wNyaOD6MCmHTaYaacGwSY6cowEbIeg-CyJSa+TS9aEguCmNYxdQARze8BOWgcIBxhwJw1McBJOnpJ0a5yQ8S+RUSBB0uQKXMeL1JMXZl3UMGMXjhCKRSFI4t8Oic2QAwhAiMZes4nMN8okACqShwc74gNaFACSUCqsGCYIhMAAgtbgoCnp9EgBfT1AA)
    
    ```javascript
    [
    // comment2
    -380014333333333333333333333333333333333333333333333333333333333333333333,
    -253951682
      ]
    ```
    MichaReiser committed Aug 29, 2022
    Configuration menu
    Copy the full SHA
    28b16e5 View commit details
    Browse the repository at this point in the history
  3. Merge with main

    MichaReiser committed Aug 29, 2022
    Configuration menu
    Copy the full SHA
    d681b13 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    703f696 View commit details
    Browse the repository at this point in the history
  5. Documentation

    MichaReiser committed Aug 29, 2022
    Configuration menu
    Copy the full SHA
    67b33ee View commit details
    Browse the repository at this point in the history