{"id":21692533,"url":"https://github.com/mirego/credo_naming","last_synced_at":"2025-12-12T00:16:26.166Z","repository":{"id":34651368,"uuid":"182267826","full_name":"mirego/credo_naming","owner":"mirego","description":"🏷 A suite of Credo checks to enforce naming best practices in an Elixir project","archived":false,"fork":false,"pushed_at":"2023-11-23T19:24:22.000Z","size":134,"stargazers_count":82,"open_issues_count":2,"forks_count":9,"subscribers_count":33,"default_branch":"main","last_synced_at":"2024-04-13T03:47:22.539Z","etag":null,"topics":["best-practices","consistency","credo","elixir"],"latest_commit_sha":null,"homepage":"https://open.mirego.com","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mirego.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-19T13:20:40.000Z","updated_at":"2024-06-19T04:07:48.994Z","dependencies_parsed_at":"2023-11-23T20:27:02.298Z","dependency_job_id":null,"html_url":"https://github.com/mirego/credo_naming","commit_stats":{"total_commits":78,"total_committers":7,"mean_commits":"11.142857142857142","dds":0.3205128205128205,"last_synced_commit":"2b9d9a114b717e039f5e108f470b66b43aa92a47"},"previous_names":["mirego/credo_filename_consistency"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirego%2Fcredo_naming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirego%2Fcredo_naming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirego%2Fcredo_naming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirego%2Fcredo_naming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mirego","download_url":"https://codeload.github.com/mirego/credo_naming/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361705,"owners_count":20926643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["best-practices","consistency","credo","elixir"],"created_at":"2024-11-25T18:16:24.395Z","updated_at":"2025-12-12T00:16:24.108Z","avatar_url":"https://github.com/mirego.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/11348/59598372-07ca4200-90ca-11e9-8645-88642ef06a64.png\" width=\"600\" /\u003e\n  \u003cbr /\u003e\u003cbr /\u003e\n  \u003ccode\u003eCredoNaming\u003c/code\u003e is a suite of checks to enforce naming best practices in an Elixir project.\n  \u003cbr /\u003e\u003cbr /\u003e\n  \u003ca href=\"https://github.com/mirego/credo_naming/actions?query=workflow%3ACI+branch%3Amain+event%3Apush\"\u003e\u003cimg src=\"https://github.com/mirego/credo_naming/workflows/CI/badge.svg?branch=master\u0026event=push\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://hex.pm/packages/credo_naming\"\u003e\u003cimg src=\"https://img.shields.io/hexpm/v/credo_naming.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\nAdd the `:credo_naming` package to your `mix.exs` dependencies:\n\n```elixir\ndef deps do\n  [\n    {:credo_naming, \"~\u003e 2.1\", only: [:dev, :test], runtime: false}\n  ]\nend\n```\n\n## Usage\n\nYou just need to add the checks you want in your `.credo.exs` configuration file.\n\n### Avoid specific terms in module names\n\nThis check will raise an issue if specific terms are found in module names.\n\n```elixir\n{CredoNaming.Check.Warning.AvoidSpecificTermsInModuleNames, terms: [\"Manager\", ~r/Helpers?/]}\n```\n\nSuppose you have a `MyApp.ErrorHelpers` module:\n\n```\n$ mix credo\n\n┃  Warnings - please take a look\n┃\n┃ [W] ↘ `Helpers` is included in the list of terms to avoid in module names.\n┃       Consider replacing it with a more accurate one.\n┃       lib/my_app/error_helpers.ex:1:39 #(MyApp.ErrorHelpers)\n```\n\nWith this check configuration for example, a module named `MyApp.UserManager` or `MyApp.FormHelpers` would not be allowed.\n\n### Ensure module/filename consistency\n\nThis check will raise an issue if the name of a module defined in a file does not match its filename.\n\n```elixir\n{CredoNaming.Check.Consistency.ModuleFilename}\n```\n\nSuppose you have a `lib/foo.ex` file that defines a `Bar` module:\n\n```\n$ mix credo\n\n┃ Consistency\n┃\n┃ [C] ↘ The module defined in `lib/foo.ex` is not named consistently with the\n┃       filename. The file should be named either:\n┃\n┃       [\"lib/bar/bar.ex\", \"lib/bar.ex\"]\n┃\n┃       lib/foo.ex:1:11 #(Bar)\n```\n\n#### Exclusions\n\nYou can exclude files or paths with the `excluded_paths` option:\n\n```elixir\n{CredoNaming.Check.Consistency.ModuleFilename, excluded_paths: [\"test/support\", \"priv\", \"rel\", \"mix.exs\"]}\n```\n\nYou can also exclude files or paths with regex:\n\n```elixir\n{CredoNaming.Check.Consistency.ModuleFilename, excluded_paths: [~r/test\\/support/, ~r/priv/, ~r/.exs/]}\n```\n\n#### Acronyms\n\nThe check converts module names to paths using `PascalCase` convention, which means that the file `lib/myapp_graphql.ex` is expected to define the module:\n\n```elixir\ndefmodule MyappGraphql do\nend\n```\n\nIf you want to define your own acronyms, you can do so using the `acronyms` option:\n\n```elixir\n{CredoNaming.Check.Consistency.ModuleFilename, acronyms: [{\"MyAppGraphQL\", \"myapp_graphql\"}]}\n```\n\nUsing this, the `lib/myapp_graphql.ex` file will expect to define the module:\n\n```elixir\ndefmodule MyAppGraphQL do\nend\n```\n\n#### Naming conventions\n\nBy default, the check allows for a specific list of valid filenames when a single module is declared within a file. You can overwrite this behaviour by providing the `valid_filename_callback` option and implement yourself if a filename should be considered valid.\n\nThe callback receives three arguments:\n\n- `filename`, the stringified name of the module contained in the file (eg. `\"lib/my_app/foo/bar.ex\"`)\n- `module_name`, the stringified name of the module contained in the file (eg. `\"MyApp.Foo.Bar\"`)\n- `opts`, the options list passed to the check (eg. `[acronyms: [{\"GraphQL\", \"graphql\"}]]`)\n\nAnd must return a tuple containing a boolean value (if the filename is considered valid) and a list of expected filenames.\n\nIn this (very simple) example, a file `lib/my_app/wrong.ex` that defines a `MyApp.Foo.Bar` module would return a `{false, [\"lib/my_app/foo/bar.ex\"]}` tuple.\n\n```elixir\ndef valid_filename?(filename, module_name, _opts) do\n  root_path = CredoNaming.Check.Consistency.ModuleFilename.root_path(filename)\n  path = \"#{Macro.underscore(module_name)}#{Path.extname(filename)}\"\n\n  filenames = [\n    Path.join([root_path, path])\n  ]\n\n  {filename in filenames, filenames}\nend\n\n{CredoNaming.Check.Consistency.ModuleFilename, valid_filename_callback: \u0026valid_filename/3}\n```\n\nYou could also use the callback to ignore specific files and fallback on the default callback for others.\n\n```elixir\ndef valid_filename?(\"lib/my_app/my_specific_file.ex\", _module_name, _opts), do: {true, []}\ndef valid_filename?(\"lib/my_app/my_other_specific_file.ex\", _module_name, _opts), do: {true, []}\ndef valid_filename?(filename, module_name, opts), do: CredoNaming.Check.Consistency.ModuleFilename.valid_filename?(filename, module_name, opts)\n\n{CredoNaming.Check.Consistency.ModuleFilename, valid_filename_callback: \u0026valid_filename/3}\n```\n\nInstead of implementing your own `valid_filename_callback` function, you can use the `plugins` option to enforce a specific supported naming convention. This option accepts a list of: one arity function or plugin name (for now, only `CredoNaming.Check.Consistency.ModuleFilename.Plugins.Phoenix` is supported as a predefined plugin).\n\n```elixir\n{CredoNaming.Check.Consistency.ModuleFilename, plugins: [CredoNaming.Check.Consistency.ModuleFilename.Plugins.Phoenix, \u0026IO.inspect/1]}\n```\n\n#### Setting `apps_path`\n\nIn case you have an umbrella project and have set `apps_path` to something other than `apps`, you can set the `apps_path` option to the correct path.\n\n```elixir\n{CredoNaming.Check.Consistency.ModuleFilename, apps_path: \"my_apps_path\"}\n```\n\n## Contributors\n\n- Rémi Prévost ([@remiprev](https://github.com/remiprev))\n- Tomáš Janoušek ([@liskin](https://github.com/liskin))\n- Felipe Duzzi ([@duzzifelipe](https://github.com/duzzifelipe))\n- Daniel Willeitner ([@D-Town44](https://github.com/D-Town44))\n- Daniel Reigada ([@DReigada](https://github.com/DReigada))\n- Pavel Tsiukhtsiayeu ([@paveltyk](https://github.com/paveltyk))\n\n## License\n\n`CredoNaming` is © 2019 [Mirego](https://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/credo_naming/blob/main/LICENSE.md) file.\n\nThe tag logo is based on [this lovely icon by Vectors Point](https://thenounproject.com/term/tag/2606427), from The Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.\n\n## About Mirego\n\n[Mirego](https://www.mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We’re a team of [talented people](https://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://www.mirego.org).\n\nWe also [love open-source software](https://open.mirego.com) and we try to give back to the community as much as we can.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirego%2Fcredo_naming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmirego%2Fcredo_naming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirego%2Fcredo_naming/lists"}