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

Order top-level imports, requires, aliases, and uses #75

Closed
angelikatyborska opened this issue Sep 4, 2022 · 0 comments · Fixed by #76
Closed

Order top-level imports, requires, aliases, and uses #75

angelikatyborska opened this issue Sep 4, 2022 · 0 comments · Fixed by #76
Assignees
Labels
x:action/improve Improve existing functionality/content x:knowledge/intermediate Quite a bit of Exercism knowledge required x:module/representer Work on Representers x:size/medium Medium amount of work x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises)

Comments

@angelikatyborska
Copy link
Member

Let's normalize solutions by ordering all of those expressions in this order:

  1. All aliases, ordered alphabetically by the module
  2. All uses, ordered alphabetically by the module
  3. All requiress, ordered alphabetically by the module
  4. All importss, ordered alphabetically by the module

All I know is that aliases need to be first because they might affect the other ones (e.g. alias A.B.C; import C won't compile if you swap the order), but the order of the other expressions I chose arbitrarily. Do we have any reasons for any specific order?

Let's not touch any of those expressions that appear after the first function/macro/guard definition. In theory we could also order those expressions when they appear at the top of a function definition, but that's a rare case so maybe there's no point?

Example input:

defmodule Foo do
  import D
  alias X.Y.Z
  alias Banana, as: Ba
  use Z
  import A

  def calc(x), do: x * 2

  import C, only: [bar: 1]
end

Desired output

defmodule Foo do
  alias Banana, as: Ba
  alias X.Y.Z
  use Z
  import A
  import D

  def calc(x), do: x * 2

  import C, only: [bar: 1]
end
@angelikatyborska angelikatyborska added x:knowledge/intermediate Quite a bit of Exercism knowledge required x:module/representer Work on Representers x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises) x:size/medium Medium amount of work x:action/improve Improve existing functionality/content labels Sep 4, 2022
@jiegillet jiegillet self-assigned this Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:action/improve Improve existing functionality/content x:knowledge/intermediate Quite a bit of Exercism knowledge required x:module/representer Work on Representers x:size/medium Medium amount of work x:type/coding Write code that is not student-facing content (e.g. test-runners, generators, but not exercises)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants