[erlang-questions] Attempting to use erl_lint on a .erl source file

Steve Vinoski vinoski@REDACTED
Fri Dec 18 03:32:40 CET 2015


On Thu, Dec 17, 2015 at 1:45 PM, Sparr <sparr0@REDACTED> wrote:

> I'm trying to use erl_lint() to build a simple Erlang syntax and style
> checker. I've gotten far enough to load the file and parse it into Forms
> and to get erl_lint to partially understand it, but then erl_lint complains
> about undefined functions that are defined. What am I doing wrong?
>
> erlint.erl :
>
>     -module(erlint).
>     -export([lint/1]).
>
>     % based on http://stackoverflow.com/a/28086396/13675
>
>     lint(File) ->
>         {ok, B} = file:read_file(File),
>         Forms = scan(erl_scan:tokens([],binary_to_list(B),1),[]),
>         F = fun(X) -> {ok,Y} = erl_parse:parse_form(X), Y end,
>         erl_lint:module([F(X) || X <- Forms],File).
>
>     scan({done,{ok,T,N},S},Res) ->
>         scan(erl_scan:tokens([],S,N),[T|Res]);
>     scan(_,Res) ->
>         lists:reverse(Res).
>
> hello.erl :
>
>     -module(hello).
>     -export([hello_world/0]).
>
>     hello_world() -> io:fwrite("hello, world\n").
>
> attempt to use :
>
>     1> c(erlint).
>     {ok,erlint}
>     2> erlint:lint("hello.erl").
>     {error,[{"hello.erl",
>              [{2,erl_lint,{undefined_function,{hello_world,0}}}]}],
>            []}
>

I copied both erlint and hello directly out of your email, pasted them into
source modules, compiled erlint, and ran erlint:lint("hello.erl"), same as
you show. It returned {ok,[]}. I then changed the first double quote in
hello.erl to a single quote to introduce an obvious syntax error, and
retried. That gave me the same result you're seeing, which makes sense
because the module is exporting a function that it never defines due to the
syntax error. You might want to check your hello.erl source, or just try to
compile it, to make sure its contents are correct.

--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151217/b696681d/attachment.htm>


More information about the erlang-questions mailing list