项目作者: xtian

项目描述 :
A happy home for custom Credo checks
高级语言: Elixir
项目地址: git://github.com/xtian/credo_contrib.git
创建时间: 2018-01-19T23:42:34Z
项目社区:https://github.com/xtian/credo_contrib

开源协议:ISC License

下载


CredoContrib Hex

CredoContrib is a set of additional checks for the Credo static analysis tool.
Many of the checks are implementations of rules from
christopheradams/elixir_style_guide. Contributions welcome!

Installation

Add credo_contrib to the list of dependencies in your mix.exs:

  1. def deps do
  2. [
  3. {:credo_contrib, "~> 0.2.0", only: [:dev, :test], runtime: false}
  4. ]
  5. end

Usage

Add CredoContrib as a plugin in your .credo.exs to enable all checks:

  1. %{
  2. configs: [
  3. %{
  4. name: "default",
  5. plugins: [
  6. {CredoContrib, []}
  7. ]
  8. }
  9. ]
  10. }

Or add the desired checks individually:

  1. %{
  2. configs: [
  3. %{
  4. name: "default",
  5. checks: [
  6. {CredoContrib.Check.FunctionBlockSyntax, allow_single_kw_defs: false},
  7. # …
  8. ]
  9. }
  10. ]
  11. }

Available Checks

CredoContrib.Check.DocWhitespace

Disallows extranneous whitespace in documentation strings:

  1. ## GOOD
  2. defmodule Foo do
  3. @moduledoc """
  4. This is a module
  5. """
  6. @doc """
  7. This is a function
  8. """
  9. def bar do
  10. :ok
  11. end
  12. end
  13. ## BAD
  14. defmodule Foo do
  15. @moduledoc """
  16. This is a module
  17. """
  18. @doc """
  19. This is a function
  20. """
  21. def bar do
  22. :ok
  23. end
  24. end

CredoContrib.Check.EmptyDocString

Disallows @doc strings that do not contain any text.

  1. ## GOOD
  2. @doc """
  3. This is a function
  4. """
  5. def bar do
  6. :ok
  7. end
  8. ## BAD
  9. @doc """
  10. """
  11. def bar do
  12. :ok
  13. end

CredoContrib.Check.EmptyTestBlock

Disallows usage of ExUnit.Case.test/3 with an empty body.

For unimplemented tests, use ExUnit.Case.test/1 and set ExUnit.start(except: [:not_implemented])

  1. ## GOOD
  2. test "something not implemented"
  3. test "something implemented" do
  4. assert 1 + 1 == 2
  5. end
  6. ## BAD
  7. test "something not implemented" do
  8. end

CredoContrib.Check.FunctionBlockSyntax

Disallows mixing of def …, do: syntax with multiple def … do … end-style
definitions

https://github.com/christopheradams/elixir_style_guide#multiple-function-defs

Options

  • allow_single_kw_defs (default: true): Set to false to only allow def …, do: syntax for
    functions with multiple heads

CredoContrib.Check.FunctionNameUnderscorePrefix

Disallows function names prefixed with a single underscore

https://github.com/christopheradams/elixir_style_guide#private-functions-with-same-name-as-public


CredoContrib.Check.ModuleAlias

Disallows alias __MODULE__ and @foo __MODULE__

https://github.com/christopheradams/elixir_style_guide#module-pseudo-variable


CredoContrib.Check.ModuleDirectivesOrder

Enforces consistent ordering for module attributes and directives.

https://github.com/christopheradams/elixir_style_guide#module-attribute-ordering


CredoContrib.Check.PublicPrivateFunctionName

Disallows public and private functions with the same name

https://github.com/christopheradams/elixir_style_guide#private-functions-with-same-name-as-public


CredoContrib.Check.SingleFunctionPipe

Disallows usage of the pipe operator with a single function call

https://github.com/christopheradams/elixir_style_guide#avoid-single-pipelines

Options

  • ignored_locals: Keyword list of names and arities of local functions to ignore. E.g., [expect: 3, stub: 3]

Development

Setup

  1. bin/setup

Running the tests

  1. bin/test

License

ISC