-
Notifications
You must be signed in to change notification settings - Fork 680
Report by issues grouped by level and type #8774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
$leftLevel = $left->error_level; | ||
$rightLevel = $right->error_level; | ||
|
||
if ($leftLevel != $rightLevel) { | ||
if ($rightLevel > 0 && $leftLevel > 0) { | ||
return $rightLevel <=> $leftLevel; | ||
} | ||
|
||
if ($rightLevel > 0) { | ||
return -1; | ||
} | ||
|
||
return $leftLevel <=> $rightLevel; | ||
} | ||
|
||
return $left->type <=> $right->type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it equivalent to return [$left->error_level, $left->type] <=> [$right->error_level, $right->type]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, I didn't realise you can use comparison operators with arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this was almost right, but not quite. complication is that negative levels sort to the top, small positive levels sort to the bottom.
…by level and type
Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
2aebebd
to
aea1c56
Compare
b18d502
to
3bc3f1c
Compare
I'm not sure why the composer update inside the Code Style Analysis job is failing - I don't think I've changed anything that should affect that. |
| The level at which issue is reported as an error is given in brackets - e.g. | | ||
| `ERROR (2): MissingReturnType` indicates that MissingReturnType is only reported | | ||
| as an error when Psalm's level is set to 4 or below. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it level 2 or level 4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's level 2, thanks for catching that. Fixed in 5423983.
ERROR: SomeAlwaysReportedIssueType - file.php:1:1 - message | ||
|
||
|
||
ERROR: SomeFeatureSpecificIssueType - file.php:1:1 - message | ||
|
||
|
||
ERROR (7): SomeLevel7IssueType - file.php:1:1 - message | ||
|
||
|
||
ERROR (4): AnotherLevel4IssueType - file.php:1:1 - message | ||
|
||
|
||
ERROR (4): SomeLevel4IssueType - file.php:1:1 - message | ||
|
||
|
||
ERROR (4): SomeLevel4IssueType - file.php:1:1 - message | ||
|
||
|
||
ERROR (2): SomeLevel2IssueType - file.php:1:1 - message | ||
|
||
|
||
ERROR (1): SomeIssueType - file.php:1:1 - message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a little sparse. Wouldn't it be more readable if we had 1 or two empty lines between levels and none between the issues of the same level?
ERROR: SomeAlwaysReportedIssueType - file.php:1:1 - message
ERROR: SomeFeatureSpecificIssueType - file.php:1:1 - message
ERROR (7): SomeLevel7IssueType - file.php:1:1 - message
ERROR (4): AnotherLevel4IssueType - file.php:1:1 - message
ERROR (4): SomeLevel4IssueType - file.php:1:1 - message
ERROR (4): SomeLevel4IssueType - file.php:1:1 - message
ERROR (2): SomeLevel2IssueType - file.php:1:1 - message
ERROR (1): SomeIssueType - file.php:1:1 - message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically the same format as the console report, it just looks sparse in the test because the code snippets are empty. I considered adding a separator between levels but I thought it's probably not worth it. Users should be a be able to do a search for whatever level they're interested in if they want to highlight it in their shell or editor.
|
||
|
||
|
||
EXPECTED, $report->create()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW now that we require PHP >7.3 you can indent the heredoc terminator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I think we need to add an explicit |
I think it makes more sense to have the errors that almost always appear (level 7 errors) next to the errors that always appear, instead of the level 1, least likely to appear errors being next to the ones that always appear. This also makes the order more similar to that output by the new --by-issue-level format report. Some time it might be nice to see if there's a way to auto generate most of this docs page from the actual issue class definitions, or have a test that checks the list of issues for each level is accurate and complete.
…vel & type equal PHP sorting only became stable in 8.0. For previous versions we would still like duplicate issues to be sorted into a logical order.
@bdsl the |
#8746
This adds a new output format,
--output-format=by-issue-level
, which is almost exactly the same as the default console output, except that:ERROR (3): PossiblyNullArgument
This is intended to be useful for getting an overview of a project, particularly when onboarding Psalm to a new codebase, and for choosing what error level to set in psalm config. The most severe errors (plus any reported due to feature specific config) appear first in the output, with the issues that would only be reported at error level 1 appearing at the end.
I wasn't sure where to document this, so for now I've made the report include a block of explanation as a heading. Happy to move that text to a more appropriate place.