Erlang -- erl_tidy

User's Guide
Reference Manual
Release Notes
PDF
Top

Syntax_Tools
Reference Manual
Version 2.1.1

Expand All
Contract All

Table of Contents

- epp_dodger
  - Top of manual page
  - parse/1
  - parse/3
  - parse/2
  - parse_file/1
  - parse_file/2
  - parse_form/2
  - parse_form/3
  - quick_parse/1
  - quick_parse/3
  - quick_parse/2
  - quick_parse_file/1
  - quick_parse_file/2
  - quick_parse_form/2
  - quick_parse_form/3
  - tokens_to_string/1
- erl_comment_scan
  - Top of manual page
  - file/1
  - join_lines/1
  - scan_lines/1
  - string/1
- erl_prettypr
  - Top of manual page
  - best/1
  - best/2
  - format/1
  - format/2
  - get_ctxt_hook/1
  - get_ctxt_linewidth/1
  - get_ctxt_paperwidth/1
  - get_ctxt_precedence/1
  - get_ctxt_user/1
  - layout/1
  - layout/2
  - set_ctxt_hook/2
  - set_ctxt_linewidth/2
  - set_ctxt_paperwidth/2
  - set_ctxt_precedence/2
  - set_ctxt_user/2
- erl_recomment
  - Top of manual page
  - quick_recomment_forms/2
  - recomment_forms/2
  - recomment_tree/2
