Skip to content

Commit e5f09ec

Browse files
brienwsvoynow
authored andcommitted
Enable the elixir code formatter (#231)
and run it, obviously.
1 parent 572b299 commit e5f09ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1722
-1086
lines changed

.formatter.exs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
inputs: ["mix.exs",
3+
"{config,lib,test}/**/*.{ex,exs}"]
4+
]

circle.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test:
1313
override:
1414
- mkdir -p $CIRCLE_TEST_REPORTS/test
1515
- script/ci/run-mix.sh dialyzer
16+
- script/ci/run-mix.sh formatter --check-formatted
1617
- script/ci/run-mix.sh credo --strict
1718
- script/ci/run-mix.sh test
1819
- script/ci/run-mix.sh coveralls.html

lib/bootleg/config.ex

+69-27
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ defmodule Bootleg.Config do
88

99
defmacro __using__(_) do
1010
quote do
11-
import Bootleg.Config, only: [role: 2, role: 3, config: 2, config: 1, config: 0,
12-
before_task: 2, after_task: 2, invoke: 1, task: 2, remote: 1, remote: 2,
13-
remote: 3, load: 1, upload: 3, download: 3]
11+
import Bootleg.Config,
12+
only: [
13+
role: 2,
14+
role: 3,
15+
config: 2,
16+
config: 1,
17+
config: 0,
18+
before_task: 2,
19+
after_task: 2,
20+
invoke: 1,
21+
task: 2,
22+
remote: 1,
23+
remote: 2,
24+
remote: 3,
25+
load: 1,
26+
upload: 3,
27+
download: 3
28+
]
1429
end
1530
end
1631

@@ -45,20 +60,24 @@ defmodule Bootleg.Config do
4560
if name == :all do
4661
raise ArgumentError, ":all is reserved by bootleg and refers to all defined roles."
4762
end
63+
4864
user = Keyword.get(options, :user, System.get_env("USER"))
49-
ssh_options = Enum.filter(options, &Enum.member?(SSH.supported_options, elem(&1, 0)) == true)
65+
66+
ssh_options =
67+
Enum.filter(options, &(Enum.member?(SSH.supported_options(), elem(&1, 0)) == true))
68+
69+
# identity needs to be present in both options lists
5070
role_options =
51-
options -- ssh_options
71+
(options -- ssh_options)
5272
|> Keyword.put(:user, user)
53-
# identity needs to be present in both options lists
5473
|> Keyword.put(:identity, ssh_options[:identity])
5574
|> Keyword.get_and_update(:identity, fn val ->
56-
if val || Keyword.has_key?(ssh_options, :identity) do
57-
{val, val || ssh_options[:identity]}
58-
else
59-
:pop
60-
end
61-
end)
75+
if val || Keyword.has_key?(ssh_options, :identity) do
76+
{val, val || ssh_options[:identity]}
77+
else
78+
:pop
79+
end
80+
end)
6281
|> elem(1)
6382

6483
quote bind_quoted: binding() do
@@ -73,6 +92,7 @@ defmodule Bootleg.Config do
7392
hosts: [],
7493
options: role_options
7594
}
95+
7696
role =
7797
:roles
7898
|> Bootleg.Config.Agent.get()
@@ -165,19 +185,29 @@ defmodule Bootleg.Config do
165185
defp add_callback(task, position, caller, do: block) do
166186
file = caller.file()
167187
line = caller.line()
188+
168189
quote do
169190
hook_number = Bootleg.Config.Agent.increment(:next_hook_number)
170-
module_name = String.to_atom("Elixir.Bootleg.DynamicCallbacks." <>
171-
String.capitalize("#{unquote(position)}") <> String.capitalize("#{unquote(task)}") <>
172-
"#{hook_number}")
191+
192+
module_name =
193+
String.to_atom(
194+
"Elixir.Bootleg.DynamicCallbacks." <>
195+
String.capitalize("#{unquote(position)}") <>
196+
String.capitalize("#{unquote(task)}") <> "#{hook_number}"
197+
)
198+
173199
defmodule module_name do
174200
@file unquote(file)
175201
def execute, do: unquote(block)
176202
def location, do: {unquote(file), unquote(line)}
177203
hook_list_name = :"#{unquote(position)}_hooks"
178204
hooks = Keyword.get(Bootleg.Config.Agent.get(hook_list_name), unquote(task), [])
179-
Bootleg.Config.Agent.merge(hook_list_name, unquote(task), hooks ++
180-
[[module_name, :execute]])
205+
206+
Bootleg.Config.Agent.merge(
207+
hook_list_name,
208+
unquote(task),
209+
hooks ++ [[module_name, :execute]]
210+
)
181211
end
182212
end
183213
end
@@ -283,9 +313,12 @@ defmodule Bootleg.Config do
283313

