eslint-formatter-gitlab (original) (raw)

ESLint Formatter for GitLab

gitlab pipeline code coverage sponsors npm version npm downloads

Show ESLint results directly in theGitLab code quality results.

Table of Contents

Installation

Install eslint and eslint-formatter-gitlab using your package manager.

npm install --save-dev eslint eslint-formatter-gitlab

Usage

Define a GitLab job to run eslint.

.gitlab-ci.yml:

eslint: image: node:20-alpine script: - npm ci - npx eslint --format gitlab . artifacts: reports: codequality: gl-codequality.json

The formatter automatically detects a GitLab CI environment. It detects where to output the code quality report based on the GitLab configuration file. It also prints ESLint issues to the GitLab job console with links.

Programmatic usage

The formatter can be used programmatically using ESLint.

import { ESLint } from 'eslint'

const eslint = new ESLint() const formatter = await eslint.loadFormatter('gitlab') const results = await eslint.lintFiles([]) const formatted = await formatter.format(results)

Example

An example of the results can be seen inMerge Request !1 ofeslint-formatter-gitlab itself.

Configuration

ESLint formatters don’t take any configuration options. eslint-formatter-gitlab uses GitLab’spredefined environment variablesto configure the output. The following predefined environment variables are used:

In addition, the environment variable ESLINT_CODE_QUALITY_REPORT is used to override the location to store the code quality report.

Compatibility

This package is compatible with Node.js 20 or greater and ESLint 9 or greater.

License

MIT © Remco Haszing