- erl_syntax
  - Top of manual page
  - abstract/1
  - add_ann/2
  - add_postcomments/2
  - add_precomments/2
  - annotated_type/2
  - annotated_type_body/1
  - annotated_type_name/1
  - application/3
  - application/2
  - application_arguments/1
  - application_operator/1
  - arity_qualifier/2
  - arity_qualifier_argument/1
  - arity_qualifier_body/1
  - atom/1
  - atom_literal/1
  - atom_name/1
  - atom_value/1
  - attribute/1
  - attribute/2
  - attribute_arguments/1
  - attribute_name/1
  - binary/1
  - binary_comp/2
  - binary_comp_body/1
  - binary_comp_template/1
  - binary_field/1
  - binary_field/3
  - binary_field/2
  - binary_field_body/1
  - binary_field_size/1
  - binary_field_types/1
  - binary_fields/1
  - binary_generator/2
  - binary_generator_body/1
  - binary_generator_pattern/1
  - bitstring_type/2
  - bitstring_type_m/1
  - bitstring_type_n/1
  - block_expr/1
  - block_expr_body/1
  - case_expr/2
  - case_expr_argument/1
  - case_expr_clauses/1
  - catch_expr/1
  - catch_expr_body/1
  - char/1
  - char_literal/1
  - char_literal/2
  - char_value/1
  - class_qualifier/2
  - class_qualifier_argument/1
  - class_qualifier_body/1
  - clause/2
  - clause/3
  - clause_body/1
  - clause_guard/1
  - clause_patterns/1
  - comment/2
  - comment/1
  - comment_padding/1
  - comment_text/1
  - compact_list/1
  - concrete/1
  - cond_expr/1
  - cond_expr_clauses/1
  - conjunction/1
  - conjunction_body/1
  - cons/2
  - constrained_function_type/2
  - constrained_function_type_argument/1
  - constrained_function_type_body/1
  - constraint/2
  - constraint_argument/1
  - constraint_body/1
  - copy_ann/2
  - copy_attrs/2
  - copy_comments/2
  - copy_pos/2
  - data/1
  - disjunction/1
  - disjunction_body/1
  - eof_marker/0
  - error_marker/1
  - error_marker_info/1
  - flatten_form_list/1
  - float/1
  - float_literal/1
  - float_value/1
  - form_list/1
  - form_list_elements/1
  - fun_expr/1
  - fun_expr_arity/1
  - fun_expr_clauses/1
  - fun_type/0
  - function/2
  - function_arity/1
  - function_clauses/1
  - function_name/1
  - function_type/2
  - function_type/1
  - function_type_arguments/1
  - function_type_return/1
  - generator/2
  - generator_body/1
  - generator_pattern/1
  - get_ann/1
  - get_attrs/1
  - get_pos/1
  - get_postcomments/1
  - get_precomments/1
  - has_comments/1
  - if_expr/1
  - if_expr_clauses/1
  - implicit_fun/3
  - implicit_fun/1
  - implicit_fun/2
  - implicit_fun_name/1
  - infix_expr/3
  - infix_expr_left/1
  - infix_expr_operator/1
  - infix_expr_right/1
  - integer/1
  - integer_literal/1
  - integer_range_type/2
  - integer_range_type_high/1
  - integer_range_type_low/1
  - integer_value/1
  - is_atom/2
  - is_char/2
  - is_form/1
  - is_integer/2
  - is_leaf/1
  - is_list_skeleton/1
  - is_literal/1
  - is_proper_list/1
  - is_string/2
  - is_tree/1
  - join_comments/2
  - list/2
  - list/1
  - list_comp/2
  - list_comp_body/1
  - list_comp_template/1
  - list_elements/1
  - list_head/1
  - list_length/1
  - list_prefix/1
  - list_suffix/1
  - list_tail/1
  - macro/1
  - macro/2
  - macro_arguments/1
  - macro_name/1
  - make_tree/2
  - map_expr/2
  - map_expr/1
  - map_expr_argument/1
  - map_expr_fields/1
  - map_field_assoc/2
  - map_field_assoc_name/1
  - map_field_assoc_value/1
  - map_field_exact/2
  - map_field_exact_name/1
  - map_field_exact_value/1
  - map_type/0
  - map_type/1
  - map_type_assoc/2
  - map_type_assoc_name/1
  - map_type_assoc_value/1
  - map_type_exact/2
  - map_type_exact_name/1
  - map_type_exact_value/1
  - map_type_fields/1
  - match_expr/2
  - match_expr_body/1
  - match_expr_pattern/1
  - meta/1
  - module_qualifier/2
  - module_qualifier_argument/1
  - module_qualifier_body/1
  - named_fun_expr/2
  - named_fun_expr_arity/1
  - named_fun_expr_clauses/1
  - named_fun_expr_name/1
  - nil/0
  - normalize_list/1
  - operator/1
  - operator_literal/1
  - operator_name/1
  - parentheses/1
  - parentheses_body/1
  - prefix_expr/2
  - prefix_expr_argument/1
  - prefix_expr_operator/1
  - receive_expr/1
  - receive_expr/3
  - receive_expr_action/1
  - receive_expr_clauses/1
  - receive_expr_timeout/1
  - record_access/3
  - record_access_argument/1
  - record_access_field/1
  - record_access_type/1
  - record_expr/3
  - record_expr/2
  - record_expr_argument/1
  - record_expr_fields/1
  - record_expr_type/1
  - record_field/1
  - record_field/2
  - record_field_name/1
  - record_field_value/1
  - record_index_expr/2
  - record_index_expr_field/1
  - record_index_expr_type/1
  - record_type/2
  - record_type_field/2
  - record_type_field_name/1
  - record_type_field_type/1
  - record_type_fields/1
  - record_type_name/1
  - remove_comments/1
  - revert/1
  - revert_forms/1
  - set_ann/2
  - set_attrs/2
  - set_pos/2
  - set_postcomments/2
  - set_precomments/2
  - size_qualifier/2
  - size_qualifier_argument/1
  - size_qualifier_body/1
  - string/1
  - string_literal/1
  - string_literal/2
  - string_value/1
  - subtrees/1
  - text/1
  - text_string/1
  - tree/1
  - tree/2
  - try_after_expr/2
  - try_expr/3
  - try_expr/4
  - try_expr/2
  - try_expr_after/1
  - try_expr_body/1
  - try_expr_clauses/1
  - try_expr_handlers/1
  - tuple/1
  - tuple_elements/1
  - tuple_size/1
  - tuple_type/0
  - tuple_type/1
  - tuple_type_elements/1
  - type/1
  - type_application/3
  - type_application/2
  - type_application_arguments/1
  - type_application_name/1
  - type_union/1
  - type_union_types/1
  - typed_record_field/2
  - typed_record_field_body/1
  - typed_record_field_type/1
  - underscore/0
  - update_tree/2
  - user_type_application/2
  - user_type_application_arguments/1
  - user_type_application_name/1
  - variable/1
  - variable_literal/1
  - variable_name/1
  - warning_marker/1
  - warning_marker_info/1
