Credoを使って引数なしで関数を定義するときは、括弧を使用するかをチェックする

## 動作環境

```sh
$ cat /etc/os-release | grep VERSION=
VERSION="20.04.4 LTS (Focal Fossa)"

$ elixir -v
Erlang/OTP 24 [erts-12.3.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit]

Elixir 1.13.0 (compiled with Erlang/OTP 24)

```

## プロジェクトの作成

```sh
$ mix new hoge
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/hoge.ex
* creating test
* creating test/test_helper.exs
* creating test/hoge_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd hoge
    mix test

Run "mix help" for more commands.
```

## Credoを導入


`hoge/mix.exs`を変更
```diff_elixir
 defmodule Hoge.MixProject do
   use Mix.Project

   def project do
     [
       app: :hoge,
       version: "0.1.0",
       elixir: "~> 1.13",
       start_permanent: Mix.env() == :prod,
       deps: deps()
     ]
   end

   # Run "mix help compile.app" to learn about applications.
   def application do
     [
       extra_applications: [:logger]
     ]
   end

   # Run "mix help deps" to learn about dependencies.
   defp deps do
     [
+       {:credo, "~> 1.6"}
       # {:dep_from_hexpm, "~> 0.3.0"},
       # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
     ]
   end
 end
```

 mix deps.getを実行
```sh
$ cd hoge/
$ mix deps.get
Resolving Hex dependencies...
Dependency resolution completed:
New:
  bunt 0.2.0
  credo 1.6.4
  file_system 0.2.10
  jason 1.3.0
* Getting credo (Hex package)
* Getting bunt (Hex package)
* Getting file_system (Hex package)
* Getting jason (Hex package)
```

## 動作チェック
```sh
mix credo 
==> file_system
Compiling 7 files (.ex)
Generated file_system app
==> bunt
Compiling 2 files (.ex)
Generated bunt app
==> jason
Compiling 10 files (.ex)
Generated jason app
==> credo
Compiling 242 files (.ex)
Generated credo app
Checking 3 source files ...

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.00 seconds (0.00s to load, 0.00s running 52 checks on 3 files)
3 mods/funs, found no issues.

Showing priority issues: ↑ ↗ →  (use `mix credo explain` to explain issues, `mix credo --help` for options).
```

正常に動作することを確認できました。

## ソースをわざと規約違反にしてみる
仮に　def hello()の書き方はプロジェクト上は規約違反としてdef helloを正しいルールと仮定します。


`hoge/lib/hoge.ex` を修正

```diff_elixir
 defmodule Hoge do
   @moduledoc """
   Documentation for `Hoge`.
   """

   @doc """
   Hello world.

   ## Examples

       iex> Hoge.hello()
       :world

   """
-   def hello do
+   def hello() do
     :world
   end
 end
```

再度　 mix credoを実行

```sh
mix credo
Checking 3 source files ...

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.05 seconds (0.03s to load, 0.02s running 52 checks on 3 files)
3 mods/funs, found no issues.

Showing priority issues: ↑ ↗ →  (use `mix credo explain` to explain issues, `mix credo --help` for options).
```

通過してしまうので対策が必要です。

## credoの設定をする

```sh
$ mix credo gen.config
* creating .credo.exs
```

`hoge/.credo.exs` を変更
```diff_elixir
　# This file contains the configuration for Credo and you are probably reading
　# this after creating it with `mix credo.gen.config`.
　#
　# If you find anything wrong or unclear in this file, please report an
　# issue on GitHub: https://github.com/rrrene/credo/issues
　#
　%{
 　 #
  　# You can have as many configs as you like in the `configs:` field.
  　configs: [
　　　　#〜中略〜
  　    checks: %{
   　     enabled: [
    　      #
     　     ## Consistency Checks
      　    #
　　　　　　　#〜中略〜

          　#
          　## Readability Checks
         　 #
          　{Credo.Check.Readability.AliasOrder, []},
         　 #〜中略〜
         　 {Credo.Check.Readability.ParenthesesInCondition, []},
-          {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
+          {Credo.Check.Readability.ParenthesesOnZeroArityDefs, [priority: :high, parens: false]},
          　{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
　　　　　　　#〜中略〜
          　{Credo.Check.Readability.WithSingleClause, []},
　　　　　　　#〜中略〜

        　],
        　disabled: [
       　　　#〜中略〜
        　]
      　}
    　}
  　]
　}
```

## 再度チェックしてみる

```sh
$ mix credo
Checking 3 source files ...

  Code Readability                                                                                                                                        
┃ 
┃ [R] ↗ Do not use parentheses when defining a function which has no arguments.
┃       lib/hoge.ex:15 #(Hoge.hello)

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.05 seconds (0.03s to load, 0.02s running 53 checks on 3 files)
3 mods/funs, found 1 code readability issue.

Showing priority issues: ↑ ↗ →  (use `mix credo explain` to explain issues, `mix credo --help` for options).
```

チェックに引っかかる事を確認できました


## ソースを直してさらにチェックしてみる

`hoge/lib/hoge.ex` を修正

```diff_elixir
 defmodule Hoge do
   @moduledoc """
   Documentation for `Hoge`.
   """

   @doc """
   Hello world.

   ## Examples

       iex> Hoge.hello()
       :world

   """
-   def hello() do
+   def hello do   
     :world
   end
 end
```

```sh
$ mix credo
Checking 3 source files ...

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.05 seconds (0.03s to load, 0.02s running 53 checks on 3 files)
3 mods/funs, found no issues.

Showing priority issues: ↑ ↗ →  (use `mix credo explain` to explain issues, `mix credo --help` for options).
```
規約違反が解消されました。