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

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

Open
rojnwa opened this issue Feb 7, 2025 · 1 comment
Open

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

rojnwa opened this issue Feb 7, 2025 · 1 comment

Comments

@rojnwa
Copy link

rojnwa commented Feb 7, 2025

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
@rojnwa rojnwa changed the title #styler:sort doesn't work on module attributes with maps/structs # styler:sort doesn't work on module attributes with maps/structs Feb 7, 2025
@novaugust
Copy link
Contributor

thanks for the issue. the problem here is the ::, styler doesn't know what to do with that. happy to take a PR!

@novaugust novaugust changed the title # styler:sort doesn't work on module attributes with maps/structs # styler:sort doesn't sort map keys in typespecs Feb 7, 2025
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

2 participants