Output JUnit XML reports of stylelint results for Gitlab CI.
Output JUnit XML reports of Stylelint results for Gitlab CI.
Based on https://github.com/eddies/stylelint-junit-formatter, slightly adapted for Gitlab CI.
Install stylelint-gitlabci-formatter (and stylelint and optionally, a config):
``shell`
npm install stylelint-gitlabci-formatter stylelint stylelint-config-standard --save-dev
Add a .stylelintrc, e.g.:
`javascript`
{
"extends": "stylelint-config-standard",
"ignoreFiles": "node_modules/*/",
}
Add a script to package.json that runs stylelint, e.g.:
`json`
{
"name": "stylelint-ci",
"version": "1.0.0",
"scripts": {
"lint": "stylelint '*/.css'"
},
"devDependencies": {
"stylelint": "^16",
"stylelint-gitlabci-formatter": "^1"
}
}
At this point, you should be able to execute npm run lint on the command line.
Add a .gitlab-ci.yml that runs stylelint and saves the results, e.g.:
`yaml
stylelint:
stage: lint
image: node:lts-alpine
before_script:
- npm install
script:
- npx stylelint
--custom-formatter ./node_modules/stylelint-gitlabci-formatter
--output-file stylelint_junit.xml
"*/.css"
artifacts:
expire_in: 1 week
when: always
# https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsjunit
reports:
junit: stylelint_junit.xml
`
The formatter will generate a .xml-report with the following look:
`xml`
In the event of errors, those are presented in a way that Gitlab CI can interpret:
`xml``