eslint-formatter-gitlab 5.0.0 → 5.1.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/index.d.ts +11 -0
- package/index.d.ts.map +1 -0
- package/index.js +65 -46
- package/package.json +7 -6
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export = eslintFormatterGitLab;
|
|
2
|
+
/**
|
|
3
|
+
* @param {import('eslint').ESLint.LintResult[]} results
|
|
4
|
+
* The ESLint report results.
|
|
5
|
+
* @param {import('eslint').ESLint.LintResultData} data
|
|
6
|
+
* The ESLint report result data.
|
|
7
|
+
* @returns {string}
|
|
8
|
+
* The ESLint output to print to the console.
|
|
9
|
+
*/
|
|
10
|
+
declare function eslintFormatterGitLab(results: import('eslint').ESLint.LintResult[], data: import('eslint').ESLint.LintResultData): string;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";AA0PA;;;;;;;GAOG;AACH,gDAPW,OAAO,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAE,QAEpC,OAAO,QAAQ,EAAE,MAAM,CAAC,cAAc,GAEpC,MAAM,CAmBlB"}
|
package/index.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import('eslint').ESLint.LintResult} LintResult
|
|
3
|
-
* @typedef {import('eslint').ESLint.LintResultData} LintResultData
|
|
4
|
-
* @typedef {import('eslint').Linter.LintMessage} LintMessage
|
|
5
|
-
* @typedef {import('codeclimate-types').Issue} Issue
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
1
|
const { createHash } = require('node:crypto')
|
|
9
2
|
const { existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } = require('node:fs')
|
|
10
3
|
const { EOL } = require('node:os')
|
|
@@ -23,9 +16,7 @@ const {
|
|
|
23
16
|
GITLAB_CI
|
|
24
17
|
} = process.env
|
|
25
18
|
|
|
26
|
-
/**
|
|
27
|
-
* @type {yaml.CollectionTag}
|
|
28
|
-
*/
|
|
19
|
+
/** @type {yaml.CollectionTag} */
|
|
29
20
|
const reference = {
|
|
30
21
|
tag: '!reference',
|
|
31
22
|
collection: 'seq',
|
|
@@ -36,7 +27,8 @@ const reference = {
|
|
|
36
27
|
}
|
|
37
28
|
|
|
38
29
|
/**
|
|
39
|
-
* @returns {string}
|
|
30
|
+
* @returns {string}
|
|
31
|
+
* The output path of the code quality artifact.
|
|
40
32
|
*/
|
|
41
33
|
function getOutputPath() {
|
|
42
34
|
const configPath = join(CI_PROJECT_DIR, CI_CONFIG_PATH)
|
|
@@ -64,10 +56,14 @@ function getOutputPath() {
|
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
/**
|
|
67
|
-
* @param {string} filePath
|
|
68
|
-
*
|
|
69
|
-
* @param {
|
|
70
|
-
*
|
|
59
|
+
* @param {string} filePath
|
|
60
|
+
* The path to the linted file.
|
|
61
|
+
* @param {import('eslint').Linter.LintMessage} message
|
|
62
|
+
* The ESLint report message.
|
|
63
|
+
* @param {Set<string>} hashes
|
|
64
|
+
* Hashes already encountered. Used to avoid duplicate hashes
|
|
65
|
+
* @returns {string}
|
|
66
|
+
* The fingerprint for the ESLint report message.
|
|
71
67
|
*/
|
|
72
68
|
function createFingerprint(filePath, message, hashes) {
|
|
73
69
|
const md5 = createHash('md5')
|
|
@@ -95,12 +91,15 @@ function createFingerprint(filePath, message, hashes) {
|
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
/**
|
|
98
|
-
* @param {LintResult[]} results
|
|
99
|
-
*
|
|
100
|
-
* @
|
|
94
|
+
* @param {import('eslint').ESLint.LintResult[]} results
|
|
95
|
+
* The ESLint report results.
|
|
96
|
+
* @param {import('eslint').ESLint.LintResultData} data
|
|
97
|
+
* The ESLint report result data.
|
|
98
|
+
* @returns {import('codeclimate-types').Issue[]}
|
|
99
|
+
* The ESLint messages in the form of a GitLab code quality report.
|
|
101
100
|
*/
|
|
102
101
|
function convert(results, data) {
|
|
103
|
-
/** @type {Issue[]} */
|
|
102
|
+
/** @type {import('codeclimate-types').Issue[]} */
|
|
104
103
|
const messages = []
|
|
105
104
|
|
|
106
105
|
/** @type {Set<string>} */
|
|
@@ -110,7 +109,7 @@ function convert(results, data) {
|
|
|
110
109
|
const relativePath = relative(CI_PROJECT_DIR, result.filePath)
|
|
111
110
|
|
|
112
111
|
for (const message of result.messages) {
|
|
113
|
-
/** @type {Issue} */
|
|
112
|
+
/** @type {import('codeclimate-types').Issue} */
|
|
114
113
|
const issue = {
|
|
115
114
|
type: 'issue',
|
|
116
115
|
categories: ['Style'],
|
|
@@ -126,26 +125,36 @@ function convert(results, data) {
|
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
|
-
|
|
130
|
-
const { docs, type } = data.rulesMeta[message.ruleId]
|
|
131
|
-
if (type === 'problem') {
|
|
132
|
-
issue.categories.unshift('Bug Risk')
|
|
133
|
-
}
|
|
128
|
+
messages.push(issue)
|
|
134
129
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
130
|
+
if (!message.ruleId) {
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!data.rulesMeta[message.ruleId]) {
|
|
135
|
+
continue
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const { docs, type } = data.rulesMeta[message.ruleId]
|
|
139
|
+
if (type === 'problem') {
|
|
140
|
+
issue.categories.unshift('Bug Risk')
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!docs) {
|
|
144
|
+
continue
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let body = docs.description || ''
|
|
148
|
+
if (docs.url) {
|
|
149
|
+
if (body) {
|
|
150
|
+
body += '\n\n'
|
|
146
151
|
}
|
|
152
|
+
body += `[${message.ruleId}](${docs.url})`
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (body) {
|
|
156
|
+
issue.content = { body }
|
|
147
157
|
}
|
|
148
|
-
messages.push(issue)
|
|
149
158
|
}
|
|
150
159
|
}
|
|
151
160
|
return messages
|
|
@@ -154,18 +163,22 @@ function convert(results, data) {
|
|
|
154
163
|
/**
|
|
155
164
|
* Make a text singular or plural based on the count.
|
|
156
165
|
*
|
|
157
|
-
* @param {number} count
|
|
158
|
-
*
|
|
159
|
-
* @
|
|
166
|
+
* @param {number} count
|
|
167
|
+
* The count of the data.
|
|
168
|
+
* @param {string} text
|
|
169
|
+
* The text to make singular or plural.
|
|
170
|
+
* @returns {string}
|
|
171
|
+
* The formatted text.
|
|
160
172
|
*/
|
|
161
173
|
function plural(count, text) {
|
|
162
174
|
return `${count} ${text}${count === 1 ? '' : 's'}`
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
/**
|
|
166
|
-
* @param {LintResult[]} results
|
|
167
|
-
*
|
|
168
|
-
*
|
|
178
|
+
* @param {import('eslint').ESLint.LintResult[]} results
|
|
179
|
+
* The ESLint report results.
|
|
180
|
+
* @returns {string}
|
|
181
|
+
* The ESLint messages converted to a format suitable as output in GitLab CI job logs.
|
|
169
182
|
*/
|
|
170
183
|
function gitlabConsoleFormatter(results) {
|
|
171
184
|
// Severity labels manually padded to have equal lengths and end with spaces
|
|
@@ -236,10 +249,14 @@ function gitlabConsoleFormatter(results) {
|
|
|
236
249
|
}
|
|
237
250
|
|
|
238
251
|
/**
|
|
239
|
-
* @param {LintResult[]} results
|
|
240
|
-
*
|
|
252
|
+
* @param {import('eslint').ESLint.LintResult[]} results
|
|
253
|
+
* The ESLint report results.
|
|
254
|
+
* @param {import('eslint').ESLint.LintResultData} data
|
|
255
|
+
* The ESLint report result data.
|
|
256
|
+
* @returns {string}
|
|
257
|
+
* The ESLint output to print to the console.
|
|
241
258
|
*/
|
|
242
|
-
|
|
259
|
+
function eslintFormatterGitLab(results, data) {
|
|
243
260
|
/* c8 ignore start */
|
|
244
261
|
if (GITLAB_CI === 'true') {
|
|
245
262
|
chalk.level = 1
|
|
@@ -256,3 +273,5 @@ module.exports = (results, data) => {
|
|
|
256
273
|
|
|
257
274
|
return gitlabConsoleFormatter(results)
|
|
258
275
|
}
|
|
276
|
+
|
|
277
|
+
module.exports = eslintFormatterGitLab
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-formatter-gitlab",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Show ESLint results directly in the GitLab code quality results",
|
|
5
5
|
"author": "Remco Haszing <remcohaszing@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
"bugs": "https://gitlab.com/remcohaszing/eslint-formatter-gitlab/-/issues",
|
|
11
11
|
"exports": "./index.js",
|
|
12
12
|
"files": [
|
|
13
|
-
"index
|
|
13
|
+
"index.*"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
+
"prepack": "tsc --build",
|
|
16
17
|
"test": "c8 node --test --test-reporter @reporters/junit --test-reporter-destination=junit.xml --test-reporter spec --test-reporter-destination stdout"
|
|
17
18
|
},
|
|
18
19
|
"keywords": [
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"yaml": "^2.0.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"eslint": "
|
|
31
|
+
"eslint": ">=5"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@reporters/junit": "^1.0.0",
|
|
@@ -36,10 +37,10 @@
|
|
|
36
37
|
"c8": "^8.0.0",
|
|
37
38
|
"codeclimate-types": "^0.3.0",
|
|
38
39
|
"eslint": "^8.0.0",
|
|
39
|
-
"eslint-config-remcohaszing": "^
|
|
40
|
-
"prettier": "^
|
|
40
|
+
"eslint-config-remcohaszing": "^10.0.0",
|
|
41
|
+
"prettier": "^3.0.0",
|
|
41
42
|
"remark-cli": "^11.0.0",
|
|
42
|
-
"remark-preset-remcohaszing": "^
|
|
43
|
+
"remark-preset-remcohaszing": "^2.0.0",
|
|
43
44
|
"typescript": "^5.0.0"
|
|
44
45
|
}
|
|
45
46
|
}
|