christopheradams / christopheradams/elixir_style_guide

Module naming with singular vs plural parent directory

Open
#160 1 comment 5 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
Elixir
Stars
4.4k
Forks
300
PR merge metrics
No merged PRs in 30d

Description

There should be a rule that handles naming modules based on whether the parent directory is plural or singular.

The most notable example of this is Phoenix. If you look at how Phoenix structures controllers you can see that it follows a different naming convention than what is specified in the style guide.

For example, a controller at the following path `my_app/controllers/home_controller.ex` will be named `MyApp.HomeController`. According to the style guide, it should be named `MyApp.Controllers.HomeController`.

Given that Phoenix is probably the most prominent project in Elixirland I think it makes sense to create a rule to accommodate this style.

If a parent directory name is plural than the module author _may_ choose to omit the parent directory in the module name. In this case, a singular form of the parent directory name _must_ be appended to the file name. The module name will reflect the file name.

For the directory structure `my_app/controllers/home_controller.ex` the module name `MyApp.HomeController` is valid.

If the module author does not omit the parent directory than the current rules apply.

Let me know what you think!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.