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.76k stars 191 forks source link

nvim-lint throws error when issue in Phpstan baseline is fixed/changed #581

Closed madflow closed 1 month ago

madflow commented 1 month ago

you will get:

 │     Parser failed. Error message:  [1, 1]
 │      ...l/share/nvim/lazy/nvim-lint/lua/lint/linters/phpstan.lua:29: attempt to perform arithmetic on field 'line' (a userdata value) 
 │       
 │      Output from linter: 
 │      {"totals":{"errors":0,"file_errors":1},"files":{"/private/tmp/actor/src/Kernel.php":{"errors":1,"messages":[{"message":"Ignored error pattern #^Method App\\\\Kernel\\:\\:fux\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$# in path /private/tmp/actor/src/Kernel.php was not matched in reported errors.","line":null,"ignorable":false}]}},"errors":[]} 
<?php

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    public function fux(array $array)
    {

    }
}
# phpstan-baseline.neon
parameters:
        ignoreErrors:
                -
                        message: "#^Method App\\\\Kernel\\:\\:fux\\(\\) has no return type specified\\.$#"
                        count: 1
                        path: src/Kernel.php

                -
                        message: "#^Method App\\\\Kernel\\:\\:fux\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#"
                        count: 1
                        path: src/Kernel.php

Kapture 2024-05-13 at 18 50 02

madflow commented 1 month ago

So as far as I can see, this is due to the fact, that phpstan does not yield a line numer for baseline errors.

 ------ --------------------------------------------------------------
  Line   Controller/SomeController.php
 ------ --------------------------------------------------------------
  5      Method SomeController::index() has no return type specified.
 ------ --------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Kernel.php
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Method App\\Kernel\:\:knall\(\) has no return type specified\.$# in path /private/tmp/actor/src/Kernel.php was not matched in reported errors.
         Ignored error pattern #^Method App\\Kernel\:\:knall\(\) has parameter \$options with no value type specified in iterable type array\.$# in path /private/tmp/actor/src/Kernel.php
         was not matched in reported errors.
 ------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 [ERROR] Found 3 errors

Would it be feasible to set the line number to "0", if there is none?

When I hackfix this like this with stackoverflowed Lua:

    for _, message in ipairs(file.messages or {}) do
      local line = 0
      if type(message.line) == "number" then
        line = message.line - 1
      end
      table.insert(diagnostics, {
        lnum = line,
        col = 0,
        message = message.message,
        source = bin,
      })
    end

I get a better result:

grafik