diff --git a/.travis.yml b/.travis.yml index f253d10..1071b16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,6 @@ language: elixir elixir: '1.9' env: - MIX_ENV=test -script: mix coveralls.travis \ No newline at end of file +script: + - mix credo --strict + - mix coveralls.travis \ No newline at end of file diff --git a/config/.credo.exs b/config/.credo.exs new file mode 100644 index 0000000..ceb8e0d --- /dev/null +++ b/config/.credo.exs @@ -0,0 +1,33 @@ +%{ + configs: [ + %{ + name: "default", + files: %{ + included: ["lib/", "src/", "web/", "apps/"], + excluded: [] + }, + checks: [ + {Credo.Check.Refactor.MapInto, false}, + {Credo.Check.Warning.LazyLogging, false}, + {Credo.Check.Readability.ModuleDoc, false}, + {Credo.Check.Consistency.TabsOrSpaces}, + + # For some checks, like AliasUsage, you can only customize the priority + # Priority values are: `low, normal, high, higher` + {Credo.Check.Design.AliasUsage, priority: :low}, + + # For others you can also set parameters + {Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100}, + + # You can also customize the exit_status of each check. + # If you don't want TODO comments to cause `mix credo` to fail, just + # set this value to 0 (zero). + {Credo.Check.Design.TagTODO, exit_status: 2}, + + # To deactivate a check: + # Put `false` as second element: + {Credo.Check.Design.TagFIXME, false} + ] + } + ] +} diff --git a/lib/redex/command/set.ex b/lib/redex/command/set.ex index f1b6aba..cf39197 100644 --- a/lib/redex/command/set.ex +++ b/lib/redex/command/set.ex @@ -3,6 +3,7 @@ defmodule Redex.Command.SET do @default_args %{expiry: nil, nx: false, xx: false} + # credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity def exec([key, value | args], state = %State{quorum: quorum, db: db}) do case args(args, @default_args) do {:ok, args} -> diff --git a/lib/redex/manager.ex b/lib/redex/manager.ex index 2e41259..1948283 100644 --- a/lib/redex/manager.ex +++ b/lib/redex/manager.ex @@ -127,12 +127,9 @@ defmodule Redex.Manager do true -> Logger.info("sync readonly partition with active partition: #{inspect(parts)}") - if length(local_nodes) > length(remote_nodes) do - remote_nodes - else + (length(local_nodes) > length(remote_nodes) && remote_nodes) || local_nodes - end - |> restart_nodes(state) + |> restart_nodes(state) end end, [node() | Node.list()] diff --git a/lib/redex/protocol/parser.ex b/lib/redex/protocol/parser.ex index 5279587..6d996e1 100644 --- a/lib/redex/protocol/parser.ex +++ b/lib/redex/protocol/parser.ex @@ -85,6 +85,7 @@ defmodule Redex.Protocol.Parser do |> parse_cont(len) end + # credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity defp parse_cont(state = %State{acc: acc, buffer: buffer}, len) when len < hd(acc) do case parse_string(buffer) do {:ok, [size], buffer, _, _, _} when is_integer(size) and byte_size(buffer) >= size + 2 -> diff --git a/mix.exs b/mix.exs index a0ee752..077aaf1 100644 --- a/mix.exs +++ b/mix.exs @@ -43,7 +43,8 @@ defmodule Redex.MixProject do {:mox, "~> 0.5", only: :test}, {:excoveralls, "~> 0.11.1", only: :test}, {:dialyxir, "~> 1.0.0-rc.6", only: :dev, runtime: false}, - {:stream_data, "~> 0.4", only: [:dev, :test]} + {:stream_data, "~> 0.4", only: [:dev, :test]}, + {:credo, "~> 1.1.0", only: [:dev, :test], runtime: false} ] end end diff --git a/mix.lock b/mix.lock index 94e79bd..35096ef 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,7 @@ %{ + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, + "credo": {:hex, :credo, "1.1.5", "caec7a3cadd2e58609d7ee25b3931b129e739e070539ad1a0cd7efeeb47014f4", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, "dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"}, "erlex": {:hex, :erlex, "0.2.4", "23791959df45fe8f01f388c6f7eb733cc361668cbeedd801bf491c55a029917b", [:mix], [], "hexpm"}, "excoveralls": {:hex, :excoveralls, "0.11.1", "dd677fbdd49114fdbdbf445540ec735808250d56b011077798316505064edb2c", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},