nvim-lint
nvim-lint copied to clipboard
nvim-lint throws error when issue in Phpstan baseline is fixed/changed
- Create a new PHP project of some sort
- Install phpstan and configure nvim-lint
- Create some phpstan error in a file
- Generate a baseline
- Open Neovim and change the code which is in the baseline
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
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: