eslint-formatter-gitlab 7.1.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,6 +15,8 @@ Show ESLint results directly in the
15
15
 
16
16
  - [Installation](#installation)
17
17
  - [Usage](#usage)
18
+ - [GitLab CI](#gitlab-ci)
19
+ - [CLI](#cli)
18
20
  - [Programmatic usage](#programmatic-usage)
19
21
  - [Example](#example)
20
22
  - [Configuration](#configuration)
@@ -31,6 +33,8 @@ npm install --save-dev eslint eslint-formatter-gitlab
31
33
 
32
34
  ## Usage
33
35
 
36
+ ### GitLab CI
37
+
34
38
  Define a GitLab job to run `eslint`.
35
39
 
36
40
  `.gitlab-ci.yml`:
@@ -50,9 +54,19 @@ The formatter automatically detects a GitLab CI environment. It detects where to
50
54
  quality report based on the GitLab configuration file. It also prints ESLint issues to the GitLab
51
55
  job console with links.
52
56
 
57
+ ### CLI
58
+
59
+ Specify the `gitlab` formatter when running `eslint` from the command line.
60
+
61
+ ```sh
62
+ npx eslint --format gitlab
63
+ ```
64
+
53
65
  ### Programmatic usage
54
66
 
55
- The formatter can be used programmatically using ESLint.
67
+ You probably want to use
68
+ [`eslint-formatter-codeclimate`](https://github.com/remcohaszing/eslint-formatter-codeclimate)
69
+ instead. But if you must, you can load the `gitlab` formatter like this using ESLint.
56
70
 
57
71
  ```js
58
72
  import { ESLint } from 'eslint'
@@ -43,12 +43,22 @@ async function getOutputPath(projectDir, jobName) {
43
43
  { cause }
44
44
  )
45
45
  }
46
- const doc = yaml.parseDocument(configContents, {
46
+ // A GitLab CI configuration file may start with a header document.
47
+ // https://docs.gitlab.com/ci/yaml/#header-keywords
48
+ const docs = yaml.parseAllDocuments(configContents, {
47
49
  version: '1.1',
48
50
  customTags: [reference]
49
51
  })
50
52
  const path = [jobName, 'artifacts', 'reports', 'codequality']
51
- const location = doc.getIn(path)
53
+
54
+ /** @type {unknown} */
55
+ let location
56
+ for (const doc of docs) {
57
+ location = doc.getIn(path)
58
+ if (location != null) {
59
+ break
60
+ }
61
+ }
52
62
  if (typeof location !== 'string' || !location) {
53
63
  throw new TypeError(
54
64
  `Expected ${path.join('.')} to be one exact path, got: ${JSON.stringify(location)}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-formatter-gitlab",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "Show ESLint results directly in the GitLab code quality results",
5
5
  "type": "module",
6
6
  "author": "Remco Haszing <remcohaszing@gmail.com>",
@@ -1 +1 @@
1
- {"version":3,"file":"eslint-formatter-gitlab.d.ts","sourceRoot":"","sources":["../lib/eslint-formatter-gitlab.js"],"names":[],"mappings":";AAyJA;;;;;;;GAOG;AACH,gDAPW,iBAAiB,EAAE,QAEnB,qBAAqB,GAEnB,OAAO,CAAC,MAAM,CAAC,CAwB3B;4BApL0B,QAAQ"}
1
+ {"version":3,"file":"eslint-formatter-gitlab.d.ts","sourceRoot":"","sources":["../lib/eslint-formatter-gitlab.js"],"names":[],"mappings":";AAmKA;;;;;;;GAOG;AACH,gDAPW,iBAAiB,EAAE,QAEnB,qBAAqB,GAEnB,OAAO,CAAC,MAAM,CAAC,CAwB3B;4BA9L0B,QAAQ"}