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

Updated dependencies, formatting, dialyzer, credo #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
159 changes: 159 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# 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/", "test/", "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: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames},
{Credo.Check.Consistency.LineEndings},
{Credo.Check.Consistency.ParameterPatternMatching},
{Credo.Check.Consistency.SpaceAroundOperators, false},
{Credo.Check.Consistency.SpaceInParentheses},
{Credo.Check.Consistency.TabsOrSpaces},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage, false},
# 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},

#
## Readability Checks
#
{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 120},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc, false},
{Credo.Check.Readability.AliasOrder},
{Credo.Check.Readability.ModuleNames},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, false},
{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},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity, max_complexity: 10},
{Credo.Check.Refactor.FunctionArity, max_arity: 12},
{Credo.Check.Refactor.LongQuoteBlocks},
{Credo.Check.Refactor.MatchInCondition},
{Credo.Check.Refactor.NegatedConditionsInUnless},
{Credo.Check.Refactor.NegatedConditionsWithElse},
{Credo.Check.Refactor.Nesting, max_nesting: 3},
{Credo.Check.Refactor.PipeChainStart, :false},
{Credo.Check.Refactor.UnlessWithElse},

#
## Warnings
#
{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}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
4 changes: 3 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
line_length: 108,
rename_deprecated_at: "1.3.0",
inputs: [".formatter.exs", "mix.exs", "{examples, config,lib,test}/**/*.{ex,exs}"]
]
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
erlang 21.1
elixir 1.7.3-otp-21

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this project supports Elixir 1.3. Is this a generated file included by mistake?

27 changes: 16 additions & 11 deletions examples/chrome_debbuger.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule ChromeDebugger do
ChromeDebugger.start("ws://127.0.0.1:55171/devtools/page/18569def-3e03-4d67-a5b9-ca6a0ee0db77", %{port: 55171})
```
"""

def start(url, state) do
{:ok, pid} = WebSockex.start(url, __MODULE__, state)
WebSockex.send_frame(pid, {:text, Poison.encode!(%{id: 1, method: "Network.enable", params: %{}})})
Expand All @@ -19,29 +19,34 @@ defmodule ChromeDebugger do
end

def terminate(reason, state) do
IO.puts("WebSockex for remote debbugging on port #{state.port} terminating with reason: #{inspect reason}")
IO.puts(
"WebSockex for remote debbugging on port #{state.port} terminating with reason: #{inspect(reason)}"
)

exit(:normal)
end

def handle_frame({_type, msg}, state) do
case Poison.decode(msg) do
{:error, error} ->
Logger.debug(inspect msg)
Logger.error(inspect error)
Logger.debug(inspect(msg))
Logger.error(inspect(error))

{:ok, message} ->
case message["method"] do
"Network.webSocketFrameReceived" ->
with true <- message["params"]["response"]["opcode"] == 1,
message_pl <- message["params"]["response"]["payloadData"]
do
IO.puts("Message from remote-debbuging port #{state.port}: #{inspect message_pl}")
else
_ -> :ok
message_pl <- message["params"]["response"]["payloadData"] do
IO.puts("Message from remote-debbuging port #{state.port}: #{inspect(message_pl)}")
else
_ -> :ok
end
_ -> :ok

_ ->
:ok
end
end

{:ok, state}
end

end
11 changes: 7 additions & 4 deletions examples/echo_client.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule EchoClient do
WebSockex.start_link("wss://echo.websocket.org/?encoding=text", __MODULE__, :fake_state, opts)
end

@spec echo(pid, String.t) :: :ok
@spec echo(pid, String.t()) :: :ok
def echo(client, message) do
Logger.info("Sending message: #{message}")
WebSockex.send_frame(client, {:text, message})
Expand All @@ -23,19 +23,22 @@ defmodule EchoClient do
Logger.info("Sending message: #{msg}")
{:reply, {:text, msg}, :fake_state}
end

def handle_frame({:text, "Close the things!" = msg}, :fake_state) do
Logger.info("Received Message: #{msg}")
{:close, :fake_state}
end

def handle_frame({:text, msg}, :fake_state) do
Logger.info("Received Message: #{msg}")
{:ok, :fake_state}
end

def handle_disconnect(%{reason: {:local, reason}}, state) do
Logger.info("Local close with reason: #{inspect reason}")
Logger.info("Local close with reason: #{inspect(reason)}")
{:ok, state}
end

def handle_disconnect(disconnect_map, state) do
super(disconnect_map, state)
end
Expand All @@ -47,8 +50,8 @@ EchoClient.echo(pid, "Yo Homies!")
EchoClient.echo(pid, "This and That!")
EchoClient.echo(pid, "Can you please reply yourself?")

Process.sleep 1000
Process.sleep(1000)

EchoClient.echo(pid, "Close the things!")

Process.sleep 1500
Process.sleep(1500)
Loading