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

Sparr sparr0@REDACTED
Thu Dec 17 19:45:13 CET 2015


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}}}]}],
           []}

PS: This is a cross post after posting on reddit and stackoverflow.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151217/05f62cf8/attachment.htm>


More information about the erlang-questions mailing list