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

Module naming with singular vs plural parent directory #160

Open
anthonator opened this issue Nov 13, 2017 · 1 comment
Open

Module naming with singular vs plural parent directory #160

anthonator opened this issue Nov 13, 2017 · 1 comment

Comments

@anthonator
Copy link

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!

@christopheradams
Copy link
Owner

Great suggestion. I think this would be appropriate as an additional rule after https://github.com/christopheradams/elixir_style_guide#module-name-nesting.

The example could be something like MyApp.XmlParser for my_app/parsers/xml_parser.ex.

Could we say more about when this rule can be applied?

It seems a good naming scheme when you want to group modules together that have the same "type" (e.g., Controller, Parser) and so the same suffix (_controller, _parser). In that case you can put them in a directory named after the plural of the type, but drop the directory name from the module name.

Are there any other packages besides Phoenix that use this naming and directory scheme? It would be helpful to document them here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants