All Projects → mirego → credo_naming

mirego / credo_naming

Licence: BSD-3-Clause license
🏷 A suite of Credo checks to enforce naming best practices in an Elixir project

Programming Languages

elixir
2628 projects
Makefile
30231 projects

Projects that are alternatives of or similar to credo naming

script-best-practices
Best practices for writing bash scripts
Stars: ✭ 15 (-77.94%)
Mutual labels:  best-practices
mllint
`mllint` is a command-line utility to evaluate the technical quality of Python Machine Learning (ML) projects by means of static analysis of the project's repository.
Stars: ✭ 67 (-1.47%)
Mutual labels:  best-practices
bce.design
minimal magic, minimal tooling, essential dependencies, high productivity, no transpilations and no migrations. The Web Components starter ships with integrated lit-html, redux-toolkit and vaadin router components.
Stars: ✭ 67 (-1.47%)
Mutual labels:  best-practices
into-docker
Never write another Dockerfile
Stars: ✭ 82 (+20.59%)
Mutual labels:  best-practices
a star on grids
Best practices for implementing A* with a focus on four- and eight-connected grid worlds.
Stars: ✭ 23 (-66.18%)
Mutual labels:  best-practices
Star-lang-specification
Work in progress specs for the Star programming language
Stars: ✭ 26 (-61.76%)
Mutual labels:  consistency
talk-dev-to-me-twitch
This repo is a collection of code samples and links to previous twitch live stream sessions. If you have any ideas or suggestions for future episodes, feel free to open an issue.
Stars: ✭ 118 (+73.53%)
Mutual labels:  best-practices
meshery.io
Site for Meshery, the cloud native management plane
Stars: ✭ 135 (+98.53%)
Mutual labels:  best-practices
NamingThings
Content on tips, tricks, advice, practices for naming things in in software/technology
Stars: ✭ 31 (-54.41%)
Mutual labels:  consistency
goodcode
A curated collection of annotated code examples from prominent open-source projects
Stars: ✭ 184 (+170.59%)
Mutual labels:  best-practices
Leetcoding-Challenge
This repository contains Leetcode Challenge Submissions.
Stars: ✭ 26 (-61.76%)
Mutual labels:  consistency
lightning-hydra-template
PyTorch Lightning + Hydra. A very user-friendly template for rapid and reproducible ML experimentation with best practices. ⚡🔥⚡
Stars: ✭ 1,905 (+2701.47%)
Mutual labels:  best-practices
dohq-ai-best-practices
Внедрение и эксплуатация PT Application Inspector. Подробнее: https://habr.com/ru/company/pt/blog/557142/
Stars: ✭ 22 (-67.65%)
Mutual labels:  best-practices
hybris
Robust and strongly consistent hybrid cloud storage library
Stars: ✭ 13 (-80.88%)
Mutual labels:  consistency
backend-best-practices
Backend uygulamaları geliştirirken dikkate alınabilecek örnek yöntemlerin derlendiği güncellenen bir kaynak.
Stars: ✭ 80 (+17.65%)
Mutual labels:  best-practices
php-the-right-way
La version française de "PHP: The Right Way" qui est un condensé des meilleures pratiques sur le développement PHP (conventions, liens vers les tutoriels qui font référence, etc)
Stars: ✭ 51 (-25%)
Mutual labels:  best-practices
best-practices
A guide for building better applications
Stars: ✭ 26 (-61.76%)
Mutual labels:  best-practices
devon4flutter-non-bloc-arch
A guide aiming to bridge the gap between the absolute Flutter basics and clean, structured Flutter Development
Stars: ✭ 283 (+316.18%)
Mutual labels:  best-practices
rubocop-graphql
Rubocop extension for enforcing graphql-ruby best practices
Stars: ✭ 143 (+110.29%)
Mutual labels:  best-practices
docker-multi-arch-hooks
Template Repository with Build Hooks for Multi-Arch and Semantic Versioned Docker Hub Containers
Stars: ✭ 29 (-57.35%)
Mutual labels:  best-practices



CredoNaming is a suite of checks to enforce naming best practices in an Elixir project.

Installation

Add the :credo_naming package to your mix.exs dependencies:

def deps do
  [
    {:credo_naming, "~> 2.0", only: [:dev, :test], runtime: false}
  ]
end

Usage

You just need to add the checks you want in your .credo.exs configuration file.

Avoid specific terms in module names

This check will raise an issue if specific terms are found in module names.

{CredoNaming.Check.Warning.AvoidSpecificTermsInModuleNames, terms: ["Manager", ~r/Helpers?/]}

Suppose you have a MyApp.ErrorHelpers module:

$ mix credo

┃  Warnings - please take a look
┃
┃ [W] ↘ `Helpers` is included in the list of terms to avoid in module names.
┃       Consider replacing it with a more accurate one.
┃       lib/my_app/error_helpers.ex:1:39 #(MyApp.ErrorHelpers)

With this check configuration for example, a module named MyApp.UserManager or MyApp.FormHelpers would not be allowed.

Ensure module/filename consistency

This check will raise an issue if the name of a module defined in a file does not match its filename.

{CredoNaming.Check.Consistency.ModuleFilename}

Suppose you have a lib/foo.ex file that defines a Bar module:

$ mix credo

┃ Consistency
┃
┃ [C] ↘ The module defined in `lib/foo.ex` is not named consistently with the
┃       filename. The file should be named either:
┃
┃       ["lib/bar/bar.ex", "lib/bar.ex"]
┃
┃       lib/foo.ex:1:11 #(Bar)

Exclusions

You can exclude files or paths with the excluded_paths option:

{CredoNaming.Check.Consistency.ModuleFilename, excluded_paths: ["test/support", "priv", "rel", "mix.exs"]}

Acronyms

The check converts module names to paths using PascalCase convention, which means that the file lib/myapp_graphql.ex is expected to define the module:

defmodule MyappGraphql do
end

If you want to define your own acronyms, you can do so using the acronyms option:

{CredoNaming.Check.Consistency.ModuleFilename, acronyms: [{"MyAppGraphQL", "myapp_graphql"}]}

Using this, the lib/myapp_graphql.ex file will expect to define the module:

defmodule MyAppGraphQL do
end

Naming conventions

By 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.

The callback receives three arguments:

  • filename, the stringified name of the module contained in the file (eg. "lib/my_app/foo/bar.ex")
  • module_name, the stringified name of the module contained in the file (eg. "MyApp.Foo.Bar")
  • opts, the options list passed to the check (eg. [acronyms: [{"GraphQL", "graphql"}]])

And must return a tuple containing a boolean value (if the filename is considered valid) and a list of expected filenames.

In 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.

def valid_filename?(filename, module_name, _opts) do
  root_path = CredoNaming.Check.Consistency.ModuleFilename.root_path(filename)
  path = "#{Macro.underscore(module_name)}#{Path.extname(filename)}"

  filenames = [
    Path.join([root_path, path])
  ]

  {filename in filenames, filenames}
end

{CredoNaming.Check.Consistency.ModuleFilename, valid_filename_callback: &valid_filename/3}

You could also use the callback to ignore specific files and fallback on the default callback for others.

def valid_filename?("lib/my_app/my_specific_file.ex", _module_name, _opts), do: {true, []}
def valid_filename?("lib/my_app/my_other_specific_file.ex", _module_name, _opts), do: {true, []}
def valid_filename?(filename, module_name, opts), do: CredoNaming.Check.Consistency.ModuleFilename.valid_filename?(filename, module_name, opts)

{CredoNaming.Check.Consistency.ModuleFilename, valid_filename_callback: &valid_filename/3}

Instead of implementing your own valid_filename_callback function, you can use the plugins option to enforce a specific supported naming convention. For now, only :phoenix is supported.

Contributors

License

CredoNaming is © 2019 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

The tag logo is based on this lovely icon by Vectors Point, from The Noun Project. Used under a Creative Commons BY 3.0 license.

About Mirego

Mirego 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 who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].