Skip to content

Commit

Permalink
Fix credo and dialyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ono committed Jul 20, 2017
1 parent 67a44d4 commit 0e1a70f
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 30 deletions.
47 changes: 34 additions & 13 deletions .credo.exs
Expand Up @@ -10,33 +10,39 @@
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# Run any exec using `mix credo -C <name>`. If no exec name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: ["lib/", "src/", "web/", "apps/"],
excluded: [~r"/_build/", ~r"/deps/"]
},
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# Credo automatically checks for updates, like e.g. Hex does.
# You can disable this behaviour below:
#
check_for_updates: true,
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
Expand All @@ -49,67 +55,65 @@
checks: [
{Credo.Check.Consistency.ExceptionNames},
{Credo.Check.Consistency.LineEndings},
{Credo.Check.Consistency.MultiAliasImportRequireUse},
{Credo.Check.Consistency.ParameterPatternMatching},
{Credo.Check.Consistency.SpaceAroundOperators},
{Credo.Check.Consistency.SpaceInParentheses},
{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, false},

# For others you can set parameters

# If you don't want the `setup` and `test` macro calls in ExUnit tests
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
#
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},

# 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},
{Credo.Check.Design.TagFIXME},

{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 160},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc},
{Credo.Check.Readability.ModuleNames},
{Credo.Check.Readability.NoParenthesesWhenZeroArity},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
{Credo.Check.Readability.ParenthesesInCondition},
{Credo.Check.Readability.PredicateFunctionNames},
{Credo.Check.Readability.PreferImplicitTry},
{Credo.Check.Readability.RedundantBlankLines},
{Credo.Check.Readability.Specs},
{Credo.Check.Readability.StringSigils},
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.VariableNames},
{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Readability.Semicolons},
{Credo.Check.Readability.SpaceAfterCommas},

# {Credo.Check.Refactor.CaseTrivialMatches}, # deprecated in 0.4.0
{Credo.Check.Refactor.ABCSize},
{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.LongQuoteBlocks},
{Credo.Check.Refactor.MatchInCondition},
{Credo.Check.Refactor.NegatedConditionsInUnless},
{Credo.Check.Refactor.NegatedConditionsWithElse},
{Credo.Check.Refactor.Nesting},
{Credo.Check.Refactor.PipeChainStart},
{Credo.Check.Refactor.UnlessWithElse},
{Credo.Check.Refactor.VariableRebinding},

{Credo.Check.Warning.BoolOperationOnSameValues},
{Credo.Check.Warning.IExPry},
{Credo.Check.Warning.IoInspect},
{Credo.Check.Warning.NameRedeclarationByAssignment},
{Credo.Check.Warning.NameRedeclarationByCase},
{Credo.Check.Warning.NameRedeclarationByDef},
{Credo.Check.Warning.NameRedeclarationByFn},
{Credo.Check.Warning.LazyLogging, false},
{Credo.Check.Warning.OperationOnSameValues},
{Credo.Check.Warning.OperationWithConstantResult},
{Credo.Check.Warning.UnusedEnumOperation},
Expand All @@ -120,6 +124,23 @@
{Credo.Check.Warning.UnusedRegexOperation},
{Credo.Check.Warning.UnusedStringOperation},
{Credo.Check.Warning.UnusedTupleOperation},
{Credo.Check.Warning.RaiseInsideRescue},

# Controversial and experimental checks (opt-in, just remove `, false`)
#
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},

# Deprecated checks (these will be deleted after a grace period)
#
{Credo.Check.Readability.Specs, false},
{Credo.Check.Warning.NameRedeclarationByAssignment, false},
{Credo.Check.Warning.NameRedeclarationByCase, false},
{Credo.Check.Warning.NameRedeclarationByDef, false},
{Credo.Check.Warning.NameRedeclarationByFn, false},

# Custom checks can be created using `mix credo.gen.check`.
#
Expand Down
5 changes: 3 additions & 2 deletions coveralls.json
@@ -1,8 +1,9 @@
{
"skip_files": [
"lib/mix/tasks"
"lib/mix/tasks",
"test"
],
"coverage_options": {
"minimum_coverage": 90
}
}
}
3 changes: 3 additions & 0 deletions dialyzer.ignore-warnings
@@ -1,2 +1,5 @@
lib/mix/tasks/analyze.ex:1: Callback info about the 'Elixir.Mix.Task' behaviour is not available
lib/mix/tasks/task_bunny.queue.reset.ex:1: Callback info about the 'Elixir.Mix.Task' behaviour is not available
:0: Unknown function 'Elixir.Mix':shell/0
:0: Unknown function 'Elixir.Mix.Task':run/1
:0: Unknown function 'Elixir.Wobserver':register/2
2 changes: 1 addition & 1 deletion lib/mix/tasks/analyze.ex
Expand Up @@ -13,7 +13,7 @@ defmodule Mix.Tasks.Analyze do
defp execute(command, options, show_output \\ false) do
commands = ["-q", "/dev/null", command]

label = "\e[1m#{command} #{Enum.join(options, " ")}\e[0m";
label = "\e[1m#{command} #{Enum.join(options, " ")}\e[0m"

" "
|> Kernel.<>(label)
Expand Down
3 changes: 2 additions & 1 deletion lib/task_bunny/consumer.ex
Expand Up @@ -9,7 +9,8 @@ defmodule TaskBunny.Consumer do
@doc """
Opens a channel and start consuming messages for the queue.
"""
@spec consume(AMQP.Connection.t, String.t, integer) :: {:ok, AMQP.Channel.t, String.t} | {:error, any}
@spec consume(AMQP.Connection.t, String.t, integer) ::
{:ok, AMQP.Channel.t, String.t} | {:error, any}
def consume(connection, queue, concurrency) do
with {:ok, channel} <- AMQP.Channel.open(connection),
:ok <- AMQP.Basic.qos(channel, prefetch_count: concurrency),
Expand Down
10 changes: 0 additions & 10 deletions lib/task_bunny/errors.ex
Expand Up @@ -4,13 +4,11 @@ defmodule TaskBunny.ConfigError do
"""
defexception [:message]

@lint false
def exception(message: message) do
title = "Failed to load TaskBunny config"
message = "#{title}\n#{message}"
%__MODULE__{message: message}
end
_ = @lint
end

defmodule TaskBunny.Connection.ConnectError do
Expand All @@ -19,7 +17,6 @@ defmodule TaskBunny.Connection.ConnectError do
"""
defexception [:type, :message]

@lint false
def exception(_opts = [type: type, host: host]) do
title = "Failed to get a connection to host '#{host}'."
detail = case type do
Expand Down Expand Up @@ -47,7 +44,6 @@ defmodule TaskBunny.Connection.ConnectError do
message = "#{title}\n#{detail}"
%__MODULE__{message: message, type: type}
end
_ = @lint
end

defmodule TaskBunny.Job.QueueNotFoundError do
Expand All @@ -56,15 +52,13 @@ defmodule TaskBunny.Job.QueueNotFoundError do
"""
defexception [:job, :message]

@lint false
def exception(job: job) do
title = "Failed to find a queue for the job."
detail = "job=#{job}"

message = "#{title}\n#{detail}"
%__MODULE__{message: message, job: job}
end
_ = @lint
end

defmodule TaskBunny.Message.DecodeError do
Expand All @@ -73,7 +67,6 @@ defmodule TaskBunny.Message.DecodeError do
"""
defexception [:message]

@lint false
def exception(opts) do
title = "Failed to decode the message."
detail = case opts[:type] do
Expand All @@ -90,7 +83,6 @@ defmodule TaskBunny.Message.DecodeError do
message = "#{title}\n#{detail}\nmessage body=#{opts[:body]}"
%__MODULE__{message: message}
end
_ = @lint
end

defmodule TaskBunny.Publisher.PublishError do
Expand All @@ -99,13 +91,11 @@ defmodule TaskBunny.Publisher.PublishError do
"""
defexception [:message, :inner_error]

@lint false
def exception(inner_error: inner_error) do
title = "Failed to publish the message."
detail = "error=#{inspect inner_error}"

message = "#{title}\n#{detail}"
%__MODULE__{message: message, inner_error: inner_error}
end
_ = @lint
end
2 changes: 1 addition & 1 deletion lib/task_bunny/initializer.ex
Expand Up @@ -71,7 +71,7 @@ defmodule TaskBunny.Initializer do
Loads config and declares queues listed
"""
@spec declare_queues_from_config() :: :ok
def declare_queues_from_config() do
def declare_queues_from_config do
Config.queues
|> Enum.each(fn (queue) -> declare_queue(queue) end)

Expand Down
7 changes: 6 additions & 1 deletion lib/task_bunny/status.ex
Expand Up @@ -15,7 +15,12 @@ defmodule TaskBunny.Status do
- `connected`, whether a connection to RabbitMQ has been made.
- `workers`, list of worker statuses.
"""
@type t :: %__MODULE__{version: String.t, up: boolean, connected: boolean, workers: list(Worker.t)}
@type t :: %__MODULE__{
version: String.t,
up: boolean,
connected: boolean,
workers: list(Worker.t)
}

defstruct version: "1", up: true, connected: false, workers: []

Expand Down
2 changes: 1 addition & 1 deletion lib/task_bunny/worker_supervisor.ex
Expand Up @@ -71,7 +71,7 @@ defmodule TaskBunny.WorkerSupervisor do
end

defp wait_for_all_jobs_done(workers, timeout) do
Enum.find_value(0..round(timeout/50), fn (_) ->
Enum.find_value(0..round(timeout / 50), fn(_) ->
if workers_running?(workers) do
:timer.sleep(50)
false
Expand Down

0 comments on commit 0e1a70f

Please sign in to comment.