Skip to content

Commit

Permalink
feat: add credo
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Apr 2, 2019
1 parent 673016e commit a8a66c6
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 113 deletions.
87 changes: 87 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
%{
configs: [
%{
name: "default",
files: %{
included: ["lib/rest"],
excluded: ["lib/rest/gen"]
},
requires: [],
checks: [
# Consistency
{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},
# Design
{Credo.Check.Design.AliasUsage},
{Credo.Check.Design.DuplicatedCode},
{Credo.Check.Design.TagFIXME},
{Credo.Check.Design.TagTODO, exit_status: 0},
# Readability
{Credo.Check.Readability.AliasOrder},
{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc},
{Credo.Check.Readability.ModuleNames},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, false},
{Credo.Check.Readability.PredicateFunctionNames},
{Credo.Check.Readability.PreferImplicitTry, false},
{Credo.Check.Readability.PreferUnquotedAtoms},
{Credo.Check.Readability.RedundantBlankLines},
{Credo.Check.Readability.Semicolons},
{Credo.Check.Readability.SinglePipe},
{Credo.Check.Readability.SpaceAfterCommas},
{Credo.Check.Readability.Specs},
{Credo.Check.Readability.StringSigils},
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.UnnecessaryAliasExpansion},
{Credo.Check.Readability.VariableNames},
# Refactor
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem},
{Credo.Check.Refactor.CaseTrivialMatches},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity},
{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.LongQuoteBlocks, false},
{Credo.Check.Refactor.MapInto},
{Credo.Check.Refactor.MatchInCondition},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.NegatedConditionsInUnless},
{Credo.Check.Refactor.NegatedConditionsWithElse},
{Credo.Check.Refactor.Nesting},
{Credo.Check.Refactor.PerceivedComplexity},
{Credo.Check.Refactor.PipeChainStart},
{Credo.Check.Refactor.UnlessWithElse},
{Credo.Check.Refactor.VariableRebinding, false},
# Warning
{Credo.Check.Warning.BoolOperationOnSameValues},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck},
{Credo.Check.Warning.IExPry},
{Credo.Check.Warning.IoInspect},
{Credo.Check.Warning.LazyLogging},
{Credo.Check.Warning.MapGetUnsafePass},
{Credo.Check.Warning.OperationOnSameValues},
{Credo.Check.Warning.OperationWithConstantResult},
{Credo.Check.Warning.RaiseInsideRescue},
{Credo.Check.Warning.UnsafeToAtom, false},
{Credo.Check.Warning.UnusedEnumOperation},
{Credo.Check.Warning.UnusedFileOperation},
{Credo.Check.Warning.UnusedKeywordOperation},
{Credo.Check.Warning.UnusedListOperation},
{Credo.Check.Warning.UnusedPathOperation},
{Credo.Check.Warning.UnusedRegexOperation},
{Credo.Check.Warning.UnusedStringOperation},
{Credo.Check.Warning.UnusedTupleOperation}
]
}
]
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ matrix:
otp_release: '21.0.8'
script:
- mix format --check-formatted
- mix credo --strict
- mix test

- language: elixir
Expand Down
16 changes: 15 additions & 1 deletion lib/rest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1435,11 +1435,17 @@ defmodule Crux.Rest do
"""
Version.since("0.2.0")

@callback execute_webhook(
webhook :: Webhook.t(),
data :: Crux.Rest.execute_webhook_options()
) :: :ok
Version.since("0.2.0")

@callback execute_webhook(
webhook :: Webhook.t(),
wait :: boolean() | nil,
data :: Crux.Rest.execute_webhook_options()
) :: :ok | {:ok, Message.t()} | {:error, term}
) :: :ok | {:ok, Message.t()} | {:error, term()}
Version.since("0.2.0")

@callback execute_webhook(
Expand All @@ -1458,6 +1464,9 @@ defmodule Crux.Rest do
"""
Version.since("0.2.0")

@callback execute_slack_webhook(webhook :: Webhook.t(), data :: term()) :: :ok
Version.since("0.2.0")

@callback execute_slack_webhook(
webhook :: Webhook.t(),
wait :: boolean() | nil,
Expand All @@ -1483,6 +1492,11 @@ defmodule Crux.Rest do
"""
Version.since("0.2.0")

@callback execute_github_webhook(webhook :: Webhook.t(), event :: String.t(), data :: term()) ::
:ok

Version.since("0.2.0")

@callback execute_github_webhook(
webhook :: Webhook.t(),
event :: String.t(),
Expand Down
14 changes: 8 additions & 6 deletions lib/rest/api_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ defmodule Crux.Rest.ApiError do

defp map_inner(error, key) when is_map(error) do
Enum.map_join(error, "\n", fn {k, v} ->
cond do
key && Regex.match?(~r/\d+/, k) -> "#{key}[#{k}]"
key -> "#{key}.#{k}"
true -> k
end
|> transform_value(v)
new_k =
cond do
key && Regex.match?(~r/\d+/, k) -> "#{key}[#{k}]"
key -> "#{key}.#{k}"
true -> k
end

transform_value(new_k, v)
end)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rest/cdn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ defmodule Crux.Rest.CDN do
def default_user_avatar(user)

def default_user_avatar(%{discriminator: discrim}) do
user_discriminator = String.to_integer(discrim) |> rem(5)
user_discriminator = discrim |> String.to_integer() |> rem(5)
"#{@base_url}/embed/avatars/#{user_discriminator}.png"
end

Expand Down
Loading

0 comments on commit a8a66c6

Please sign in to comment.