Skip to content
Open
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
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`.
#
]
}
]
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ erl_crash.dump
/mnesia
/log
/test/tmp
/cover
/cover
23 changes: 19 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
language: elixir
elixir:
- 1.3.3
otp_release:
- 19.1
matrix:
include:
- otp_release: 18.3
elixir: 1.3
- otp_release: 19.3
elixir: 1.3
- otp_release: 18.3
elixir: 1.4
- otp_release: 19.3
elixir: 1.4
- otp_release: 20.2
elixir: 1.4
- otp_release: 19.3
elixir: 1.5
- otp_release: 20.2
elixir: 1.5
- otp_release: 20.2
elixir: 1.6
sudo: false
after_script:
- MIX_ENV=test mix coveralls.travis
- mix credo
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.0.1 (2018-01-26)

- Clean up warnings

## v1.0.0 (2016-11-20)

- Improvements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pid = :global.whereis_name("alfred")
# Create a Hedwig message
msg = %Hedwig.Message{
type: "groupchat",
room: "my_room@example.com"
room: "my_room@example.com",
text: "hello world"
}

Expand Down
12 changes: 5 additions & 7 deletions lib/hedwig/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ defmodule Hedwig.Adapter do

An adapter is the interface to the service your bot runs on. To implement an
adapter you will need to translate messages from the service to the
`Hedwig.Message` struct and call `Hedwig.Robot.handle_message(robot, msg)`.
`Hedwig.Message` struct and call `Hedwig.Robot.handle_in(robot, msg)`.
"""

use Behaviour

@doc false
defmacro __using__(_opts) do
quote do
Expand Down Expand Up @@ -57,15 +55,15 @@ defmodule Hedwig.Adapter do

@doc false
def start_link(module, opts) do
GenServer.start_link(module, {self, opts})
GenServer.start_link(module, {self(), opts})
end

@type robot :: pid
@type state :: term
@type opts :: any
@type msg :: Hedwig.Message.t

defcallback send(pid, msg) :: term
defcallback reply(pid, msg) :: term
defcallback emote(pid, msg) :: term
@callback send(pid, msg) :: term
@callback reply(pid, msg) :: term
@callback emote(pid, msg) :: term
end
5 changes: 3 additions & 2 deletions lib/hedwig/adapters/console/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ defmodule Hedwig.Adapters.Console.Connection do
end

defp get_system_user do
System.cmd("whoami", [])
"whoami"
|> System.cmd([])
|> elem(0)
|> String.strip()
|> String.trim()
end
end
2 changes: 1 addition & 1 deletion lib/hedwig/adapters/console/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Hedwig.Adapters.Console.Reader do
end

def handle_info(text, {owner, user}) when is_binary(text) do
Kernel.send(owner, {:message, String.strip(text)})
Kernel.send(owner, {:message, String.trim(text)})
Process.sleep(200)
GenServer.cast(self(), :get_io)

Expand Down
2 changes: 1 addition & 1 deletion lib/hedwig/adapters/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Hedwig.Adapters.Test do
use Hedwig.Adapter

def init({robot, opts}) do
GenServer.cast(self, :after_init)
GenServer.cast(self(), :after_init)
{:ok, %{conn: nil, opts: opts, robot: robot}}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hedwig/responder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ defmodule Hedwig.Responder do
@doc false
def usage(name) do
import String
Enum.map(@usage, &(&1 |> strip |> replace("hedwig", name)))
Enum.map(@usage, &(&1 |> trim |> replace("hedwig", name)))
end

def init({aka, name, opts, robot}) do
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
21 changes: 14 additions & 7 deletions lib/mix/tasks/hedwig.gen.robot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ defmodule Mix.Tasks.Hedwig.Gen.Robot do
"""]

aka = opts[:aka] || "/"
name = opts[:name] || prompt_for_name
name = opts[:name] || prompt_for_name()
robot = opts[:robot] || default_robot(app)
adapter = get_adapter_module(deps)

underscored = Mix.Utils.underscore(robot)
underscored = Macro.underscore(robot)
file = Path.join("lib", underscored) <> ".ex"

robot = Module.concat([robot])
Expand Down Expand Up @@ -78,16 +78,22 @@ 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 |> Mix.Utils.camelize
^app -> app |> to_string |> Macro.camelize
mod -> mod |> inspect
end |> Module.concat(Robot)
end
end

defp available_adapters(deps) do
deps
|> all_modules
|> Kernel.++(hedwig_modules)
|> Kernel.++(hedwig_modules())
|> Enum.uniq
|> Enum.filter(&implements_adapter?/1)
|> Enum.with_index
Expand Down Expand Up @@ -136,8 +142,9 @@ defmodule Mix.Tasks.Hedwig.Gen.Robot do
end

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

defp prompt_for_adapter(adapters) do
Expand Down
Loading