exsamples icon indicating copy to clipboard operation
exsamples copied to clipboard

Long table is not formatted properly

Open Malian opened this issue 3 years ago • 1 comments

The following code:

      samples do
        :id | :name | :currency | :language | :population | :inflation | :continent | :main_sport | :independence_day
        1 | "Brazil" | "Real (BRL)" | "Portuguese" | 204451000 | 7.70 | "South America" | "Football" | ~D["1822-09-07"]
      end

is formatted like this:

      samples do
        :id |            :name | :currency | :language | :population | :inflation | :continent | :main_sport | :independence_day
           
          1
            |         "Brazil"
            |     "Real (BRL)"
            |     "Portuguese"
            |      204_451_000
            |             7.70
            |  "South America"
            |       "Football"
            | ~D["1822-09-07"]
      end

Here is a test that reproduce the error

  test "very long table" do
    code = """
    samples do
      :id | :name | :currency | :language | :population | :inflation | :continent | :main_sport | :independence_day
      1 | "Brazil" | "Real (BRL)" | "Portuguese" | 204451000 | 7.70 | "South America" | "Football" | ~D["1822-09-07"]
    end
    """

    assert Samples.FormatterPlugin.format(code, []) == """
           samples do
             :id | :name    | :currency    | :language    | :population | :inflation | :continent      | :main_sport | :independence_day
               1 | "Brazil" | "Real (BRL)" | "Portuguese" | 204_451_000 |       7.70 | "South America" | "Football"  | ~D["1822-09-07"]
           end
           """
  end

I am suspecting the line_length to be the cause of this behaviour.

I believe we should override the line_length to properly render the table. WDYT? ping @msaraiva

Malian avatar Jun 02 '22 12:06 Malian

Yeah, the problem is that we need to run the Elixir formatter before we run ours, keeping its original behavior, including the line length. We need to find another way to do that. Maybe something like:

  1. read the original tables
  2. run the Elixir formatter
  3. replace the wrongly formatted tables with the original ones
  4. run our formatter

Any other suggestion?

msaraiva avatar Jun 02 '22 13:06 msaraiva