Skip to content

Trailing white-space are added after comments in the middle of a table #7

@Malian

Description

@Malian

Formatting the following code

samples do
      :fuel_type | :co2 | :year | :percentage
      # 2020
      :diesel    |  105 |  2020 |       0.069
end

Will result in:

samples do
      :fuel_type | :co2 | :year | :percentage
      # 2020----
      :diesel    |  105 |  2020 |       0.069
end

WIth 4 whitespaces after # 2020. I represented them with -

Here is a test that reproduces the bug:

  test "handle comments" do
    code = """
    samples do
      :fuel_type | :co2 | :year | :percentage
      # 2020
      :diesel | 105 | 2020 | 0.069
      :petrol | 110 | 2020 | 0.054
    end
    """

    assert Samples.FormatterPlugin.format(code, []) == """
           samples do
             :fuel_type | :co2 | :year | :percentage
             # 2020
             :diesel    |  105 |  2020 |       0.069
             :petrol    |  110 |  2020 |       0.054
           end
           """
  end

This is due to the offset we add to the first column

{col_index, value} ->
offset = if col_index == 0, do: String.duplicate(" ", column_offset), else: ""
offset <> align_value(value, cols_info[col_index], false)

A solution could be to pattern match on # in the walk function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions