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

feat: comment directive "sort" #167

Closed
novaugust opened this issue May 16, 2024 · 5 comments · Fixed by #205 or #207
Closed

feat: comment directive "sort" #167

novaugust opened this issue May 16, 2024 · 5 comments · Fixed by #205 or #207
Labels
enhancement New feature or request

Comments

@novaugust
Copy link
Contributor

Often there's a series of ast siblings that codebase authors want to keep sorted. We know this to be the case for things like aliases, imports, etc, but what about arbitrary lists within the code? The author just has to put a comment like "please keep this sorted :(" and hope their coworkers play along.

But the whole point of styler is saving you from having to think about your coworkers preferences! (this is a joke. sort of.)

So maybe it could maintain this for us?

Example Input

# given
@my_list [
  # styler:sort
  :a,
  :quick,
  :brown,
  :fox
]
# get
@my_list [
  # styler:sort
  :a,
  :brown,
  :fox,
  :quick
]

could be neat!

@novaugust novaugust added the enhancement New feature or request label Nov 7, 2024
@zimt28
Copy link

zimt28 commented Nov 22, 2024

I like to sort my deps alphabetically, so this might be helpful there, too.

@novaugust
Copy link
Contributor Author

@zimt28 should be! you could take styler main for a drive if you wanted to test it out. it'd look like this:

def deps do
  # styler:sort
  [
    {:styler, github: "adobe/elixir-styler"},
    ...
  ]
end

@zimt28
Copy link

zimt28 commented Nov 23, 2024

It doesn't work quite right yet, this is the order it produces:

defp deps do
  # styler:sort
  [
    {:styler, github: "adobe/elixir-styler"},
    {:ash, "~> 3.0"},
    {:ash_phoenix, "~> 2.0"},
    {:ash_postgres, "~> 2.0"},
    {:bandit, "~> 1.5"},
    {:dns_cluster, "~> 0.1.1"},
    {:ecto_sql, "~> 3.10"},
    {:finch, "~> 0.13"},
    {:gettext, "~> 0.20"},
    {:heroicons,
      github: "tailwindlabs/heroicons", tag: "v2.1.1", sparse: "optimized", app: false, compile: false, depth: 1},
    {:igniter, "~> 0.1"},
    {:jason, "~> 1.2"},
    {:phoenix, "~> 1.7.14"},
    {:phoenix_ecto, "~> 4.5"},
    {:phoenix_html, "~> 4.1"},
    {:phoenix_live_dashboard, "~> 0.8.3"},
    # TODO bump on release to {:phoenix_live_view, "~> 1.0.0"},
    {:postgrex, ">= 0.0.0"},
    {:swoosh, "~> 1.5"},
    {:telemetry_metrics, "~> 1.0"},
    {:telemetry_poller, "~> 1.0"},
    {:phoenix_live_view, "~> 1.0.0-rc.1", override: true},
    {:esbuild, "~> 0.8", runtime: Mix.env() == :dev},
    {:floki, ">= 0.30.0", only: :test},
    {:fluxon, "~> 1.0.0", repo: :fluxon},
    {:phoenix_live_reload, "~> 1.2", only: :dev},
    {:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
    {:tailwind_formatter, "~> 0.4", only: [:dev, :test], runtime: false}
  ]
end

Also, it would be nice if it could move along comments above entries

@novaugust
Copy link
Contributor Author

ah thanks, will address the tuple issues and the comments (thanks for the reminder) before releasing :)

@novaugust novaugust reopened this Nov 23, 2024
@novaugust
Copy link
Contributor Author

tuples will sort properly with the latest commit, 411cc93

will take a stab at comments sometime in the next week, they're always tricky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants