diff --git a/.travis.yml b/.travis.yml index 89cf84f..24c3918 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ otp_release: script: - if [[ `elixir -v` = *"1.11"* ]]; then mix format --check-formatted; fi - MIX_ENV=test mix test --trace --cover + - MIX_ENV=test mix credo --strict services: - redis-server sudo: false diff --git a/config/.credo.exs b/config/.credo.exs new file mode 100644 index 0000000..e4c8eae --- /dev/null +++ b/config/.credo.exs @@ -0,0 +1,86 @@ +# This file contains the configuration for Credo. +# +# 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: [ + %{ + # + # Run any config using `mix credo -C `. If no config 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: [] + }, + # + # The `checks:` field contains all the checks that are run. You can + # customize the parameters of any given check by adding a second element + # to the tuple. + # + # There are two ways of deactivating a check: + # 1. deleting the check from this list + # 2. putting `false` as second element (to quickly "comment it out"): + # + # {Credo.Check.Consistency.ExceptionNames, false} + # + checks: [ + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, false}, + {Credo.Check.Warning.LazyLogging, false}, + {Credo.Check.Consistency.ExceptionNames}, + {Credo.Check.Consistency.LineEndings}, + {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 + {Credo.Check.Design.DuplicatedCode, mass_threshold: 16, nodes_threshold: 2}, + + # 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.MaxLineLength, priority: :low, max_length: 120}, + {Credo.Check.Readability.ModuleAttributeNames}, + {Credo.Check.Readability.ModuleDoc}, + {Credo.Check.Readability.ModuleNames}, + {Credo.Check.Readability.PredicateFunctionNames}, + {Credo.Check.Readability.TrailingBlankLine}, + {Credo.Check.Readability.TrailingWhiteSpace}, + {Credo.Check.Readability.VariableNames}, + {Credo.Check.Refactor.ABCSize}, + {Credo.Check.Refactor.CaseTrivialMatches}, + {Credo.Check.Refactor.CondStatements}, + {Credo.Check.Refactor.FunctionArity, ignore_defp: true}, + {Credo.Check.Refactor.MatchInCondition}, + {Credo.Check.Refactor.PipeChainStart}, + {Credo.Check.Refactor.CyclomaticComplexity}, + {Credo.Check.Refactor.NegatedConditionsInUnless}, + {Credo.Check.Refactor.NegatedConditionsWithElse}, + {Credo.Check.Refactor.Nesting}, + {Credo.Check.Refactor.UnlessWithElse}, + {Credo.Check.Warning.IExPry}, + {Credo.Check.Warning.IoInspect}, + {Credo.Check.Warning.OperationOnSameValues}, + {Credo.Check.Warning.UnusedEnumOperation}, + {Credo.Check.Warning.UnusedKeywordOperation}, + {Credo.Check.Warning.UnusedListOperation}, + {Credo.Check.Warning.UnusedStringOperation}, + {Credo.Check.Warning.UnusedTupleOperation}, + {Credo.Check.Warning.OperationWithConstantResult} + ] + } + ] +} diff --git a/lib/verk_web.ex b/lib/verk_web.ex index 0888eaa..6e5686d 100644 --- a/lib/verk_web.ex +++ b/lib/verk_web.ex @@ -1,4 +1,6 @@ defmodule VerkWeb do + @moduledoc false + use Application @doc false diff --git a/lib/verk_web/mount.ex b/lib/verk_web/mount.ex index f7a8fbb..b20e8bb 100644 --- a/lib/verk_web/mount.ex +++ b/lib/verk_web/mount.ex @@ -1,4 +1,6 @@ defmodule VerkWeb.Mount do + @moduledoc false + defmacro __using__(path: path) do quote bind_quoted: [path: path] do path = if String.starts_with?(path, "/"), do: path, else: "/" <> path diff --git a/lib/verk_web/mount_route.ex b/lib/verk_web/mount_route.ex index 010f981..a851924 100644 --- a/lib/verk_web/mount_route.ex +++ b/lib/verk_web/mount_route.ex @@ -1,4 +1,6 @@ defmodule VerkWeb.MountRoute do + @moduledoc false + defmacro __using__(path: path) do quote bind_quoted: [path: path] do path = if String.starts_with?(path, "/"), do: path, else: "/" <> path diff --git a/lib/verk_web/plug/mount.ex b/lib/verk_web/plug/mount.ex index 988b9dd..2521058 100644 --- a/lib/verk_web/plug/mount.ex +++ b/lib/verk_web/plug/mount.ex @@ -1,4 +1,6 @@ defmodule VerkWeb.Plug.Mount do + @moduledoc false + import Plug.Conn def init(default), do: default diff --git a/lib/verk_web/range_paginator.ex b/lib/verk_web/range_paginator.ex index beab197..32d30e1 100644 --- a/lib/verk_web/range_paginator.ex +++ b/lib/verk_web/range_paginator.ex @@ -1,4 +1,8 @@ defmodule VerkWeb.RangePaginator do + @moduledoc """ + Range paginator for the pages. + """ + defstruct [:page, :per_page, :from, :to, :has_next, :has_prev] def new(total_entries, page \\ 1, per_page \\ 20) do @@ -22,5 +26,5 @@ defmodule VerkWeb.RangePaginator do defp to_int(nil, default), do: default defp to_int(page, _) when is_integer(page), do: page - defp to_int(page, _), do: Integer.parse(page) |> elem(0) + defp to_int(page, _), do: page |> Integer.parse() |> elem(0) end diff --git a/lib/verk_web/tracking_jobs_handler.ex b/lib/verk_web/tracking_jobs_handler.ex index 2d3056a..3d7b5e7 100644 --- a/lib/verk_web/tracking_jobs_handler.ex +++ b/lib/verk_web/tracking_jobs_handler.ex @@ -1,4 +1,8 @@ defmodule VerkWeb.TrackingJobsHandler do + @moduledoc """ + Responsible for tracking jobs. + """ + @broadcast_interval 1_000 use GenStage diff --git a/lib/verk_web/tracking_queues_handler.ex b/lib/verk_web/tracking_queues_handler.ex index f23e964..837c940 100644 --- a/lib/verk_web/tracking_queues_handler.ex +++ b/lib/verk_web/tracking_queues_handler.ex @@ -1,4 +1,8 @@ defmodule VerkWeb.TrackingQueuesHandler do + @moduledoc """ + Responsible for tracking queues. + """ + use GenStage def start_link(pid) do diff --git a/mix.exs b/mix.exs index 342fdad..55f3211 100644 --- a/mix.exs +++ b/mix.exs @@ -47,7 +47,8 @@ defmodule VerkWeb.Mixfile do {:coverex, "~> 1.4", only: :test}, {:meck, "~> 0.8", only: :test}, {:timex, "~> 3.3.0"}, - {:jason, "~> 1.1"} + {:jason, "~> 1.1"}, + {:credo, "~> 1.5", only: [:dev, :test], runtime: false} ] end diff --git a/mix.lock b/mix.lock index 89e8900..af0ca96 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,6 @@ %{ "basic_auth": {:hex, :basic_auth, "2.2.5", "ec2c934e4943b63cfc7d6b01c6f3fa51ade2a518ca36c9c0caee18a90bf98c4e", [:mix], [{:plug, "~> 0.14 or ~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "8b5f067bcfe48d7dc02d43c18ad9e9b54e630c2da720667ac8ed46979b54b7cb"}, + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "confex": {:hex, :confex, "3.4.0", "8b1c3cc7a93320291abb31223a178df19d7f722ee816c05a8070c8c9a054560d", [:mix], [], "hexpm", "4a14e15185c772389979cf4c050ddcc7a25a4d62759da13a170e0ca7274a22c7"}, @@ -7,6 +8,7 @@ "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"}, "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, + "credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"}, "earmark": {:hex, :earmark, "1.4.10", "bddce5e8ea37712a5bfb01541be8ba57d3b171d3fa4f80a0be9bcf1db417bcaf", [:mix], [{:earmark_parser, ">= 1.4.10", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "12dbfa80810478e521d3ffb941ad9fbfcbbd7debe94e1341b4c4a1b2411c1c27"}, "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, "ex_doc": {:hex, :ex_doc, "0.22.6", "0fb1e09a3e8b69af0ae94c8b4e4df36995d8c88d5ec7dbd35617929144b62c00", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "1e0aceda15faf71f1b0983165e6e7313be628a460e22a031e32913b98edbd638"}, diff --git a/web/channels/room_channel.ex b/web/channels/room_channel.ex index 97e1054..2e41178 100644 --- a/web/channels/room_channel.ex +++ b/web/channels/room_channel.ex @@ -1,4 +1,6 @@ defmodule VerkWeb.RoomChannel do + @moduledoc false + use Phoenix.Channel alias VerkWeb.TrackingJobsHandler alias VerkWeb.TrackingQueuesHandler diff --git a/web/controllers/scheduled_controller.ex b/web/controllers/scheduled_controller.ex index daedf18..e69e9af 100644 --- a/web/controllers/scheduled_controller.ex +++ b/web/controllers/scheduled_controller.ex @@ -1,6 +1,6 @@ defmodule VerkWeb.ScheduledController do use VerkWeb.Web, :controller - alias Verk.{SortedSet, Redis} + alias Verk.{Redis, SortedSet} @schedule_key "schedule" diff --git a/web/views/helpers/queues_helpers.ex b/web/views/helpers/queues_helpers.ex index 9ab9f03..ddd5cd5 100644 --- a/web/views/helpers/queues_helpers.ex +++ b/web/views/helpers/queues_helpers.ex @@ -1,4 +1,6 @@ defmodule VerkWeb.Queue.Helpers do + @moduledoc false + import Phoenix.HTML.Link import VerkWeb.Router.Helpers diff --git a/web/views/job_view.ex b/web/views/job_view.ex index 6972362..d9275ff 100644 --- a/web/views/job_view.ex +++ b/web/views/job_view.ex @@ -6,7 +6,8 @@ defmodule VerkWeb.JobView do end def current_stacktrace(process_info) do - info(process_info, :current_stacktrace) + process_info + |> info(:current_stacktrace) |> Exception.format_stacktrace() |> Phoenix.HTML.Format.text_to_html() end diff --git a/web/views/page_view.ex b/web/views/page_view.ex index 02bd62b..ef6682a 100644 --- a/web/views/page_view.ex +++ b/web/views/page_view.ex @@ -1,13 +1,6 @@ defmodule VerkWeb.PageView do use VerkWeb.Web, :view - def stats(queues_stats) do - Enum.map(queues_stats, fn queue_stats -> - Map.put(queue_stats, :enqueued_counter, Verk.Queue.count!(queue_stats.queue)) - |> Map.merge(Verk.Stats.queue_total(queue_stats.queue)) - end) - end - def total_processed do Verk.Stats.total().processed end @@ -26,7 +19,7 @@ defmodule VerkWeb.PageView do def uptime do {time, _} = :erlang.statistics(:wall_clock) - Timex.Duration.from_milliseconds(time) |> Timex.format_duration(:humanized) + time |> Timex.Duration.from_milliseconds() |> Timex.format_duration(:humanized) end def process_count, do: :erlang.system_info(:process_count) diff --git a/web/views/queues_view.ex b/web/views/queues_view.ex index 40103cb..ee0fe5e 100644 --- a/web/views/queues_view.ex +++ b/web/views/queues_view.ex @@ -3,7 +3,8 @@ defmodule VerkWeb.QueuesView do def stats(queues_stats) do Enum.map(queues_stats, fn queue_stats -> - Map.put(queue_stats, :enqueued_counter, Verk.Queue.count!(queue_stats.queue)) + queue_stats + |> Map.put(:enqueued_counter, Verk.Queue.count!(queue_stats.queue)) |> Map.merge(Verk.Stats.queue_total(queue_stats.queue)) end) end