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

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

Open
Malian opened this issue Jun 9, 2022 · 0 comments
Open

Comments

@Malian
Copy link
Contributor

Malian commented Jun 9, 2022

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.

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

No branches or pull requests

1 participant