dialyzer works, but im missing some config or something for deps

pull/259/head
connor rigby 2017-03-02 07:22:00 -08:00
parent 97eddebd65
commit 6c82520c50
14 changed files with 45 additions and 91 deletions

View File

@ -3,15 +3,6 @@ defmodule Farmbot.Token do
@moduledoc """
The unencoded version of the token.
"""
@enforce_keys [:bot,
:exp,
:fw_update_server,
:os_update_server,
:iat,
:iss,
:jti,
:mqtt,
:sub]
@type t :: %__MODULE__{
# Github apis for bot and fw updates.
fw_update_server: String.t,
@ -45,7 +36,6 @@ defmodule Farmbot.Token do
@moduledoc """
Token Object
"""
@enforce_keys [:encoded, :unencoded]
defstruct [:encoded, :unencoded]
@type t :: %__MODULE__{
encoded: binary,
@ -55,8 +45,7 @@ defmodule Farmbot.Token do
@doc """
Creates a valid token from json.
"""
@spec create(map | {:ok, map}) :: t | :not_valid
def create({:ok, token}), do: create(token)
@spec create(map | {:ok, map}) :: {:ok, t} | :not_valid
def create(%{"encoded" => encoded,
"unencoded" =>
%{"bot" => bot,

View File

@ -12,7 +12,6 @@ defmodule Farmbot.BotState.ProcessSupervisor do
@spec start_link :: {:ok, pid}
def start_link, do: Supervisor.start_link(__MODULE__, [], name: __MODULE__)
@spec init([]) :: {:ok, pid}
def init([]) do
Logger.info ">> Starting FarmProcess Supervisor"
children = [

View File

@ -10,9 +10,9 @@ defmodule Farmbot.Logger do
use GenEvent
require Logger
@type state :: {[log_message], posting?}
# @type state :: {[log_message], posting?}
@spec init(any) :: {:ok, state}
# @spec init(any) :: {:ok, state}
def init(_), do: {:ok, build_state()}
# ten megs. i promise
@ -74,7 +74,6 @@ defmodule Farmbot.Logger do
def handle_call(_, state), do: {:ok, :unhandled, state}
def handle_info(_, state), do: dispatch state
@spec terminate(any, state) :: no_return
def terminate(_,_) do
# if this backend crashes just pop it out of the logger backends.
# if we don't do this it bacomes a huge mess because of Logger
@ -86,7 +85,7 @@ defmodule Farmbot.Logger do
Logger.remove_backend(__MODULE__)
end
@spec emit(map) :: :ok
# @spec emit(map) :: no_return
defp emit(msg), do: Farmbot.Transport.log(msg)
# IF we are already posting messages to the api, no need to check the count.
@ -106,7 +105,7 @@ defmodule Farmbot.Logger do
end
# Posts an array of logs to the API.
@spec do_post([log_message],pid) :: :ok
# @spec do_post([log_message], pid) :: :ok
defp do_post(m, _pid) do
{messages, _} = Enum.partition(m, fn(message) ->
case Poison.encode(message) do
@ -119,7 +118,7 @@ defmodule Farmbot.Logger do
# Parses what the api sends back. Will only ever return :ok even if there was
# an error.
@spec parse_resp(any) :: :ok
# @spec parse_resp(any) :: :ok
defp parse_resp({:ok, %HTTPoison.Response{status_code: 200}}),
do: GenEvent.call(Elixir.Logger, Farmbot.Logger, :post_success)
@ -128,32 +127,32 @@ defmodule Farmbot.Logger do
GenEvent.call(Elixir.Logger, Farmbot.Logger, {:post_fail, error})
end
@type rpc_log_type
:: :success
| :busy
| :warn
| :error
| :info
| :fun
@type logger_level
:: :info
| :debug
| :warn
| :error
@type channels :: :toast
@type meta :: [] | [type: rpc_log_type]
@type log_message
:: %{message: String.t,
channels: channels,
created_at: integer,
meta: %{
type: rpc_log_type,
x: integer,
y: integer,
z: integer}}
# @type rpc_log_type
# :: :success
# | :busy
# | :warn
# | :error
# | :info
# | :fun
#
# @type logger_level
# :: :info
# | :debug
# | :warn
# | :error
#
# @type channels :: :toast
#
# @type meta :: [] | [type: rpc_log_type]
# @type log_message
# :: %{message: String.t,
# channels: channels,
# created_at: integer,
# meta: %{
# type: rpc_log_type,
# x: integer,
# y: integer,
# z: integer}}
# Translates Logger levels into Farmbot levels.
# :info -> :info
@ -164,7 +163,7 @@ defmodule Farmbot.Logger do
# Also takes some meta.
# Meta should take priority over
# Logger Levels.
@spec parse_type(logger_level, meta) :: rpc_log_type
# @spec parse_type(logger_level, meta) :: rpc_log_type
defp parse_type(:debug, []), do: :info
defp parse_type(level, []), do: level
defp parse_type(_level, [type: type]), do: type
@ -173,7 +172,7 @@ defmodule Farmbot.Logger do
defp parse_channels([channels: channels]), do: channels
defp parse_channels(_), do: []
@spec sanitize(binary, [any]) :: {:ok, String.t} | nil
# @spec sanitize(binary, [any]) :: {:ok, String.t} | nil
defp sanitize(message, meta) do
m = Keyword.take(meta, [:module])
if !meta[:nopub] do
@ -231,8 +230,8 @@ defmodule Farmbot.Logger do
end
defp parse_created_at(_), do: nil
@spec build_log(String.t, number, rpc_log_type, [channels], [integer])
:: {:ok, log_message}
# @spec build_log(String.t, number, rpc_log_type, [channels], [integer])
# :: {:ok, log_message}
defp build_log(message, created_at, type, channels, [x,y,z]) do
a =
%{message: message,
@ -246,7 +245,7 @@ defmodule Farmbot.Logger do
{:ok, a}
end
@type posting? :: boolean
@spec build_state :: state
# @type posting? :: boolean
# @spec build_state :: state
defp build_state, do: {[], false}
end

View File

@ -21,7 +21,7 @@ defmodule Sequence.Supervisor do
"""
def start_link, do: GenServer.start_link(__MODULE__, [], name: __MODULE__)
@spec init([]) :: {:ok, state}
# @spec init([]) :: {:ok, state}
def init([]) do
Process.flag(:trap_exit, true)
{:ok, %{q: :queue.new(), blocks: [], running: nil}}

View File

@ -3,7 +3,6 @@ defmodule Farmbot.Serial.Supervisor do
use Supervisor
require Logger
@spec init([]) :: {:ok, pid}
def init([]) do
children = [worker(Farmbot.Serial.Handler, [], restart: :permanent)]
supervise(children, strategy: :one_for_one)
@ -12,7 +11,6 @@ defmodule Farmbot.Serial.Supervisor do
@doc """
Start the serial supervisor
"""
@spec start_link :: {:ok, pid}
def start_link do
Logger.info(">> is starting serial services")
Supervisor.start_link(__MODULE__, [], name: __MODULE__)

View File

@ -13,14 +13,10 @@ defmodule Farmbot.System.FS.ConfigStorage do
defp default_config_file,
do: "#{:code.priv_dir(:farmbot)}/configs/#{@default_config_file_name}"
@type args :: binary
@spec start_link(args) :: {:ok, pid}
def start_link, do: start_link([])
def start_link(_args) do
def start_link do
GenServer.start_link(__MODULE__, @config_file, name: __MODULE__)
end
@spec init(args) :: {:ok, map}
def init(path) do
Logger.info ">> Config Storage init!"
# Checks if the json file exists or not
@ -133,6 +129,6 @@ defmodule Farmbot.System.FS.ConfigStorage do
end
# tries to parse contents. raises an exception if it can't
@spec parse_json!(args) :: map
@spec parse_json!(binary) :: map
defp parse_json!(contents), do: contents |> Poison.decode!
end

View File

@ -15,18 +15,15 @@ defmodule Farmbot.System.FS.Worker do
require Logger
use GenStage
@spec start_link(binary) :: {:ok, pid}
def start_link(target) do
GenStage.start_link(__MODULE__, target, name: __MODULE__)
end
@spec init(binary) :: {:consumer, binary, subscribe_to: [Farmbot.System.FS]}
def init(target) do
mod = Module.concat([Farmbot, System, target, FileSystem])
{:consumer, mod, subscribe_to: [Farmbot.System.FS]}
end
@spec handle_events([any], any, binary) :: {:noreply, [], binary}
def handle_events(events, _from, mod) do
mod.mount_read_write
for {transaction, cb} <- events do
@ -41,13 +38,8 @@ defmodule Farmbot.System.FS.Worker do
{:noreply, [], mod}
end
def get_state do
GenServer.call(__MODULE__, :get_state)
end
def handle_call(:get_state, _, state), do: {:reply, [], state, state}
@spec terminate(any,binary) :: :ok
def terminate(_,mod) do
mod.mount_read_only
:ok

View File

@ -4,13 +4,6 @@ defmodule Farmbot.Transport.GenMqtt do
Transport for GenMqtt
"""
# GENSTAGE HACK
@spec handle_call(any, any, any) :: {:reply, any, any}
@spec handle_cast(any, any) :: {:noreply, any}
@spec handle_info(any, any) :: {:noreply, any}
@spec init(any) :: {:ok, any}
@spec handle_events(any, any, any) :: no_return
use GenStage
require Logger
alias Farmbot.Token

View File

@ -9,10 +9,6 @@ defmodule Farmbot.Transport.GenMqtt.Client do
alias Farmbot.CeleryScript.Command
alias Farmbot.CeleryScript.Ast
@spec handle_call(any, any, any) :: {:reply, any, any}
@spec handle_cast(any, Token.t) :: ok
@spec handle_info(any, Token.t) :: ok
@type ok :: {:ok, Token.t}
@spec init(Token.t) :: ok

View File

@ -87,6 +87,7 @@ defmodule Farmbot.Transport do
inc_count()
{:noreply, [], old_state}
else
dec_count() # HACK(Connor) Dialyzer hack
reset_count()
GenStage.async_notify(__MODULE__, {:status, new_state})
{:noreply, [], new_state}

View File

@ -5,7 +5,6 @@ defmodule Farmbot.Transport.Supervisor do
use Supervisor
@transports Application.get_env(:farmbot, :transports)
@spec init([]) :: {:ok, pid}
def init([]) do
children = build_children(@transports)
opts = [strategy: :one_for_one]

View File

@ -5,13 +5,6 @@ defmodule Farmbot.Transport.WebSocket do
use GenStage
require Logger
# GENSTAGE HACK
@spec handle_call(any, any, any) :: {:reply, any, any}
@spec handle_cast(any, any) :: {:noreply, any}
@spec handle_info(any, any) :: {:noreply, any}
@spec init(any) :: {:ok, any}
@spec handle_events(any, any, any) :: no_return
# TODO(Connor) THIS IS BACKWRDS
# Configurator starts this module, and it should be the other way.
@doc """

View File

@ -111,7 +111,8 @@ defmodule Farmbot.Updates.Handler do
Parses the httpotion response.
"""
@spec parse_resp(HTTPoison.Response.t) :: {:assets, Strint.t, String.t}
@spec parse_resp(HTTPoison.Response.t)
:: {:assets, Strint.t, String.t} | {:error, :bad_resp}
def parse_resp(
{:ok, %HTTPoison.Response{
body: body,
@ -123,8 +124,6 @@ defmodule Farmbot.Updates.Handler do
{:assets, new_version, assets}
end
# If we happen to get something weird from httpotion
@spec parse_resp(any) :: {:error, :bad_resp}
def parse_resp(_), do: {:error, :bad_resp}
def do_update_check do

View File

@ -30,7 +30,7 @@ defmodule Farmbot.Mixfile do
compilers: Mix.compilers ++ maybe_use_webpack(),
aliases: aliases(@target),
deps: deps() ++ system(@target),
dialyzer: [plt_add_deps: :project],
dialyzer: [plt_add_deps: :app_tree, plt_add_apps: [:mnesia, :hackney]],
preferred_cli_env: [
vcr: :test, "vcr.delete": :test, "vcr.check": :test, "vcr.show": :test,
"all_test": :test,