Repository navigation
Expand file tree
/
Copy patherl_tidy.escript
More file actions
executable file
·64 lines (52 loc) · 1.79 KB
/
Copy patherl_tidy.escript
File metadata and controls
executable file
·64 lines (52 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env escript
%%!
%% -*- coding: utf-8 -*-
-mode(compile).
-export([main/1]).
%% erl_tidy.escript: does not support HRL ESCRIPT APP.SRC.
main([]) ->
io:format(standard_error
,"Usage: ~s <ERL files or folders>\n"
,[filename:dirname(escript:script_name())]
),
halt(1);
main(Files) ->
tidy_files(Files).
%% Internals
tidy_files(Paths) ->
lists:foreach(fun tidy/1, Paths).
printer(AST, Options) ->
erl_prettypr:format(AST, [{paper, 115}
,{ribbon, 100}
| Options
]).
tidy(Path) ->
case {filelib:is_regular(Path), filelib:is_dir(Path)} of
{true, _} ->
case filename:extension(Path) of
".erl" ->
erl_tidy:file(Path, [{backups, false}
,{quiet, false}
,{verbose, false}
,{printer, fun printer/2}
,{keep_unused, true}
,{auto_export_vars, false}
,{auto_list_comp, true}
,{new_guard_tests, true}
,{no_imports, true}
,{idem, true}
]);
_ ->
skip(Path)
end;
{_, true} ->
RegExp = "\\.erl$",
Paths = filelib:fold_files(Path, RegExp, true, fun cons/2, []),
tidy_files(Paths);
_ ->
skip(Path)
end.
cons(H, T) -> [H | T].
skip(Path) ->
io:format(standard_error, "Skipping ~s\n", [Path]).
%% End of Module