diff --git a/.circleci/config.yml b/.circleci/config.yml index 2e1b9b5..9993570 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,6 +48,7 @@ jobs: - run: mix docs - run: mix hex.build - run: mix dialyzer + - run: mix credo -a --strict - save_cache: key: v1-mix-cache-{{ checksum "mix.lock" }} paths: diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..2961835 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,14 @@ +# config/.credo.exs +%{ + configs: [ + %{ + name: "default", + checks: [ + {Credo.Check.Refactor.MapInto, false}, + {Credo.Check.Warning.LazyLogging, false}, + {Credo.Check.Readability.LargeNumbers, only_greater_than: 86400}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, parens: true} + ] + } + ] +} diff --git a/lib/nerves_ssh/exec.ex b/lib/nerves_ssh/exec.ex index 667483a..b89bf68 100644 --- a/lib/nerves_ssh/exec.ex +++ b/lib/nerves_ssh/exec.ex @@ -1,15 +1,17 @@ defmodule NervesSSH.Exec do - @doc """ - Run one command coming over ssh + @moduledoc """ + This module contains helper methods for running commands over SSH """ + @doc """ + Run one Elixir command coming over ssh + """ + @spec run_elixir(charlist()) :: {:ok, binary()} | {:error, binary()} def run_elixir(cmd) do - try do - {result, _env} = Code.eval_string(to_string(cmd)) - {:ok, inspect(result)} - catch - kind, value -> - {:error, "** (#{kind}) #{inspect(value)}"} - end + {result, _env} = Code.eval_string(to_string(cmd)) + {:ok, inspect(result)} + catch + kind, value -> + {:error, "** (#{kind}) #{inspect(value)}"} end end diff --git a/lib/nerves_ssh/options.ex b/lib/nerves_ssh/options.ex index e7ac7fb..75b7db1 100644 --- a/lib/nerves_ssh/options.ex +++ b/lib/nerves_ssh/options.ex @@ -15,6 +15,8 @@ defmodule NervesSSH.Options do * `:daemon_option_overrides` - additional options to pass to `:ssh.daemon/2`. These take precedence and are unchecked. """ + alias Nerves.Runtime.KV + @default_system_dir "/etc/ssh" @otp System.otp_release() |> Integer.parse() |> elem(0) @@ -243,9 +245,7 @@ defmodule NervesSSH.Options do defp valid_subsystem?(_), do: false defp add_fwup_subsystem(opts) do - # TODO: Make it possible to opt out of this - - devpath = Nerves.Runtime.KV.get("nerves_fw_devpath") + devpath = KV.get("nerves_fw_devpath") new_subsystems = [SSHSubsystemFwup.subsystem_spec(devpath: devpath) | opts.subsystems] %{opts | subsystems: new_subsystems} diff --git a/mix.exs b/mix.exs index 28a0be5..7dbae0c 100644 --- a/mix.exs +++ b/mix.exs @@ -18,7 +18,8 @@ defmodule NervesSSH.MixProject do preferred_cli_env: %{ docs: :docs, "hex.publish": :docs, - "hex.build": :docs + "hex.build": :docs, + credo: :test } ] end @@ -36,7 +37,8 @@ defmodule NervesSSH.MixProject do {:ex_doc, "~> 0.22", only: :docs, runtime: false}, {:ssh_subsystem_fwup, "~> 0.5"}, {:nerves_runtime, "~> 0.11"}, - {:sshex, "~> 2.2.1", only: [:dev, :test]} + {:sshex, "~> 2.2.1", only: [:dev, :test]}, + {:credo, "~> 1.2", only: :test, runtime: false} ] end diff --git a/mix.lock b/mix.lock index adf180e..92e28b3 100644 --- a/mix.lock +++ b/mix.lock @@ -1,10 +1,13 @@ %{ + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, + "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, "earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"}, "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, "elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.22.2", "03a2a58bdd2ba0d83d004507c4ee113b9c521956938298eba16e55cc4aba4a6c", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "cf60e1b3e2efe317095b6bb79651f83a2c1b3edcb4d319c421d7fcda8b3aff26"}, + "jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"}, "makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"}, "makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"}, "nerves_runtime": {:hex, :nerves_runtime, "0.11.2", "7606c559d6eb33736af813394d8b4e67e3ede155808c6dc4b2ac0aea2c1b66fb", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:system_registry, "~> 0.8.0", [hex: :system_registry, repo: "hexpm", optional: false]}, {:uboot_env, "~> 0.1.1 or ~> 0.2.0", [hex: :uboot_env, repo: "hexpm", optional: false]}], "hexpm", "094446be5a1d51d3ec0c26e9f5905ab42731397e8715404a5e5e095b4f3125b6"},