-
Notifications
You must be signed in to change notification settings - Fork 540
Include identifier in gitlab
error format
#4421
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
base: 2.1.x
Are you sure you want to change the base?
Conversation
I think you should ask GitLab support first. |
GitLab specifies this in the documentation (https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format) :
Is the code quality report handled correctly if there is a NULL value for |
@Koretech10 It seems to me that |
I had some success with the following custom implementation: <?php declare(strict_types=1);
// See https://github.com/phpstan/phpstan-src/blob/1.12.32/src/Command/ErrorFormatter/GitlabErrorFormatter.php
namespace App\PHPStan;
use Nette\Utils\Json;
use PHPStan\Command\AnalysisResult;
use PHPStan\Command\ErrorFormatter\ErrorFormatter;
use PHPStan\Command\Output;
use PHPStan\File\RelativePathHelper;
/**
* @see https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html#implementing-a-custom-tool
*/
final readonly class GitLabWithIdentifiersErrorFormatter implements ErrorFormatter
{
public function __construct(
private RelativePathHelper $relativePathHelper,
) {}
public function formatErrors(AnalysisResult $analysisResult, Output $output): int
{
$errorsArray = [];
foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) {
$error = [
'description' => "{$fileSpecificError->getIdentifier()}: {$fileSpecificError->getMessage()}",
... services:
errorFormatter.gitLabWithIdentifiers:
class: App\PHPStan\GitLabWithIdentifiersErrorFormatter ![]() @ondrejmirtes Given the |
Please ask GitLab support first and then get back. Thanks. |
I did submit a GitLab support request (for my own reference: https://support.gitlab.com/hc/en-us/requests/662951), and am now awaiting feedback. |
GitLab support did answer and sent me a link to https://gitlab.com/gitlab-org/gitlab/-/merge_requests/117402, which introduces both the documentation and usafe of |
As described in the example in https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format: ```json [ { "description": "'unused' is assigned a value but never used.", "check_name": "no-unused-vars", "fingerprint": "7815696ecbf1c96e6894b779456d330e", "severity": "minor", "location": { "path": "lib/index.js", "lines": { "begin": 42 } } } ] ```
e1c705f
to
9cea543
Compare
So what's this code quality scan widget? How can PHPStan make one? |
The code quality scan widget is just one of a couple of ways that GitLab has to show the results of a code quality report. The role of PHPStan is only to produce the code quality report file, and I believe it should deliver information that is as accurate (already the case) and complete (missing field added through this pull request) as possible. The role of GitLab is then to take that report and display the information within in a useful and hopefully also complete way - that part currently seems bugged, but I plan to fix it in GitLab itself. |
In regards to the GitLab documentation - the widget is described here: https://docs.gitlab.com/ci/testing/code_quality/#merge-request-widget. The part that concerns PHPStan is described here: https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format. The |
So this code quality scan widget already appears for PHPStan? If not, what makes it do appear for eslint but not for PHPStan? I'm asking because I don't want to merge PR that's essentially noop today, and I generally want to improve the experience for GitLab PHPStan users. |
As described in the example in https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format: