@@ -78,6 +78,14 @@ defmodule Mix.Tasks.Format do
78
78
as `.heex`. Without passing this flag, it is assumed that the code being
79
79
passed via stdin is valid Elixir code. Defaults to "stdin.exs".
80
80
81
+ * `--migrate` - enables the `:migrate` option, which should be able to
82
+ automatically fix some deprecation warnings but is changing the AST.
83
+ This should be safe in typical projects, but there is a non-zero risk
84
+ of breaking code for meta-programming heavy projects that relied on a
85
+ specific AST, or projects that are re-defining functions from the `Kernel`.
86
+ See the "Migration formatting" section in `Code.format_string!/2` for
87
+ more information.
88
+
81
89
## When to format code
82
90
83
91
We recommend developers to format code directly in their editors, either
@@ -184,7 +192,8 @@ defmodule Mix.Tasks.Format do
184
192
dot_formatter: :string ,
185
193
dry_run: :boolean ,
186
194
stdin_filename: :string ,
187
- force: :boolean
195
+ force: :boolean ,
196
+ migrate: :boolean
188
197
]
189
198
190
199
@ manifest_timestamp "format_timestamp"
@@ -362,17 +371,21 @@ defmodule Mix.Tasks.Format do
362
371
end
363
372
364
373
defp eval_dot_formatter ( cwd , opts ) do
365
- cond do
366
- dot_formatter = opts [ :dot_formatter ] ->
367
- { dot_formatter , eval_file_with_keyword_list ( dot_formatter ) }
374
+ { dot_formatter , format_opts } =
375
+ cond do
376
+ dot_formatter = opts [ :dot_formatter ] ->
377
+ { dot_formatter , eval_file_with_keyword_list ( dot_formatter ) }
368
378
369
- File . regular? ( Path . join ( cwd , ".formatter.exs" ) ) ->
370
- dot_formatter = Path . join ( cwd , ".formatter.exs" )
371
- { ".formatter.exs" , eval_file_with_keyword_list ( dot_formatter ) }
379
+ File . regular? ( Path . join ( cwd , ".formatter.exs" ) ) ->
380
+ dot_formatter = Path . join ( cwd , ".formatter.exs" )
381
+ { ".formatter.exs" , eval_file_with_keyword_list ( dot_formatter ) }
372
382
373
- true ->
374
- { ".formatter.exs" , [ ] }
375
- end
383
+ true ->
384
+ { ".formatter.exs" , [ ] }
385
+ end
386
+
387
+ # the --migrate flag overrides settings from the dot formatter
388
+ { dot_formatter , Keyword . take ( opts , [ :migrate ] ) ++ format_opts }
376
389
end
377
390
378
391
# This function reads exported configuration from the imported
0 commit comments