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

Support default phoenix apps with additional options for ModuleFilename #11

Closed sitch closed 4 years ago

sitch commented 4 years ago

Currently if you have something like

defmodule MyAppWeb.MyController` do

phoenix will put this into

/my_app_web/controllers/my_controller.ex

So it would be useful if either in acronyms or substitutions where you could say

[{"my_app_web/controllers/, "my_app_web/"}]
remi commented 4 years ago

Hi @sitch,

This is a duplicate of #3 where I posted a kind of workaround.

In the current README.md there is this note:

In the future, there may be some “naming convention flavours” (eg. :default, :phoenix, etc.) to use instead of having to implement your own callback.

So if you implement a valid_filename_callback to match the naming pattern used in Phoenix, please share 😄

Cheers!

sitch commented 4 years ago

Oh kickass thanks!

sitch commented 4 years ago

For anyone else with a similiar phoniex-esque layout (just find and replace my_app with your app name):

        {
          CredoNaming.Check.Consistency.ModuleFilename,
          excluded_paths: ["config", "mix.exs"],
          valid_filename_callback: fn
            "lib/my_app_web/channels/" <> filepart, module_name, opts ->
              valid_filename?("lib/my_app_web/" <> filepart, module_name, opts)

            "lib/my_app_web/controllers/" <> filepart, module_name, opts ->
              valid_filename?("lib/my_app_web/" <> filepart, module_name, opts)

            "lib/my_app_web/views/" <> filepart, module_name, opts ->
              valid_filename?("lib/my_app_web/" <> filepart, module_name, opts)

            "test/my_app_web/channels/" <> filepart, module_name, opts ->
              valid_filename?("test/my_app_web/" <> filepart, module_name, opts)

            "test/my_app_web/controllers/" <> filepart, module_name, opts ->
              valid_filename?("test/my_app_web/" <> filepart, module_name, opts)

            "test/my_app_web/views/" <> filepart, module_name, opts ->
              valid_filename?("test/my_app_web/" <> filepart, module_name, opts)

            filename, module_name, opts ->
              valid_filename?(filename, module_name, opts)
          end
        },