Codor icon indicating copy to clipboard operation
Codor copied to clipboard

Is it possible for tests to check which lines contained the error?

Open bmitch opened this issue 9 years ago • 5 comments

bmitch avatar Dec 20 '16 00:12 bmitch

Yeah, the line number is the key of the _errors array in PHP_CodeSniffer_File.

If you replace the foreach loop in the \Codor\Tests\Wrappers\Results::getAllErrorMessages() method like this:

foreach ($errors as $line => $error) {
    $allErrorMessages[] = "Error at line $line: " . reset($error)[0]['message'];
}

The output becomes this:

[
  0 => "Error at line 5: Return null value found."
  1 => "Error at line 21: Return null value found."
]

winkbrace avatar Dec 30 '16 08:12 winkbrace

Hmm, I just realised that you're logging the error with the $stackPtr of the scope start, not the index of the actual token that has an error. Currently error messages point to the start of functions instead of the actual line that contains the error.

I've updated my last PR to report return null errors with the correct stack pointer.

winkbrace avatar Dec 30 '16 10:12 winkbrace

Thanks, I'll take a look at this in the next few days when I have time. But if you feel like tackling it please go ahead.

bmitch avatar Dec 30 '16 17:12 bmitch

I think you should have a look at it first. The error messages would change with that implementation. And maybe you want to do something different with the lines.

Anyway, I'm on vacation starting now, so won't be programming (much) the coming week. Have a good new year! ;)

winkbrace avatar Dec 30 '16 17:12 winkbrace

OK thanks. You too!

bmitch avatar Dec 30 '16 18:12 bmitch