Skip to content

Commit cbd6abe

Browse files
Nitrinojosevalim
authored andcommitted
Run the code formatter on Mix.Tasks.Compile.App (#6663)
1 parent e13d6cb commit cbd6abe

File tree

1 file changed

+86
-35
lines changed

1 file changed

+86
-35
lines changed

lib/mix/lib/mix/tasks/compile.app.ex

+86-35
Original file line numberDiff line numberDiff line change
@@ -107,45 +107,50 @@ defmodule Mix.Tasks.Compile.App do
107107
def run(args) do
108108
{opts, _, _} = OptionParser.parse(args, switches: [force: :boolean])
109109

110-
project = Mix.Project.get!
111-
config = Mix.Project.config
110+
project = Mix.Project.get!()
111+
config = Mix.Project.config()
112112

113-
app = Keyword.get(config, :app)
113+
app = Keyword.get(config, :app)
114114
version = Keyword.get(config, :version)
115115

116116
validate_app(app)
117117
validate_version(version)
118118

119-
path = Mix.Project.compile_path
120-
mods = modules_from(Path.wildcard("#{path}/*.beam")) |> Enum.sort
119+
path = Mix.Project.compile_path()
120+
mods = modules_from(Path.wildcard("#{path}/*.beam")) |> Enum.sort()
121121

122-
target = Path.join(path, "#{app}.app")
123-
sources = Mix.Project.config_files
122+
target = Path.join(path, "#{app}.app")
123+
sources = Mix.Project.config_files()
124124

125125
if opts[:force] || Mix.Utils.stale?(sources, [target]) || modules_changed?(mods, target) do
126126
best_guess = [
127127
description: to_charlist(config[:description] || app),
128128
modules: mods,
129129
registered: [],
130-
vsn: to_charlist(version),
130+
vsn: to_charlist(version)
131131
]
132132

133-
properties = if function_exported?(project, :application, 0) do
134-
project_application = project.application()
135-
unless Keyword.keyword?(project_application) do
136-
Mix.raise "Application configuration returned from application/0 should be a keyword list"
133+
properties =
134+
if function_exported?(project, :application, 0) do
135+
project_application = project.application
136+
137+
unless Keyword.keyword?(project_application) do
138+
Mix.raise(
139+
"Application configuration returned from application/0 should be a keyword list"
140+
)
141+
end
142+
143+
Keyword.merge(best_guess, project_application)
144+
else
145+
best_guess
137146
end
138-
Keyword.merge(best_guess, project_application)
139-
else
140-
best_guess
141-
end
142147

143148
properties = ensure_correct_properties(properties, config)
144149
contents = :io_lib.format("~p.~n", [{:application, app, properties}])
145150

146151
Mix.Project.ensure_structure()
147152
File.write!(target, IO.chardata_to_string(contents))
148-
Mix.shell.info "Generated #{app} app"
153+
Mix.shell().info("Generated #{app} app")
149154
:ok
150155
else
151156
:noop
@@ -156,19 +161,22 @@ defmodule Mix.Tasks.Compile.App do
156161
case :file.consult(target) do
157162
{:ok, [{:application, _app, properties}]} ->
158163
properties[:modules] != mods
164+
159165
_ ->
160166
false
161167
end
162168
end
163169

164170
defp validate_app(app) when is_atom(app), do: :ok
171+
165172
defp validate_app(app) do
166173
ensure_present(:app, app)
167174
Mix.raise("Expected :app to be an atom, got: #{inspect(app)}")
168175
end
169176

170177
defp validate_version(version) do
171178
ensure_present(:version, version)
179+
172180
unless is_binary(version) and match?({:ok, _}, Version.parse(version)) do
173181
Mix.raise("Expected :version to be a SemVer version, got: #{inspect(version)}")
174182
end
@@ -177,10 +185,11 @@ defmodule Mix.Tasks.Compile.App do
177185
defp ensure_present(name, nil) do
178186
Mix.raise("Please ensure mix.exs file has the #{inspect(name)} in the project definition")
179187
end
188+
180189
defp ensure_present(_name, _val), do: :ok
181190

182191
defp modules_from(beams) do
183-
Enum.map beams, &(&1 |> Path.basename |> Path.rootname(".beam") |> String.to_atom)
192+
Enum.map(beams, &(&1 |> Path.basename() |> Path.rootname(".beam") |> String.to_atom()))
184193
end
185194

186195
defp language_app(config) do
@@ -199,73 +208,115 @@ defmodule Mix.Tasks.Compile.App do
199208
end
200209

201210
defp validate_properties!(properties) do
202-
Enum.each properties, fn
211+
Enum.each(properties, fn
203212
{:description, value} ->
204213
unless is_list(value) do
205-
Mix.raise "Application description (:description) is not a character list, got: #{inspect value}"
214+
Mix.raise(
215+
"Application description (:description) is not a character list, got: #{
216+
inspect(value)
217+
}"
218+
)
206219
end
220+
207221
{:id, value} ->
208222
unless is_list(value) do
209-
Mix.raise "Application id (:id) is not a character list, got: #{inspect value}"
223+
Mix.raise("Application id (:id) is not a character list, got: #{inspect(value)}")
210224
end
225+
211226
{:vsn, value} ->
212227
unless is_list(value) do
213-
Mix.raise "Application vsn (:vsn) is not a character list, got: #{inspect value}"
228+
Mix.raise("Application vsn (:vsn) is not a character list, got: #{inspect(value)}")
214229
end
230+
215231
{:maxT, value} ->
216232
unless value == :infinity or is_integer(value) do
217-
Mix.raise "Application maximum time (:maxT) is not an integer or :infinity, got: #{inspect value}"
233+
Mix.raise(
234+
"Application maximum time (:maxT) is not an integer or :infinity, got: " <>
235+
inspect(value)
236+
)
218237
end
238+
219239
{:modules, value} ->
220240
unless is_list(value) and Enum.all?(value, &is_atom(&1)) do
221-
Mix.raise "Application modules (:modules) should be a list of atoms, got: #{inspect value}"
241+
Mix.raise(
242+
"Application modules (:modules) should be a list of atoms, got: #{inspect(value)}"
243+
)
222244
end
245+
223246
{:registered, value} ->
224247
unless is_list(value) and Enum.all?(value, &is_atom(&1)) do
225-
Mix.raise "Application registered processes (:registered) should be a list of atoms, got: #{inspect value}"
248+
Mix.raise(
249+
"Application registered processes (:registered) should be a list of atoms, got: " <>
250+
inspect(value)
251+
)
226252
end
253+
227254
{:included_applications, value} ->
228255
unless is_list(value) and Enum.all?(value, &is_atom(&1)) do
229-
Mix.raise "Application included applications (:included_applications) should be a list of atoms, got: #{inspect value}"
256+
Mix.raise(
257+
"Application included applications (:included_applications) should be a list of atoms, got: " <>
258+
inspect(value)
259+
)
230260
end
261+
231262
{:extra_applications, value} ->
232263
unless is_list(value) and Enum.all?(value, &is_atom(&1)) do
233-
Mix.raise "Application extra applications (:extra_applications) should be a list of atoms, got: #{inspect value}"
264+
Mix.raise(
265+
"Application extra applications (:extra_applications) should be a list of atoms, got: " <>
266+
inspect(value)
267+
)
234268
end
269+
235270
{:applications, value} ->
236271
unless is_list(value) and Enum.all?(value, &is_atom(&1)) do
237-
Mix.raise "Application applications (:applications) should be a list of atoms, got: #{inspect value}"
272+
Mix.raise(
273+
"Application applications (:applications) should be a list of atoms, got: " <>
274+
inspect(value)
275+
)
238276
end
277+
239278
{:env, value} ->
240279
unless Keyword.keyword?(value) do
241-
Mix.raise "Application environment (:env) should be a keyword list, got: #{inspect value}"
280+
Mix.raise(
281+
"Application environment (:env) should be a keyword list, got: #{inspect(value)}"
282+
)
242283
end
284+
243285
{:start_phases, value} ->
244286
unless Keyword.keyword?(value) do
245-
Mix.raise "Application start phases (:start_phases) should be a keyword list, got: #{inspect value}"
287+
Mix.raise(
288+
"Application start phases (:start_phases) should be a keyword list, got: " <>
289+
inspect(value)
290+
)
246291
end
292+
247293
{:mod, []} ->
248294
:ok
295+
249296
{:mod, {module, _args}} when is_atom(module) ->
250297
:ok
298+
251299
{:mod, value} ->
252-
Mix.raise "Application callback module (:mod) should be either [] or {module, start_args}, got: #{inspect value}"
300+
Mix.raise(
301+
"Application callback module (:mod) should be either [] or {module, start_args}, got: " <>
302+
inspect(value)
303+
)
304+
253305
_ ->
254306
:ok
255-
end
307+
end)
256308

257309
properties
258310
end
259311

260312
defp apps_from_prod_non_optional_deps(properties) do
261313
included_applications = Keyword.get(properties, :included_applications, [])
262314

263-
for %{app: app, opts: opts, top_level: true} <- Mix.Dep.cached,
315+
for %{app: app, opts: opts, top_level: true} <- Mix.Dep.cached(),
264316
Keyword.get(opts, :app, true),
265317
Keyword.get(opts, :runtime, true),
266318
not Keyword.get(opts, :optional, false),
267-
app not in included_applications,
268-
do: app
319+
app not in included_applications, do: app
269320
end
270321

271322
defp normalize_apps(apps, properties, config) do

0 commit comments

Comments
 (0)