Skip to content

Commit

Permalink
add credo check to travis config (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 authored and scrogson committed Jan 8, 2018
1 parent 6d396da commit 9092cb3
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 5 deletions.
146 changes: 146 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# 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 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: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: false,
#
# 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
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
{Credo.Check.Consistency.ExceptionNames},
{Credo.Check.Consistency.LineEndings},
{Credo.Check.Consistency.ParameterPatternMatching},
{Credo.Check.Consistency.SpaceAroundOperators},
{Credo.Check.Consistency.SpaceInParentheses},
{Credo.Check.Consistency.TabsOrSpaces},

# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage, priority: :low},

# For some checks, you can also set other 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: 80},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc},
{Credo.Check.Readability.ModuleNames},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
{Credo.Check.Readability.ParenthesesInCondition},
{Credo.Check.Readability.PredicateFunctionNames},
{Credo.Check.Readability.PreferImplicitTry},
{Credo.Check.Readability.RedundantBlankLines},
{Credo.Check.Readability.StringSigils},
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.VariableNames},
{Credo.Check.Readability.Semicolons},
{Credo.Check.Readability.SpaceAfterCommas},

{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity, false},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.LongQuoteBlocks, false},
{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.Warning.BoolOperationOnSameValues},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck},
{Credo.Check.Warning.IExPry},
{Credo.Check.Warning.IoInspect},
{Credo.Check.Warning.LazyLogging},
{Credo.Check.Warning.OperationOnSameValues},
{Credo.Check.Warning.OperationWithConstantResult},
{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},
{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`.
#
]
}
]
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ matrix:
sudo: false
after_script:
- MIX_ENV=test mix coveralls.travis
- mix credo
3 changes: 2 additions & 1 deletion lib/hedwig/adapters/console/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ defmodule Hedwig.Adapters.Console.Connection do
end

defp get_system_user do
System.cmd("whoami", [])
"whoami"
|> System.cmd([])
|> elem(0)
|> String.trim()
end
Expand Down
2 changes: 2 additions & 0 deletions lib/hedwig/responder/supervisor.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Hedwig.Responder.Supervisor do
@moduledoc false

def start_link do
import Supervisor.Spec, warn: false

Expand Down
1 change: 1 addition & 0 deletions lib/hedwig/test/robot_case.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Hedwig.RobotCase do
use ExUnit.CaseTemplate

@moduledoc false
@robot Hedwig.TestRobot
@default_responders [{Hedwig.Responders.Help, []}, {TestResponder, []}]

Expand Down
2 changes: 2 additions & 0 deletions lib/hedwig/test/test_robot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Code.ensure_compiled(Hedwig.Adapters.Test)
defmodule Hedwig.TestRobot do
use Hedwig.Robot, otp_app: :hedwig, adapter: Hedwig.Adapters.Test

@moduledoc false

def handle_connect(%{name: name} = state) do
if :undefined == :global.whereis_name(name) do
:yes = :global.register_name(name, self())
Expand Down
11 changes: 9 additions & 2 deletions lib/mix/tasks/hedwig.gen.robot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ defmodule Mix.Tasks.Hedwig.Gen.Robot do
end

defp default_robot(app) do
app
|> alias_module
|> Module.concat(Robot)
end

defp alias_module(app) do
case Application.get_env(app, :app_namespace, app) do
^app -> app |> to_string |> Macro.camelize
mod -> mod |> inspect
end |> Module.concat(Robot)
end
end

defp available_adapters(deps) do
Expand Down Expand Up @@ -136,7 +142,8 @@ defmodule Mix.Tasks.Hedwig.Gen.Robot do
end

defp prompt_for_name do
Mix.shell.prompt("What would you like to name your bot?:")
"What would you like to name your bot?:"
|> Mix.shell.prompt
|> String.trim
end

Expand Down
4 changes: 3 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ defmodule Hedwig.Mixfile do

defp deps do
[{:excoveralls, "~> 0.7.2", only: :test},
{:ex_doc, "~> 0.16.3", only: :dev}]
{:ex_doc, "~> 0.16.3", only: :dev},
{:credo, "~> 0.8", only: [:dev, :test], runtime: false}
]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
Expand Down
4 changes: 3 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%{"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm"},
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [], [], "hexpm"},
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm"},
"credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.7.2", "f69ede8c122ccd3b60afc775348a53fc8c39fe4278aee2f538f0d81cc5e7ff3a", [:mix], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
Expand Down

0 comments on commit 9092cb3

Please sign in to comment.