mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.94k stars 204 forks source link

PHPInsights parse error #624

Closed Rasmus-Bertell closed 2 weeks ago

Rasmus-Bertell commented 2 months ago

I get the following when trying to use PHPInsights with my project

 Diagnostics:
 1. Parser failed. Error message:
    ...are/nvim/lazy/nvim-lint/lua/lint/linters/phpinsights.lua:28: attempt to perform arithmetic on field 'line' (a nil value)

    Output from linter:
    {"summary":{"code":100,"complexity":100,"architecture":94.1,"style":100,"security issues":0,"fixed issues":0},"Code":[],"Compl
 exity":[],"Architecture":[{"title":"Normal classes are forbidden. Classes must be final or abstract","insightClass":"NunoMaduro\\
 PhpInsights\\Domain\\Insights\\ForbiddenNormalClasses","file":"User.php"}],"Style":[],"Security":[]}

This error originates from here

https://github.com/mfussenegger/nvim-lint/blob/efc6fc83f0772283e064c53a8f9fb5645bde0bc0/lua/lint/linters/phpinsights.lua#L28

Seems like the parser doesn't account for architecture messages and looking at the output I don't know if it can since there's no line number or message. Perhaps if the line number defaults to 1 when missing and message falls back to title if missing. I made a quick test and this seems to fix the issue, but I don't know if this is the "proper" way to fix it.

        table.insert(diagnostics, {
          lnum = (message.line or 1) - 1,
          col = 0,
          message = message.message or message.title,
          severity = severity,
          source = bin,
        })
z01cbrag commented 3 weeks ago

This approach worked well for me