Problem/Motivation
Now that Gitlab is running for core its time to clean up how codequality is reported. Currently all code quality steps like esling, phpcs, phpstan, stylelint all al reported as "tests". Which is technically true, but its also possible to output those reports and have them reported in a separate tab. This would also allow showing the problems inline in the merge requests.
See: https://docs.gitlab.com/ee/ci/testing/code_quality.html#implement-a-cust...
Known issues.
We have Gitlab ultimate, so we COULD get inline errors in the mergerequests.
Unfortunately, it is only displayed on the child pipelines, this means no inline help on the MR... :disappointed: I was secretly already dreading if the child pipeline setup was going to make us run into some issues.
There is an open issue (for years) around this. But that doesnt seem to be close. We could have inline error messages in the pipeline, but not if we use childs. (https://gitlab.com/gitlab-org/gitlab/-/issues/215725).
Possible tools per lint step
The tools we use and how they could integrate into gitlab:
eslint
Add the flag --format gitlab
PHP Code Sniffer
No real support, but seems easy enough:
https://github.com/micheh/phpcs-gitlab or https://daniel-r-ness.medium.com/converting-phpcs-output-to-gitlab-codec...
PHPStan
phpstan analyze --error-format=gitlab
stylelint
https://github.com/leon0399/stylelint-formatter-gitlab
Dependency evaluation; all these are dev dependencies that do a single small task of converting tool output to a format GitLab can read, none of this is needed at runtime and will in effect only be executed on GitLab.
micheh/phpcs-gitlab
Release cycle: two releases in 2020, none since; both the plugin and the GitLab output format are stable and seemingly require no maintenance.
Security policy: none
Maintainer: Michel Hunziker https://github.com/micheh
eslint-formatter-gitlab
Release cycle: major releases approximately once a year, follows strict semver and updates when NodeJS is updated.
Security policy: none
Maintainer: Remco Haszing https://gitlab.com/remcohaszing
stylelint-formatter-gitlab
Release cycle: three releases in four years
Security policy: none
Maintainer: Leonid Meleshin https://gitlab.com/leon0399
Steps to reproduce
Run a pipeline, in the childpipeline there is a new Codequality tab. See draft MR for an mr with these changes and some real errors.
Proposed resolution
Add a few packages for the reports and export everything as codequality artifacts.
Remaining tasks
Implement PHPStan reportImplement PHPCS reportImplement eslint reportImplement stylelint report- Decide if the dependencies are ok like this
Follow up to investigate issue where child pipelines do not report codequality to their parents. See: https://gitlab.com/gitlab-org/gitlab/-/issues/215725
User interface changes
Tests tab in gitlab now only shows tests, new tab codequality with codequality issues.



API changes
Data model changes
Release notes snippet
Three new development dependencies provide GitLab-compatible output for PHP CodeSniffer, ESLint and Stylelint.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | Screenshot_20230916_182222_Chrome.jpg | 832.14 KB | bbrala |
| #12 | Screenshot from 2023-09-16 16-53-26.png | 173.69 KB | catch |
| #12 | Screenshot from 2023-09-16 16-52-12.png | 102.62 KB | catch |
Issue fork drupal-3387339
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
longwaveI also found
stylelint-formatter-gitlabover in #3386481: Add stylelint-junit-formatter to package.json, happy to merge that issue with this one.I think we should add the tools to composer.json/package.json as appropriate instead of adding them at build time.
Comment #4
cmlaraLinking the related feature request for this to be enabled in Contrib templates.
If these were to be installed as part of cores setup it would likely make contrib testing easier too.
Comment #5
andypostComment #7
bbralaComment #8
bbralaComment #9
bbralaPostponed on #3387503: Move Gitlab linting steps to main job
Comment #10
catchComment #11
bbralaReady for review and such again
Comment #12
catchNo substantive review but adding screenshots, what a difference from 'build successful' or 'custom commands failed'.
Comment #13
bbralaUpdated is.
Alsl added screenshot of the mr overview page, that already shows the cs issues also.
Comment #14
dwwThis is fantastic, thanks! Hope to review the code ASAP.
Comment #15
longwaveI think we should add the dependencies to composer.json and package.json.
Comment #16
longwaveThere are some other bits we can clean up now we are not providing junit output.
Comment #17
bbralaRemoved as suggested.
Comment #18
bbralaComment #19
longwaveDependency evaluation; all these are dev dependencies that do a single small task of converting tool output to a format GitLab can read, none of this is needed at runtime and will in effect only be executed on GitLab.
micheh/phpcs-gitlab
Release cycle: two releases in 2020, none since; both the plugin and the GitLab output format are stable and seemingly require no maintenance.
Security policy: none
Maintainer: Michel Hunziker https://github.com/micheh
eslint-formatter-gitlab
Release cycle: major releases approximately once a year, follows strict semver and updates when NodeJS is updated.
Security policy: none
Maintainer: Remco Haszing https://gitlab.com/remcohaszing
stylelint-formatter-gitlab
Release cycle: three releases in four years
Security policy: none
Maintainer: Leonid Meleshin https://gitlab.com/leon0399
Comment #20
catchNeeds a cspell change but otherwise looks good. Presumably adding this in the main yarn build will help with caching on gitlab a bit too.
Comment #21
catchLooks great to me. Going to make a massive difference to contributor experience.
Comment #23
catchCommitted/pushed to 11.x, thanks!
This doesn't cherry-pick cleanly to 10.1.x due to the yarn.lock changes - we'll need to decide whether to backport it or have it as 10.2.x-only. Might be better to backport in order to keep the yaml in sync so moving back for now.
Added the dependency evaluation to the issue summary.
Comment #24
bbralaYay it's in!
Backport will be a good idea imo. Not sure what the besta pproach for that would be though.
Comment #25
andypostIt caused regression in CI
stylelintandeslintjobs (which are using to override variables) are using PHP 8.1 image- https://git.drupalcode.org/project/drupal/-/jobs/104537
- https://git.drupalcode.org/project/drupal/-/jobs/104535
vs
- https://git.drupalcode.org/project/drupal/-/jobs/104536
- https://git.drupalcode.org/project/drupal/-/jobs/104538
Comment #26
andypostI mean the following section resetting
_TARGET_PHPvariableComment #27
fjgarlin commentedCorrect, it's completely overriding this section:
We could just add
ESLINT_CODE_QUALITY_REPORTandSTYLELINT_CODE_QUALITY_REPORTto thedefault-job-settings-linttemplate and remove those overrides from'🧹 CSS linting (stylelint)':and'🧹 JavaScript linting (eslint)':.Or we could use the
!reference [.default-job-settings, variables]syntax in the sections that override the variables.I think the first solution might be easier/cleaner.
Comment #28
longwaveI think we should not set those variables at all; the docs for both packages imply the variable is optional and it will try to discover the location from the pipeline YAML.
Comment #30
longwaveOpened MR!4840 to try this.
Comment #31
fjgarlin commentedEven better! Keeping an eye on the pipeline. If it works RTBC for the changes from my side.
Comment #32
longwaveI thought the code didn't take the working directory into account, but it appears that it does, so trying without the
exportto see if autodetection does work.Comment #33
fjgarlin commentedstylelint-quality-report.json: found 1 matching artifact files and directoriesandeslint-quality-report.json: found 1 matching artifact files and directoriesand the images are the php-8.2with the changes in the MR. The only thing now is removing the
KUBERNETES_CPU_REQUESTas this will be fixed upstream and is not needed in this MR.RTBC when that line goes away.
Comment #34
longwaveReverted, this may fail on GitLab CI because of the (unrelated) runner issue.
Comment #35
bbralaWe can inline, but i've looked at this also in another issue and we should probably decouple the vars. I'll search for my solution
Somethign like:
That should allow merging normally.
But the quick fix is still just the export inline.
Comment #36
bbralaI committed that in #3388162: Investigate realistic resource requests for core jobs, but haven't run the pipeline yet.
Comment #37
longwaveWe don't even need the export inline, both packages correctly autodetect the path as seen in the last-but-one successful run.
Comment #38
fjgarlin commentedYup, RTBC based on that indeed. Lines aren't needed at all.
Comment #40
catchCommitted/pushed to 11.x, thanks! Leaving open for backport again.
Comment #41
catch10.2.x was branched since this landed, and 10.1.x is security-only, so we can just leave this in 10.2.x