mirego / credo_naming

🏷 A suite of Credo checks to enforce naming best practices in an Elixir project
https://open.mirego.com
BSD 3-Clause "New" or "Revised" License
88 stars 9 forks source link

Not desired errors with phoenix projects #3

Closed Kitton closed 5 years ago

Kitton commented 5 years ago

credo_filename_consistency shows errors for web part of phoenix project. For example, for a well-established structure(AFAIK) like

module name - ProjectWeb.StatusController
file path - lib/project_web/controllers/status_controller.ex

it shows the expected error

┃ [C] ↘ The module defined in 
┃       `lib/project_web/controllers/status_controller.ex` is not named 
┃       consistently with the filename. The file should be named either:

┃       ["lib/project_web/status_controller/status_controller.ex", 
┃       "lib/project_web/status_controller.ex", 
┃       "lib/project_web.status_controller.ex"]

it will be good to handle it automatically or be able to manually define that project_web/controllers == project_web similar to acronyms functionality.

The same issue for the Views. Thanks!

remi commented 5 years ago

Yes, this is a known issue because credo_naming is somewhat opinionated.

In our Elixir boilerplate project we try to follow the <domain>.<context>.<module> naming convention.

Which means that for all things status-related in the ProjectWeb domain, all modules should be ProjectWeb.Status.<module> and located in lib/project_web/status/<file>.ex.

I’m going to close this issue and create a new enhancement issue to be able to define your own naming convention with credo_naming.

remi commented 4 years ago

@Kitton We just released v0.5.0 which supports a :valid_filename_callback option.

It’s not the ideal way to support multiple naming conventions, but it’s the best we can do at the moment 😄