284314
if Code.ensure_compiled?(module_name) do
285315
{orig_file, orig_line} = module_name.location
286-
UI.warn "warning: task '#{unquote(task)}' is being redefined. " <>
287-
"The most recent definition will win, but this is probably not what you meant to do. " <>
288-
"The previous definition was at: #{orig_file}:#{orig_line}"
316+
317+
UI.warn(
318+
"warning: task '#{unquote(task)}' is being redefined. " <>
319+
"The most recent definition will win, but this is probably not what you meant to do. " <>
320+
"The previous definition was at: #{orig_file}:#{orig_line}"
321+
)
289322
end
290323

291324
original_opts = Code.compiler_options()
@@ -300,6 +333,7 @@ defmodule Bootleg.Config do
300333
after
301334
Code.compiler_options(original_opts)
302335
end
336+
303337
:ok
304338
end
305339
end
@@ -309,7 +343,7 @@ defmodule Bootleg.Config do
309343
agent_key
310344
|> Bootleg.Config.Agent.get()
311345
|> Keyword.get(task, [])
312-
|> Enum.each(fn([module, fnref]) -> apply(module, fnref, []) end)
346+
|> Enum.each(fn [module, fnref] -> apply(module, fnref, []) end)
313347
end
314348

315349
@spec module_for_task(atom) :: atom
@@ -352,6 +386,7 @@ defmodule Bootleg.Config do
352386
invoke_task_callbacks(task, :before_hooks)
353387

