1erl_tidy(3) Erlang Module Definition erl_tidy(3)
2
3
4
6 erl_tidy - Tidies and pretty-prints Erlang source code, removing unused
7 functions, updating obsolete constructs and function calls, etc.
8
10 Tidies and pretty-prints Erlang source code, removing unused functions,
11 updating obsolete constructs and function calls, etc.
12
13 Caveats: It is possible that in some intricate uses of macros, the
14 automatic addition or removal of parentheses around uses or arguments
15 could cause the resulting program to be rejected by the compiler; how‐
16 ever, we have found no such case in existing code. Programs defining
17 strange macros can usually not be read by this program, and in those
18 cases, no changes will be made.
19
20 If you really, really want to, you may call it "Inga".
21
22 Disclaimer: The author accepts no responsibility for errors introduced
23 in code that has been processed by the program. It has been reasonably
24 well tested, but the possibility of errors remains. Keep backups of
25 your original code safely stored, until you feel confident that the
26 new, modified code can be trusted.
27
29 filename() = file:filename():
30
31
32 syntaxTree() = erl_syntax:syntaxTree():
33
34
35 An abstract syntax tree. See the erl_syntax module for details.
36
38 dir() -> ok
39
40 Equivalent to dir("").
41
42 dir(Dir) -> ok
43
44 Equivalent to dir(Dir, []).
45
46 dir(Directory::filename(), Options::[term()]) -> ok
47
48 Tidies Erlang source files in a directory and its subdirecto‐
49 ries.
50
51 Available options:
52
53 {follow_links, boolean()}:
54 If the value is true, symbolic directory links will be fol‐
55 lowed. The default value is false.
56
57 {recursive, boolean()}:
58 If the value is true, subdirectories will be visited recur‐
59 sively. The default value is true.
60
61 {regexp, string()}:
62 The value denotes a regular expression (see module re).
63 Tidying will only be applied to those regular files whose
64 names match this pattern. The default value is ".*\\.erl$",
65 which matches normal Erlang source file names.
66
67 {test, boolean()}:
68 If the value is true, no files will be modified. The default
69 value is false.
70
71 {verbose, boolean()}:
72 If the value is true, progress messages will be output while
73 the program is running, unless the quiet option is true. The
74 default value when calling dir/2 is true.
75
76 See the function file/2 for further options.
77
78 See also: re(3), file/2.
79
80 file(Name) -> ok
81
82 Equivalent to file(Name, []).
83
84 file(Name::filename(), Options::[term()]) -> ok
85
86 Tidies an Erlang source code file.
87
88 Available options are:
89
90 {backup_suffix, string()}:
91 Specifies the file name suffix to be used when a backup file
92 is created; the default value is ".bak" (cf. the backups
93 option).
94
95 {backups, boolean()}:
96 If the value is true, existing files will be renamed before
97 new files are opened for writing. The new names are formed
98 by appending the string given by the backup_suffix option to
99 the original name. The default value is true.
100
101 {dir, filename()}:
102 Specifies the name of the directory in which the output file
103 is to be written. By default, the current directory is used.
104 If the value is an empty string, the current directory is
105 used.
106
107 {outfile, filename()}:
108 Specifies the name of the file (without suffix) to which the
109 resulting source code is to be written. If this option is
110 not specified, the Name argument is used.
111
112 {printer, Function}:
113
114
115 * Function = (syntaxTree(), [term()]) -> string()
116
117 Specifies a function for prettyprinting Erlang syntax trees.
118 This is used for outputting the resulting module definition.
119 The function is assumed to return formatted text for the
120 given syntax tree, and should raise an exception if an error
121 occurs. The default formatting function calls erl_pret‐
122 typr:format/2.
123
124 {test, boolean()}:
125 If the value is true, no files will be modified; this is
126 typically most useful if the verbose flag is enabled, to
127 generate reports about the program files without affecting
128 them. The default value is false.
129
130 {stdout, boolean()}:
131 If the value is true, instead of the file being written to
132 disk it will be printed to stdout. The default value is
133 false.
134
135 See the function module/2 for further options.
136
137 See also: module/2, erl_prettypr:format/2.
138
139 module(Forms) -> syntaxTree()
140
141 Equivalent to module(Forms, []).
142
143 module(Forms, Options::[term()]) -> syntaxTree()
144
145 Types:
146
147 Forms = syntaxTree() | [syntaxTree()]
148
149 Tidies a syntax tree representation of a module definition. The
150 given Forms may be either a single syntax tree of type
151 form_list, or a list of syntax trees representing "program
152 forms". In either case, Forms must represent a single complete
153 module definition. The returned syntax tree has type form_list
154 and represents a tidied-up version of the same source code.
155
156 Available options are:
157
158 {auto_export_vars, boolean()}:
159 If the value is true, all matches "{V1, ..., Vn} = E" where
160 E is a case-, if- or receive-expression whose branches all
161 return n-tuples (or explicitly throw exceptions) will be
162 rewritten to bind and export the variables V1, ..., Vn
163 directly. The default value is false.
164
165 For example:
166
167 {X, Y} = case ... of
168 ... -> {17, foo()};
169 ... -> {42, bar()}
170 end
171
172
173 will be rewritten to:
174
175 case ... of
176 ... -> X = 17, Y = foo(), {X, Y};
177 ... -> X = 42, Y = bar(), {X, Y}
178 end
179
180
181 {auto_list_comp, boolean()}:
182 If the value is true, calls to lists:map/2 and lists:fil‐
183 ter/2 will be rewritten using list comprehensions. The
184 default value is true.
185
186 {file, string()}:
187 Specifies the name of the file from which the source code
188 was taken. This is only used for generation of error
189 reports. The default value is the empty string.
190
191 {idem, boolean()}:
192 If the value is true, all options that affect how the code
193 is modified are set to "no changes". For example, to only
194 update guard tests, and nothing else, use the options
195 [new_guard_tests, idem]. (Recall that options closer to the
196 beginning of the list have higher precedence.)
197
198 {keep_unused, boolean()}:
199 If the value is true, unused functions will not be removed
200 from the code. The default value is false.
201
202 {new_guard_tests, boolean()}:
203 If the value is true, guard tests will be updated to use the
204 new names, e.g. "is_integer(X)" instead of "integer(X)". The
205 default value is true. See also old_guard_tests.
206
207 {no_imports, boolean()}:
208 If the value is true, all import statements will be removed
209 and calls to imported functions will be expanded to explicit
210 remote calls. The default value is false.
211
212 {old_guard_tests, boolean()}:
213 If the value is true, guard tests will be changed to use the
214 old names instead of the new ones, e.g. "integer(X)" instead
215 of "is_integer(X)". The default value is false. This option
216 overrides the new_guard_tests option.
217
218 {quiet, boolean()}:
219 If the value is true, all information messages and warning
220 messages will be suppressed. The default value is false.
221
222 {rename, [{{atom(), atom(), integer()}, {atom(), atom()}}]}:
223 The value is a list of pairs, associating tuples {Module,
224 Name, Arity} with tuples {NewModule, NewName}, specifying
225 renamings of calls to remote functions. By default, the
226 value is the empty list.
227
228 The renaming affects only remote calls (also when disguised
229 by import declarations); local calls within a module are not
230 affected, and no function definitions are renamed. Since the
231 arity cannot change, the new name is represented by {NewMod‐
232 ule, NewName} only. Only calls matching the specified arity
233 will match; multiple entries are necessary for renaming
234 calls to functions that have the same module and function
235 name, but different arities.
236
237 This option can also be used to override the default renam‐
238 ing of calls which use obsolete function names.
239
240 {verbose, boolean()}:
241 If the value is true, progress messages will be output while
242 the program is running, unless the quiet option is true. The
243 default value is false.
244
246 Richard Carlsson <carlsson.richard@gmail.com>
247
248
249
250 syntax_tools 2.1.7 erl_tidy(3)