如何使用 erl_tidy 和 erl_lint?

mca*_*dre 3 erlang lint

我知道文档解释了这些工具,但我不明白解释。有人可以提供一两个例子吗?

Jul*_*ren 5

erl_tidy,最简单的方法 - 也是最直接的,如果你一直在你的源目录中运行一个,就是直接从 Eshell 使用它,如

$ 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>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,bad.erl

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

bad(0)->1;bad(1)->2;bad(N)->3.bad()->0.
Run Code Online (Sandbox Code Playgroud)

到整理好的

-module(bad).

-compile(export_all).

bad ( 0 ) -> 1 ; bad ( 1 ) -> 2 ; bad ( N ) -> 3 . bad ( ) -> 0 .
Run Code Online (Sandbox Code Playgroud)

...好吧,这不是魔术师:-)

erl_tidy也可以通过参数调用 to erl,如

$ # unix prompt
$ erl -s erl_tidy dir
tidying directory `./wesnoth'.
tidying directory `./wesnoth/Vix'.
tidying directory `./wesnoth/Vix/utils'.
...
Run Code Online (Sandbox Code Playgroud)

erl_lint然而完全不同。要了解如何使用它,首先要了解这个字符串评估示例中发生了什么erl_lint旨在作用于 Erlang 源的中间表示,而不是它的字符串。

  • 是的,要运行 erl_tidy 而不更改任何文件(仅打印有关更改的信息),请传递 'test' 或 '{test, true}' 作为选项。请注意,自从我编写此程序以来已经很长时间了,因此它没有做很多事情。Tidier (http://tidier.softlab.ntua.gr/mediawiki/index.php/Main_Page) 功能更强大。 (2认同)