mcandre
mcandre

Reputation: 24602

How do I use erl_tidy and erl_lint?

I know the docs explain these tools, but I don't understand the explanation. Can someone provide an example or two?

Upvotes: 3

Views: 1793

Answers (1)

Julian Fondren
Julian Fondren

Reputation: 5619

Of erl_tidy, the simplest way - and the most direct, if you have one running in your source directory all the time anyway, is to use it directly from Eshell, as in

$ erl
1> m(erl_tidy).
% output snipped
2> erl_tidy:dir().  % recursively tidy the present directory and its children
% output snipped
3> erl_tidy:dir("", [{recursive, false}]).  % just the present directory
reading module `./bad.erl'.
made backup of file `./bad.erl'.
writing to file `./bad.erl'.
4>

In this case, bad.erl went from

-module(bad).
-compile(export_all).

bad(0)->1;bad(1)->2;bad(N)->3.bad()->0.

to the tidied

-module(bad).

-compile(export_all).

bad ( 0 ) -> 1 ; bad ( 1 ) -> 2 ; bad ( N ) -> 3 . bad ( ) -> 0 .

... well, it's not a magician :-)

erl_tidy can also be invoked through arguments to erl, as in

$ # unix prompt
$ erl -s erl_tidy dir
tidying directory `./wesnoth'.
tidying directory `./wesnoth/Vix'.
tidying directory `./wesnoth/Vix/utils'.
...

erl_lint however is completely different. To understand how to use it, first understand what's going on in this string evaluation example. erl_lint is designed to act on an intermediate representation of Erlang source, not on strings of it.

Upvotes: 5

Related Questions