Skip to content

# styler:sort doesn't sort map keys in typespecs #213

@rojnwa

Description

@rojnwa

Versions

Elixir: 1.18.2
Styler: 1.3.3

Example Input

defmodule Example do
  # styler:sort
  @type t :: %__MODULE__{
          id: Ecto.UUID.t(),
          street_address: String.t(),
          postal_code: String.t(),
          locality: String.t(),
          region: String.t(),
          country_iso: String.t(),
          deleted_at: DateTime.t() | nil,
          inserted_at: DateTime.t(),
          updated_at: DateTime.t()
        }
end

Stacktrace / Current Behaviour

When putting a line break in the definition after ::, the list gets ordered and # styler:sort is moved back above the module attribute again. The line break persists.

defmodule Example do
  @type t ::
          # styler:sort
          %__MODULE__{
            id: Ecto.UUID.t(),
            street_address: String.t(),
            postal_code: String.t(),
            locality: String.t(),
            region: String.t(),
            country_iso: String.t(),
            deleted_at: DateTime.t() | nil,
            inserted_at: DateTime.t(),
            updated_at: DateTime.t()
          }
end

Because the comment gets moved, this map won't be sorted afterwards.

defmodule Example do
  # styler:sort
  @type t ::
          %__MODULE__{
            country_iso: String.t(),
            deleted_at: DateTime.t() | nil,
            id: Ecto.UUID.t(),
            inserted_at: DateTime.t(),
            locality: String.t(),
            postal_code: String.t(),
            region: String.t(),
            street_address: String.t(),
            updated_at: DateTime.t()
          }
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions