tonyhffong / Lint.jl

A lint tool for Julia code
Other
168 stars 33 forks source link

Line numbers off by one #247

Open goerz opened 6 years ago

goerz commented 6 years ago

The line numbers reported by the linter consistenly seem off by one, For example, when I do

julia> lintfile("./run_single_node.jl")

it reports things like

./run_single_node.jl:230 E321 new_basis: use of undeclared symbol

when new_basis is in fact used in line 229. The same is true for all other messages.

Actually, I also don't understand what Lint is complaining about in regards to new_basis, as it is an argument to the funtion that contains line 229:

"""
Pad the given `state` defined on `basis` with zeroes in order to fit on
`new_basis`

The `state` is assumed to be a concatenation of `pdim` classical paramters,
followed by `n_hilbert` entries giving the complex amplitude for each basis
state in `basis`. The output will contain the first `pdim` entries unchanged.
"""
function resize_state(state::Array, basis::Basis, new_basis::Basis):: Array
    n_hilbert = prod(basis.dims)
    new_n_hilbert = prod(new_basis.dims)   # this is line 229
    pdim = length(state) - n_hilbert
    @assert length(new_basis.dims) == length(basis.dims)
    @assert new_basis.dims >= basis.dims
    new_state = zeros(Complex128, pdim + new_n_hilbert)
    new_state[1:pdim] = state[1:pdim]
    j = 0
    for (i, etuple) in enumerate(basis.e)
    j += 1
    new_etuple = new_basis.e[j]
    while new_etuple != etuple
        j += 1
        new_etuple = new_basis.e[j]
    end
    new_state[pdim + j] = state[pdim + i]
    end
    return new_state
end

I wonder if it's being thrown off by the docstring, because it also says

run_single_node.jl:219 E131 resize_state(state::Array, basis::Basis, new_basis::Basis): Lint does not understand argument #1

about the line that starts the docstring.

TotalVerb commented 6 years ago

I think Lint doesn't understand return type annotations. I had a (slightly stale) PR addressing that, but it's not quite done.

As for the lines, I think that might be partially a limitation of how we are parsing the code to lint. Eventually we want to migrate to a multi-layer linter starting at the CST layer, but there is a lot of work to be done to get there, and recently this package has gone somewhat undermaintained.