Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-> at the beginning of the line makes the linter crash #183

Closed
robertoaloi opened this issue Mar 13, 2021 · 1 comment · Fixed by #184
Closed

-> at the beginning of the line makes the linter crash #183

robertoaloi opened this issue Mar 13, 2021 · 1 comment · Fixed by #184
Labels

Comments

@robertoaloi
Copy link
Contributor

The following code:

-spec wait_for_fun(term(), non_neg_integer(), non_neg_integer())
-> {ok, any()} | ok | timeout.

Causes the linter to fail with:

# apps/els_dap/test/els_dap_test_utils.erl [FAIL]
Error: 'function_clause' while applying rule 'operator_spaces'.

Moving the -> away from the beginning of the line solves the issue.

robertoaloi added a commit to erlang-ls/erlang_ls that referenced this issue Mar 13, 2021
@paulo-ferraz-oliveira
Copy link
Collaborator

Issue is in this function:

-spec character_at_location(Position::atom(),
                            Lines::[binary()],
                            Operator::string(),
                            Location::{integer(), integer()},
                            Encoding::latin1|utf8) -> char().
character_at_location(Position, Lines, Operator, {LineNo, Col}, Encoding) ->
    Line = lists:nth(LineNo, Lines),
    OperatorLineStr = unicode:characters_to_list(Line, Encoding),
    ColToCheck = case Position of
        left  -> Col - 1;
        right -> Col + length(Operator)
    end,
    % If ColToCheck is greater than the length of OperatorLineStr variable, it
    % means the end of line was reached so return " " to make the check pass,
    % otherwise return the character at the given column.
    % NOTE: text below only applies when the given Position is equal to `right`.
    SpaceChar = $\s,
    case {Position, (ColToCheck > length(OperatorLineStr))} of
        {right, true}  -> SpaceChar;
        _ -> lists:nth(ColToCheck, OperatorLineStr)
    end.

I'll try to fix soon.

robertoaloi added a commit to erlang-ls/erlang_ls that referenced this issue Mar 13, 2021
* Upgrade linter (elvis_core, rebar3_lint)
* Fetch linter from Hex rather than git
* Run linter via its plugin and not as a compiler hook
* Fix current linting issues
* Update Elvis config in test application

Found an elvis_core bug: inaka/elvis_core#183

Not using wildcards for `dirs` in the Elvis config, since they are
still not supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants