@@ -77,6 +77,8 @@ defmodule Mix.Tasks.Format do
7777
7878 * `--dry-run` - does not save files after formatting.
7979
80+ * `--verbose` - prints the names of files that were formatted.
81+
8082 * `--dot-formatter` - path to the file with formatter configuration.
8183 Defaults to `.formatter.exs` if one is available. See the
8284 "Formatting options" section above for more information.
@@ -199,6 +201,7 @@ defmodule Mix.Tasks.Format do
199201 no_exit: :boolean ,
200202 dot_formatter: :string ,
201203 dry_run: :boolean ,
204+ verbose: :boolean ,
202205 stdin_filename: :string ,
203206 force: :boolean ,
204207 migrate: :boolean
@@ -264,7 +267,7 @@ defmodule Mix.Tasks.Format do
264267 maybe_cache_timestamps ( all_args , files , fn files ->
265268 files
266269 |> Task . async_stream ( & format_file ( & 1 , opts ) , ordered: false , timeout: :infinity )
267- |> Enum . reduce ( { [ ] , [ ] } , & collect_status / 2 )
270+ |> Enum . reduce ( { [ ] , [ ] , [ ] } , & collect_status / 2 )
268271 |> check! ( opts )
269272 end )
270273 end
@@ -773,39 +776,64 @@ defmodule Mix.Tasks.Format do
773776
774777 defp write_or_print ( file , input , output ) do
775778 cond do
776- file == :stdin -> IO . write ( output )
777- input == output -> :ok
778- true -> File . write! ( file , output )
779- end
779+ file == :stdin ->
780+ IO . write ( output )
781+ :ok
780782
781- :ok
783+ in put == output ->
784+ :ok
785+
786+ true ->
787+ File . write! ( file , output )
788+ { :formatted , file }
789+ end
782790 end
783791
784792 defp collect_status ( { :ok , :ok } , acc ) , do: acc
785793
786- defp collect_status ( { :ok , { :exit , _ , _ , _ } = exit } , { exits , not_formatted } ) do
787- { [ exit | exits ] , not_formatted }
794+ defp collect_status ( { :ok , { :exit , _ , _ , _ } = exit } , { exits , not_formatted , formatted } ) do
795+ { [ exit | exits ] , not_formatted , formatted }
788796 end
789797
790- defp collect_status ( { :ok , { :not_formatted , file } } , { exits , not_formatted } ) do
791- { exits , [ file | not_formatted ] }
798+ defp collect_status ( { :ok , { :not_formatted , file } } , { exits , not_formatted , formatted } ) do
799+ { exits , [ file | not_formatted ] , formatted }
792800 end
793801
794- defp check! ( { [ ] , [ ] } , _task_opts ) do
802+ defp collect_status ( { :ok , { :formatted , file } } , { exits , not_formatted , formatted } ) do
803+ { exits , not_formatted , [ file | formatted ] }
804+ end
805+
806+ defp check! ( { [ ] , [ ] , [ ] } , _task_opts ) do
807+ :ok
808+ end
809+
810+ defp check! ( { [ ] , [ ] , formatted } , task_opts ) do
811+ if task_opts [ :verbose ] do
812+ formatted
813+ |> Enum . sort ( )
814+ |> Enum . each ( & Mix . shell ( ) . info ( [ :green , "* formatting " , :reset , Path . relative_to_cwd ( & 1 ) ] ) )
815+ end
816+
795817 :ok
796818 end
797819
798- defp check! ( { [ { :exit , :stdin , exception , stacktrace } | _ ] , _not_formatted } , _task_opts ) do
820+ defp check! (
821+ { [ { :exit , :stdin , exception , stacktrace } | _ ] , _not_formatted , _formatted } ,
822+ _task_opts
823+ ) do
799824 Mix . shell ( ) . error ( "mix format failed for stdin" )
800825 reraise exception , stacktrace
801826 end
802827
803- defp check! ( { [ { :exit , file , exception , stacktrace } | _ ] , _not_formatted } , _task_opts ) do
828+ defp check! (
829+ { [ { :exit , file , exception , stacktrace } | _ ] , _not_formatted , _formatted } ,
830+ _task_opts
831+ ) do
804832 Mix . shell ( ) . error ( "mix format failed for file: #{ Path . relative_to_cwd ( file ) } " )
805833 reraise exception , stacktrace
806834 end
807835
808- defp check! ( { _exits , [ _ | _ ] = not_formatted } , task_opts ) do
836+ defp check! ( { _exits , [ _ | _ ] = not_formatted , _formatted } , task_opts ) do
809837 no_exit? = Keyword . get ( task_opts , :no_exit , false )
810838
811839 message = """
0 commit comments