354388
module_name = module_for_task(task)
389+
355390
if Code.ensure_compiled?(module_name) do
356391
apply(module_name, :execute, [])
357392
end
@@ -460,6 +495,7 @@ defmodule Bootleg.Config do
460495
"""
461496
defmacro remote(role, options, lines) do
462497
roles = unpack_role(role)
498+
463499
quote bind_quoted: binding() do
464500
Enum.reduce(roles, [], fn role, outputs ->
465501
role
@@ -480,9 +516,12 @@ defmodule Bootleg.Config do
480516
@spec load(binary | charlist) :: :ok | {:error, :enoent}
481517
def load(file) do
482518
case File.regular?(file) do
483-
true -> Code.eval_file(file)
484-
:ok
485-
false -> {:error, :enoent}
519+
true ->
520+
Code.eval_file(file)
521+
:ok
522+
523+
false ->
524+
{:error, :enoent}
486525
end
487526
end
488527

@@ -527,6 +566,7 @@ defmodule Bootleg.Config do
527566
defmacro upload(role, local_path, remote_path) do
528567
{roles, filters} = split_roles_and_filters(role)
529568
roles = unpack_role(roles)
569+
530570
quote bind_quoted: binding() do
531571
Enum.each(roles, fn role ->
532572
role
@@ -580,6 +620,7 @@ defmodule Bootleg.Config do
580620
defmacro download(role, remote_path, local_path) do
581621
{roles, filters} = split_roles_and_filters(role)
582622
roles = unpack_role(roles)
623+
583624
quote bind_quoted: binding() do
584625
Enum.each(roles, fn role ->
585626
role
@@ -614,8 +655,8 @@ defmodule Bootleg.Config do
614655
@doc false
615656
@spec cache_project_config(atom) :: any
616657
def cache_project_config(prop) do
617-
unless Project.umbrella? do
618-
val = Project.config[prop]
658+
unless Project.umbrella?() do
659+
val = Project.config()[prop]
619660
Bootleg.Config.Agent.merge(:config, prop, val)
620661
val
621662
else
@@ -640,14 +681,15 @@ defmodule Bootleg.Config do
640681
@spec split_roles_and_filters(atom | keyword) :: {[atom], keyword}
641682
defp split_roles_and_filters(role) do
642683
role
643-
|> List.wrap
684+
|> List.wrap()
644685
|> Enum.split_while(fn term -> !is_tuple(term) end)
645686
end
646687

647688
@doc false
648689
@spec unpack_role(atom | keyword) :: tuple
649690
defp unpack_role(role) do
650691
wrapped_role = List.wrap(role)
692+
651693
if Enum.any?(wrapped_role, fn role -> role == :all end) do
652694
quote do: Keyword.keys(Bootleg.Config.Agent.get(:roles))
653695
else

lib/bootleg/config/agent.ex

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ defmodule Bootleg.Config.Agent do
1010
state_fn = fn ->
1111
[roles: [], config: [env: env], before_hooks: [], after_hooks: [], next_hook_number: 0]
1212
end
13+
1314
case Agent.start_link(state_fn, name: Bootleg.Config.Agent) do
14-
{:error, {:already_started, pid}} -> {:ok, pid}
15+
{:error, {:already_started, pid}} ->
16+
{:ok, pid}
17+
1518
{:ok, pid} ->
1619
wait_cleanup()
1720
launch_monitor()
18-
Tasks.load_tasks
21+
Tasks.load_tasks()
1922
{:ok, pid}
20-
val -> val
23+
24+
val ->
25+
val
2126
end
2227
end
2328

@@ -38,7 +43,7 @@ defmodule Bootleg.Config.Agent do
3843

3944
@spec increment(atom) :: integer()
4045
def increment(key) do
41-
Agent.get_and_update(agent_pid(), fn (state) ->
46+
Agent.get_and_update(agent_pid(), fn state ->
4247
{state[key], Keyword.put(state, key, state[key] + 1)}
4348
end)
4449
end
@@ -49,6 +54,7 @@ defmodule Bootleg.Config.Agent do
4954
Process.sleep(10)
5055
wait_cleanup()
5156
end
57+
5258
:ok
5359
end
5460

@@ -57,14 +63,16 @@ defmodule Bootleg.Config.Agent do
5763
ref = Process.monitor(Bootleg.Config.Agent)
5864
Process.register(self(), :"Bootleg.Config.Agent.monitor")
5965
send(parent_pid, {:monitor_up, self()})
66+
6067
receive do
6168
{:DOWN, ^ref, :process, _pid, _reason} ->
6269
Enum.each(:code.all_loaded(), fn {module, _file} ->
6370
if String.starts_with?(Atom.to_string(module), "Elixir.Bootleg.DynamicTasks.") ||
64-
String.starts_with?(Atom.to_string(module), "Elixir.Bootleg.DynamicCallbacks.")do
71+
String.starts_with?(Atom.to_string(module), "Elixir.Bootleg.DynamicCallbacks.") do
6572
unload_code(module)
6673
end
6774
end)
75+
6876
Process.unregister(:"Bootleg.Config.Agent.monitor")
6977
end
7078
end
@@ -79,6 +87,7 @@ defmodule Bootleg.Config.Agent do
7987
defp launch_monitor do
8088
if Process.whereis(Bootleg.Config.Agent) do
8189
pid = Process.spawn(__MODULE__, :agent_monitor, [self()], [])
90+
8291
receive do
8392
{:monitor_up, ^pid} -> :ok
8493
end
@@ -87,8 +96,7 @@ defmodule Bootleg.Config.Agent do
8796

8897
@spec agent_pid() :: pid | atom
8998
defp agent_pid do
90-
{:ok, pid} = Bootleg.Config.Agent.start_link
99+
{:ok, pid} = Bootleg.Config.Agent.start_link()
91100
pid
92101
end
93-
94102
end

lib/bootleg/host.ex

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ defmodule Bootleg.Host do
1717
def option(%__MODULE__{} = host, option) when is_atom(option) do
1818
get_in(host, [Access.key!(:options), option])
1919
end
20+
2021
def option(%__MODULE__{} = host, option, value) when is_atom(option) do
2122
put_in(host, [Access.key!(:options), option], value)
2223
end
2324

2425
def ssh_option(%__MODULE__{} = host, option) when is_atom(option) do
2526
get_in(host, [Access.key!(:host), Access.key!(:options), option])
2627
end
28+
2729
def ssh_option(%__MODULE__{} = host, option, value) when is_atom(option) do
2830
put_in(host, [Access.key!(:host), Access.key!(:options), option], value)
2931
end
@@ -38,6 +40,7 @@ defmodule Bootleg.Host do
3840

3941
defp do_combine_uniq([h | t], set, fun, acc) do
4042
value = fun.(h)
43+
4144
case set do
4245
%{^value => true} -> do_combine_uniq(t, set, fun, Enum.map(acc, &combine_hosts(&1, h)))
4346
%{} -> do_combine_uniq(t, Map.put(set, value, true), fun, [h | acc])
@@ -50,7 +53,7 @@ defmodule Bootleg.Host do
5053

5154
defp combine_hosts(host1, host2) do
5255
if host_id(host1) == host_id(host2) do
53-
combine_host_options host1, host2
56+
combine_host_options(host1, host2)
5457
else
5558
host1
5659
end

lib/bootleg/mix_task.ex

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ defmodule Bootleg.MixTask do
66
quote do
77
use Mix.Task
88

9-
@spec run(OptionParser.argv) :: :ok
9+
@spec run(OptionParser.argv()) :: :ok
1010
if is_atom(unquote(task)) && unquote(task) do
1111
def run(args) do
1212
{env, _} = Tasks.parse_env_task(args)
13+
1314
if env do
1415
Config.env(env)
1516
end
1617

1718
use Config
1819

19-
invoke unquote(task)
20+
invoke(unquote(task))
2021
end
2122
else
2223
def run(args) do
2324
{env, _} = Tasks.parse_env_task(args)
25+
2426
if env do
2527
Config.env(env)
2628
end
@@ -29,7 +31,7 @@ defmodule Bootleg.MixTask do
2931
end
3032
end
3133

32-
defoverridable [run: 1]
34+
defoverridable run: 1
3335
end
3436
end
3537
end

0 commit comments

Comments
 (0)