- erl_syntax_lib
  - Top of manual page
  - analyze_application/1
  - analyze_attribute/1
  - analyze_export_attribute/1
  - analyze_file_attribute/1
  - analyze_form/1
  - analyze_forms/1
  - analyze_function/1
  - analyze_function_name/1
  - analyze_implicit_fun/1
  - analyze_import_attribute/1
  - analyze_module_attribute/1
  - analyze_record_attribute/1
  - analyze_record_expr/1
  - analyze_record_field/1
  - analyze_type_application/1
  - analyze_type_name/1
  - analyze_wild_attribute/1
  - annotate_bindings/1
  - annotate_bindings/2
  - fold/3
  - fold_subtrees/3
  - foldl_listlist/3
  - function_name_expansions/1
  - is_fail_expr/1
  - limit/2
  - limit/3
  - map/2
  - map_subtrees/2
  - mapfold/3
  - mapfold_subtrees/3
  - mapfoldl_listlist/3
  - new_variable_name/2
  - new_variable_name/1
  - new_variable_names/3
  - new_variable_names/2
  - strip_comments/1
  - to_comment/1
  - to_comment/2
  - to_comment/3
  - variables/1
- erl_tidy
  - Top of manual page
  - dir/0
  - dir/1
  - dir/2
  - file/1
  - file/2
  - module/1
  - module/2
- igor
  - Top of manual page
  - create_stubs/2
  - merge/2
  - merge/3
  - merge_files/3
  - merge_files/4
  - merge_sources/3
  - parse_transform/2
  - rename/2
  - rename/3
- merl
  - Top of manual page
  - alpha/2
  - compile/1
  - compile/2
  - compile_and_load/1
  - compile_and_load/2
  - match/2
  - meta_template/1
  - print/1
  - qquote/3
  - qquote/2
  - quote/2
  - quote/1
  - show/1
  - subst/2
  - switch/2
  - template/1
  - template_vars/1
  - term/1
  - tree/1
  - tsubst/2
  - var/1
- merl_transform
  - Top of manual page
  - parse_transform/2
- prettypr
  - Top of manual page
  - above/2
  - beside/2
  - best/3
  - break/1
  - empty/0
  - floating/1
  - floating/3
  - follow/2
  - follow/3
  - format/1
  - format/2
  - format/3
  - nest/2
  - null_text/1
  - par/1
  - par/2
  - sep/1
  - text/1
  - text_par/1
  - text_par/2

# erl_tidy

### MODULE

erl_tidy

### MODULE SUMMARY

Tidies and pretty-prints Erlang source code, removing unused functions, updating obsolete constructs and function calls, etc.

### DESCRIPTION

Tidies and pretty-prints Erlang source code, removing unused functions, updating obsolete constructs and function calls, etc.

Caveats: It is possible that in some intricate uses of macros, the automatic addition or removal of parentheses around uses or arguments could cause the resulting program to be rejected by the compiler; however, we have found no such case in existing code. Programs defining strange macros can usually not be read by this program, and in those cases, no changes will be made.

If you really, really want to, you may call it "Inga".

Disclaimer: The author accepts no responsibility for errors introduced in code that has been processed by the program. It has been reasonably well tested, but the possibility of errors remains. Keep backups of your original code safely stored, until you feel confident that the new, modified code can be trusted.

### DATA TYPES

filename() = file:filename()

syntaxTree() = erl_syntax:syntaxTree()

  An abstract syntax tree. See the erl_syntax module for details.

### EXPORTS

dir() -> ok

Equivalent to dir("").

dir(Dir) -> ok

Equivalent to dir(Dir, []).

dir(Directory::filename(), Options::[term()]) -> ok

Tidies Erlang source files in a directory and its subdirectories.

Available options:

{follow_links, boolean()}

  If the value is true, symbolic directory links will be followed. The default value is false.

{recursive, boolean()}

  If the value is true, subdirectories will be visited recursively. The default value is true.

{regexp, string()}

  The value denotes a regular expression (see module re). Tidying will only be applied to those regular files whose names match this pattern. The default value is ".*\\.erl$", which matches normal Erlang source file names.

{test, boolean()}

  If the value is true, no files will be modified. The default value is false.

{verbose, boolean()}

  If the value is true, progress messages will be output while the program is running, unless the quiet option is true. The default value when calling dir/2 is true.

See the function file/2 for further options.

See also: re(3), file/2.

file(Name) -> ok

Equivalent to file(Name, []).

file(Name::filename(), Options::[term()]) -> ok

Tidies an Erlang source code file.

Available options are:

