gerbal

gerbal

Ordering Use, Import, Alias, Require?

Is there a recommended ordering of require, use, import, and alias? Does the style guide have anything to say about the preferred ordering of special forms?

Marked As Solved

moxley

moxley

Note that the order of some items have been changed:

  1. @moduledoc
  2. @behaviour
  3. use
  4. import
  5. require
  6. alias
  7. @module_attribute
  8. defstruct
  9. @type
  10. @callback
  11. @macrocallback
  12. @optional_callbacks
  13. defmacro, defmodule, defguard, def, etc.
19
Post #3

Also Liked

gerbal

gerbal

Nevermind, the styleguide is pretty explicit about this: GitHub - christopheradams/elixir_style_guide: A community driven style guide for Elixir · GitHub

List module attributes and directives in the following order:

  • @moduledoc
  • @behaviour
  • use
  • import
  • alias
  • require
  • defstruct
  • @type
  • @module_attribute
  • @callback
  • @macrocallback
  • @optional_callbacks

Add a blank line between each grouping, and sort the terms (like module names) alphabetically.

16
Post #2
LostKobrakai

LostKobrakai

It won‘t ever do that. One premise of the core formatter is that it won‘t change the underlying AST by applying formatting. That ensures that formatting will never introduce a change in behavior of the code and therefore won‘t introduce unintended bugs. Reordering expressions means changing the AST however.

lud

lud

I wonder if anyone is using the following:

  • alias
  • import
  • require
  • use

So you can just sort the whole thing alphabetically, without empty lines.

An only after that module attributes, including @moduledoc, as in the doc I found quite often useful to be able to reuse another attribute, or even call a remote function.

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement