rrrene / credo-proposals

Proposals for Credo, the Elixir code analysis tool with a focus on code consistency and teaching
MIT License
9 stars 0 forks source link

Proposal: Prefer alias over import for a single function #20

Open ghost opened 6 years ago

ghost commented 6 years ago

Environment

What were you trying to do?

When a user, uses import for a single function from a module, a Software design should be thrown.

Expected outcome

When running:

mix credo --strict

Users should be warned about using import for a single function.

Actual outcome

Nothing, import for a single function without using only is not flagged.

Selvaticus commented 6 years ago

Hi @dark0dave,

Would credo have to distinguish between functions and macros? In order to present the warning or not.

Also, what is the drive being using alias instead of import? (In my ignorance I feel they are the same if talk about functions)

Cheers

ghost commented 6 years ago

It would not.

The reason here is mostly for readability, it becomes complex if you import multiple modules with import. Better to alias where possible, in this manner its more precise as what functions you are using.

Ideal use would be if just using a single function from a module, alias would be used. If all functions are in use then import is acceptable.