@@ -23,14 +23,12 @@ defmodule JS2E do
2323 alias JS2E.Parsers . { ParserWarning , ParserError }
2424 alias JS2E.Printers.PrinterError
2525
26- @ spec main ( [ String . t ] ) :: :ok
26+ @ spec main ( [ String . t ( ) ] ) :: :ok
2727 def main ( args ) do
28-
29- { options , paths , errors } =
30- OptionParser . parse ( args , switches: [ module_name: :string ] )
28+ { options , paths , errors } = OptionParser . parse ( args , switches: [ module_name: :string ] )
3129
3230 if length ( paths ) == 0 do
33- IO . puts @ moduledoc
31+ IO . puts ( @ moduledoc )
3432 exit ( :normal )
3533 end
3634
@@ -42,22 +40,21 @@ defmodule JS2E do
4240 files = resolve_all_paths ( paths )
4341
4442 if length ( files ) == 0 do
45- print_error ( "Error: Could not find any " <>
46- "JSON files in path: #{ inspect paths } " )
43+ print_error ( "Error: Could not find any " <> "JSON files in path: #{ inspect ( paths ) } " )
4744 exit ( :no_files )
4845 end
4946
5047 output_path = create_output_dir ( options )
5148 JS2E . generate ( files , output_path )
5249 end
5350
54- @ spec resolve_all_paths ( [ String . t ] ) :: [ Path . t ]
51+ @ spec resolve_all_paths ( [ String . t ( ) ] ) :: [ Path . t ( ) ]
5552 defp resolve_all_paths ( paths ) do
5653 paths
5754 |> Enum . filter ( & File . exists? / 1 )
58- |> Enum . reduce ( [ ] , fn ( filename , files ) ->
55+ |> Enum . reduce ( [ ] , fn filename , files ->
5956 cond do
60- File . dir? filename ->
57+ File . dir? ( filename ) ->
6158 walk_directory ( filename ) ++ files
6259
6360 String . ends_with? ( filename , ".json" ) ->
@@ -69,15 +66,15 @@ defmodule JS2E do
6966 end )
7067 end
7168
72- @ spec walk_directory ( String . t ) :: [ String . t ]
69+ @ spec walk_directory ( String . t ( ) ) :: [ String . t ( ) ]
7370 defp walk_directory ( dir ) do
7471 dir
75- |> File . ls!
72+ |> File . ls! ( )
7673 |> Enum . reduce ( [ ] , fn file , files ->
7774 filename = "#{ dir } /#{ file } "
7875
7976 cond do
80- File . dir? filename ->
77+ File . dir? ( filename ) ->
8178 walk_directory ( filename ) ++ files
8279
8380 String . ends_with? ( file , ".json" ) ->
@@ -89,58 +86,55 @@ defmodule JS2E do
8986 end )
9087 end
9188
92- @ spec create_output_dir ( list ) :: String . t
89+ @ spec create_output_dir ( list ) :: String . t ( )
9390 defp create_output_dir ( options ) do
94-
95- output_path = if Keyword . has_key? ( options , :module_name ) do
96- Keyword . get ( options , :module_name )
97- else
98- "Domain"
99- end
91+ output_path =
92+ if Keyword . has_key? ( options , :module_name ) do
93+ Keyword . get ( options , :module_name )
94+ else
95+ "Domain"
96+ end
10097
10198 output_path
10299 |> File . mkdir_p! ( )
103100
104101 output_path
105102 end
106103
107- @ spec generate ( [ String . t ] , String . t ) :: :ok
104+ @ spec generate ( [ String . t ( ) ] , String . t ( ) ) :: :ok
108105 def generate ( schema_paths , module_name ) do
109-
110- Logger . info "Parsing JSON schema files!"
106+ Logger . info ( "Parsing JSON schema files!" )
111107 parser_result = parse_schema_files ( schema_paths )
112108 pretty_parser_warnings ( parser_result . warnings )
113109
114110 if length ( parser_result . errors ) > 0 do
115111 pretty_parser_errors ( parser_result . errors )
116-
117112 else
118- Logger . info "Converting to Elm code!"
113+ Logger . info ( "Converting to Elm code!" )
119114 printer_result = print_schemas ( parser_result . schema_dict , module_name )
120115
121116 if length ( printer_result . errors ) > 0 do
122117 pretty_printer_errors ( printer_result . errors )
123-
124118 else
125- Logger . info "Printing Elm code to file(s)!"
119+ Logger . info ( "Printing Elm code to file(s)!" )
126120
127121 file_dict = printer_result . file_dict
122+
128123 Enum . each ( file_dict , fn { file_path , file_content } ->
129- { :ok , file } = File . open file_path , [ :write ]
130- IO . binwrite file , file_content
131- File . close file
132- Logger . info "Created file '#{ file_path } '"
124+ { :ok , file } = File . open ( file_path , [ :write ] )
125+ IO . binwrite ( file , file_content )
126+ File . close ( file )
127+ Logger . info ( "Created file '#{ file_path } '" )
133128 end )
134129 end
135130 end
136131 end
137132
138- @ spec pretty_parser_warnings ( [ ParserWarning . t ] ) :: :ok
133+ @ spec pretty_parser_warnings ( [ ParserWarning . t ( ) ] ) :: :ok
139134 defp pretty_parser_warnings ( warnings ) do
140135 warnings
141136 |> Enum . each ( fn { file_path , warnings } ->
142137 if length ( warnings ) > 0 do
143-
144138 warning_header ( )
145139
146140 warnings
@@ -150,45 +144,50 @@ defmodule JS2E do
150144 warning_type
151145 |> to_string
152146 |> String . replace ( "_" , " " )
153- |> String . downcase
147+ |> String . downcase ( )
154148
155- padding = String . duplicate ( "-" ,
156- max ( 0 , 74 - String . length ( pretty_warning_type ) - String . length ( file_path ) ) )
149+ padding =
150+ String . duplicate (
151+ "-" ,
152+ max ( 0 , 74 - String . length ( pretty_warning_type ) - String . length ( file_path ) )
153+ )
157154
158155 warnings
159156 |> Enum . each ( fn warning ->
160157 print_header ( "--- #{ pretty_warning_type } #{ padding } #{ file_path } \n " )
161- IO . puts warning . message
158+ IO . puts ( warning . message )
162159 end )
163160 end )
164-
165161 end
166162 end )
163+
167164 :ok
168165 end
169166
170- @ spec pretty_parser_errors ( [ ParserError . t ] ) :: :ok
167+ @ spec pretty_parser_errors ( [ ParserError . t ( ) ] ) :: :ok
171168 defp pretty_parser_errors ( errors ) do
172169 errors
173170 |> Enum . each ( fn { file_path , errors } ->
174171 if length ( errors ) > 0 do
175-
176172 errors
177173 |> Enum . group_by ( fn err -> err . error_type end )
178174 |> Enum . each ( fn { error_type , errors } ->
179175 pretty_error_type =
180176 error_type
181177 |> to_string
182178 |> String . replace ( "_" , " " )
183- |> String . upcase
179+ |> String . upcase ( )
184180
185- padding = String . duplicate ( "-" ,
186- max ( 0 , 74 - String . length ( pretty_error_type ) - String . length ( file_path ) ) )
181+ padding =
182+ String . duplicate (
183+ "-" ,
184+ max ( 0 , 74 - String . length ( pretty_error_type ) - String . length ( file_path ) )
185+ )
187186
188187 errors
189188 |> Enum . each ( fn error ->
190189 print_header ( "--- #{ pretty_error_type } #{ padding } #{ file_path } \n " )
191- IO . puts error . message
190+ IO . puts ( error . message )
192191 end )
193192 end )
194193 end
@@ -197,52 +196,49 @@ defmodule JS2E do
197196 :ok
198197 end
199198
200- @ spec pretty_printer_errors ( [ PrinterError . t ] ) :: :ok
199+ @ spec pretty_printer_errors ( [ PrinterError . t ( ) ] ) :: :ok
201200 defp pretty_printer_errors ( errors ) do
202-
203201 errors
204202 |> Enum . each ( fn { file_path , errors } ->
205203 if length ( errors ) > 0 do
206-
207204 errors
208205 |> Enum . group_by ( fn err -> err . error_type end )
209206 |> Enum . each ( fn { error_type , errors } ->
210-
211207 pretty_error_type =
212208 error_type
213209 |> to_string
214210 |> String . replace ( "_" , " " )
215- |> String . upcase
211+ |> String . upcase ( )
216212
217- padding = String . duplicate ( "-" ,
218- max ( 0 , 74 - String . length ( pretty_error_type ) - String . length ( file_path ) ) )
213+ padding =
214+ String . duplicate (
215+ "-" ,
216+ max ( 0 , 74 - String . length ( pretty_error_type ) - String . length ( file_path ) )
217+ )
219218
220219 errors
221220 |> Enum . each ( fn error ->
222221 print_header ( "--- #{ pretty_error_type } #{ padding } #{ file_path } \n " )
223- IO . puts error . message
222+ IO . puts ( error . message )
224223 end )
225224 end )
226-
227225 end
228226 end )
227+
229228 :ok
230229 end
231230
232231 defp print_error ( str ) do
233- IO . puts IO.ANSI . format ( [ :cyan , str ] )
232+ IO . puts ( IO.ANSI . format ( [ :cyan , str ] ) )
234233 end
235234
236235 defp print_header ( str ) do
237- IO . puts IO.ANSI . format ( [ :cyan , str ] )
236+ IO . puts ( IO.ANSI . format ( [ :cyan , str ] ) )
238237 end
239238
240239 defp warning_header do
241- header = String . duplicate ( "^" , 35 ) <>
242- " WARNINGS " <>
243- String . duplicate ( "^" , 35 )
240+ header = String . duplicate ( "^" , 35 ) <> " WARNINGS " <> String . duplicate ( "^" , 35 )
244241
245- IO . puts IO.ANSI . format ( [ :yellow , header ] )
242+ IO . puts ( IO.ANSI . format ( [ :yellow , header ] ) )
246243 end
247-
248244end
0 commit comments