Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add credo #90

Merged
merged 4 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
86 changes: 86 additions & 0 deletions config/.credo.exs
Original file line number Diff line number Diff line change
@@ -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 <name>`. 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}
]
}
]
}
2 changes: 2 additions & 0 deletions lib/verk_web.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule VerkWeb do
@moduledoc false

use Application

@doc false
Expand Down
2 changes: 2 additions & 0 deletions lib/verk_web/mount.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/verk_web/mount_route.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/verk_web/plug/mount.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule VerkWeb.Plug.Mount do
@moduledoc false

import Plug.Conn

def init(default), do: default
Expand Down
6 changes: 5 additions & 1 deletion lib/verk_web/range_paginator.ex
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions lib/verk_web/tracking_jobs_handler.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule VerkWeb.TrackingJobsHandler do
@moduledoc """
Responsible for tracking jobs.
"""

@broadcast_interval 1_000

use GenStage
Expand Down
4 changes: 4 additions & 0 deletions lib/verk_web/tracking_queues_handler.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule VerkWeb.TrackingQueuesHandler do
@moduledoc """
Responsible for tracking queues.
"""

use GenStage

def start_link(pid) do
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
%{
"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"},
"coverex": {:hex, :coverex, "1.5.0", "a4248302f09562993041f1b056866bfd5688d3a03c429de80c47ea6663989ecc", [:mix], [{:hackney, "~> 1.5", [hex: :hackney, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 3.1 or ~> 4.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "21a8f6e734a277b86c01b3cc44b7cc8b77cb1886adbebb708eefc6398567dcac"},
"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"},
Expand Down
2 changes: 2 additions & 0 deletions web/channels/room_channel.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule VerkWeb.RoomChannel do
@moduledoc false

use Phoenix.Channel
alias VerkWeb.TrackingJobsHandler
alias VerkWeb.TrackingQueuesHandler
Expand Down
2 changes: 1 addition & 1 deletion web/controllers/scheduled_controller.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule VerkWeb.ScheduledController do
use VerkWeb.Web, :controller
alias Verk.{SortedSet, Redis}
alias Verk.{Redis, SortedSet}

@schedule_key "schedule"

Expand Down
2 changes: 2 additions & 0 deletions web/views/helpers/queues_helpers.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule VerkWeb.Queue.Helpers do
@moduledoc false

import Phoenix.HTML.Link
import VerkWeb.Router.Helpers

Expand Down
3 changes: 2 additions & 1 deletion web/views/job_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions web/views/page_view.ex
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion web/views/queues_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down