{backup_suffix, string()}

  Specifies the file name suffix to be used when a backup file is created; the default value is ".bak" (cf. the backups option).

{backups, boolean()}

  If the value is true, existing files will be renamed before new files are opened for writing. The new names are formed by appending the string given by the backup_suffix option to the original name. The default value is true.

{dir, filename()}

  Specifies the name of the directory in which the output file is to be written. By default, the current directory is used. If the value is an empty string, the current directory is used.

{outfile, filename()}

  Specifies the name of the file (without suffix) to which the resulting source code is to be written. If this option is not specified, the Name argument is used.

{printer, Function}

  - Function = (syntaxTree(), [term()]) -> string()

  Specifies a function for prettyprinting Erlang syntax trees. This is used for outputting the resulting module definition. The function is assumed to return formatted text for the given syntax tree, and should raise an exception if an error occurs. The default formatting function calls erl_prettypr:format/2.

{test, boolean()}

  If the value is true, no files will be modified; this is typically most useful if the verbose flag is enabled, to generate reports about the program files without affecting them. The default value is false.

{stdout, boolean()}

  If the value is true, instead of the file being written to disk it will be printed to stdout. The default value is false.

See the function module/2 for further options.

See also: module/2, erl_prettypr:format/2.

module(Forms) -> syntaxTree()

Equivalent to module(Forms, []).

module(Forms, Options::[term()]) -> syntaxTree()

Types:

Forms = syntaxTree() | [syntaxTree()]

Tidies a syntax tree representation of a module definition. The given Forms may be either a single syntax tree of type form_list, or a list of syntax trees representing "program forms". In either case, Forms must represent a single complete module definition. The returned syntax tree has type form_list and represents a tidied-up version of the same source code.

Available options are:

{auto_export_vars, boolean()}

  If the value is true, all matches "{V1, ..., Vn} = E" where E is a case-, if- or receive-expression whose branches all return n-tuples (or explicitly throw exceptions) will be rewritten to bind and export the variables V1, ..., Vn directly. The default value is false.

  For example:

                       {X, Y} = case ... of
                                    ... -> {17, foo()};
                                    ... -> {42, bar()}
                                end

  will be rewritten to:

                       case ... of
                           ... -> X = 17, Y = foo(), {X, Y};
                           ... -> X = 42, Y = bar(), {X, Y}
                       end

{auto_list_comp, boolean()}

  If the value is true, calls to lists:map/2 and lists:filter/2 will be rewritten using list comprehensions. The default value is true.

{file, string()}

  Specifies the name of the file from which the source code was taken. This is only used for generation of error reports. The default value is the empty string.

{idem, boolean()}

  If the value is true, all options that affect how the code is modified are set to "no changes". For example, to only update guard tests, and nothing else, use the options [new_guard_tests, idem]. (Recall that options closer to the beginning of the list have higher precedence.)

{keep_unused, boolean()}

  If the value is true, unused functions will not be removed from the code. The default value is false.

{new_guard_tests, boolean()}

  If the value is true, guard tests will be updated to use the new names, e.g. "is_integer(X)" instead of "integer(X)". The default value is true. See also old_guard_tests.

{no_imports, boolean()}

  If the value is true, all import statements will be removed and calls to imported functions will be expanded to explicit remote calls. The default value is false.

{old_guard_tests, boolean()}

  If the value is true, guard tests will be changed to use the old names instead of the new ones, e.g. "integer(X)" instead of "is_integer(X)". The default value is false. This option overrides the new_guard_tests option.

{quiet, boolean()}

  If the value is true, all information messages and warning messages will be suppressed. The default value is false.

{rename, [{{atom(), atom(), integer()}, {atom(), atom()}}]}

  The value is a list of pairs, associating tuples {Module, Name, Arity} with tuples {NewModule, NewName}, specifying renamings of calls to remote functions. By default, the value is the empty list.

  The renaming affects only remote calls (also when disguised by import declarations); local calls within a module are not affected, and no function definitions are renamed. Since the arity cannot change, the new name is represented by {NewModule, NewName} only. Only calls matching the specified arity will match; multiple entries are necessary for renaming calls to functions that have the same module and function name, but different arities.

  This option can also be used to override the default renaming of calls which use obsolete function names.

{verbose, boolean()}

  If the value is true, progress messages will be output while the program is running, unless the quiet option is true. The default value is false.

Richard Carlsson carlsson.richard@gmail.com