@darksheep/eslint-formatter-github 0.0.1 โ 2.0.1
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/CHANGELOG.md +56 -0
- package/package.json +6 -6
- package/src/index.js +74 -40
- package/types/index.d.ts +0 -23
package/CHANGELOG.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [2.0.1](https://github.com/DarkSheepSoftware/node-packages/compare/eslint-formatter-github-v2.0.0...eslint-formatter-github-v2.0.1) (2024-06-07)
|
4
|
+
|
5
|
+
|
6
|
+
### ๐ฆ Dependencies
|
7
|
+
|
8
|
+
* **dev:** update dependency @types/node to v20.14.1 ([#207](https://github.com/DarkSheepSoftware/node-packages/issues/207)) ([5ad7a75](https://github.com/DarkSheepSoftware/node-packages/commit/5ad7a75b29cf1fe8710a70f4179027ff7f156611))
|
9
|
+
|
10
|
+
|
11
|
+
### Dependencies
|
12
|
+
|
13
|
+
* The following workspace dependencies were updated
|
14
|
+
* dependencies
|
15
|
+
* @darksheep/github-actions bumped from 2.0.0 to 2.0.1
|
16
|
+
* @darksheep/package.json bumped from 2.0.0 to 2.0.1
|
17
|
+
|
18
|
+
## [2.0.0](https://github.com/DarkSheepSoftware/node-packages/compare/eslint-formatter-github-v1.0.0...eslint-formatter-github-v2.0.0) (2024-05-31)
|
19
|
+
|
20
|
+
|
21
|
+
### โ BREAKING CHANGES
|
22
|
+
|
23
|
+
* Drop node@^18
|
24
|
+
|
25
|
+
### ๐ก Features
|
26
|
+
|
27
|
+
* Bump to latest node lts versions ([#196](https://github.com/DarkSheepSoftware/node-packages/issues/196)) ([60a95cc](https://github.com/DarkSheepSoftware/node-packages/commit/60a95cc41b22c39428d35814c0d5e85830052a14))
|
28
|
+
* Drop node@^18 ([5f809a6](https://github.com/DarkSheepSoftware/node-packages/commit/5f809a6b2737db425cde55d58c22375ebcded687))
|
29
|
+
|
30
|
+
|
31
|
+
### ๐ฆ Dependencies
|
32
|
+
|
33
|
+
* **dev:** update dependency eslint to v9 ([#139](https://github.com/DarkSheepSoftware/node-packages/issues/139)) ([a01a119](https://github.com/DarkSheepSoftware/node-packages/commit/a01a119642704615386e37f2092801e08cf2f1b7))
|
34
|
+
|
35
|
+
|
36
|
+
### Dependencies
|
37
|
+
|
38
|
+
* The following workspace dependencies were updated
|
39
|
+
* dependencies
|
40
|
+
* @darksheep/github-actions bumped from 1.0.0 to 2.0.0
|
41
|
+
* @darksheep/package.json bumped from 1.0.0 to 2.0.0
|
42
|
+
|
43
|
+
## 1.0.0 (2024-04-22)
|
44
|
+
|
45
|
+
|
46
|
+
### ๐งน Miscellaneous Chores
|
47
|
+
|
48
|
+
* Move all packages to the packages directory ([6bc5f93](https://github.com/DarkSheepSoftware/node-packages/commit/6bc5f9395c80d8f7f1721c88a4923b7bc133e9c2))
|
49
|
+
|
50
|
+
|
51
|
+
### Dependencies
|
52
|
+
|
53
|
+
* The following workspace dependencies were updated
|
54
|
+
* dependencies
|
55
|
+
* @darksheep/github-actions bumped to 1.0.0
|
56
|
+
* @darksheep/package.json bumped to 1.0.0
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@darksheep/eslint-formatter-github",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.1",
|
4
4
|
"description": "ESLint + Github actions",
|
5
5
|
"license": "UNLICENCED",
|
6
6
|
"type": "commonjs",
|
@@ -16,16 +16,16 @@
|
|
16
16
|
"prepack": "tsc"
|
17
17
|
},
|
18
18
|
"dependencies": {
|
19
|
-
"@darksheep/github-actions": "
|
20
|
-
"@darksheep/package.json": "
|
19
|
+
"@darksheep/github-actions": "2.0.1",
|
20
|
+
"@darksheep/package.json": "2.0.1"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
|
-
"@darksheep/eslint": "~4.
|
24
|
-
"@types/node": "~20.
|
23
|
+
"@darksheep/eslint": "~4.4.0",
|
24
|
+
"@types/node": "~20.14.0",
|
25
25
|
"eslint": "~8.57.0",
|
26
26
|
"typescript": "~5.4.0"
|
27
27
|
},
|
28
28
|
"engines": {
|
29
|
-
"node": "^
|
29
|
+
"node": "^20.13.1 || ^22.2.0"
|
30
30
|
}
|
31
31
|
}
|
package/src/index.js
CHANGED
@@ -40,65 +40,99 @@ const {
|
|
40
40
|
* @property {number} fixableWarningCount
|
41
41
|
*/
|
42
42
|
|
43
|
+
/**
|
44
|
+
* @param {LintResult[]} fileResults The eslint results
|
45
|
+
* @returns {Record<'warningCount' | 'errorCount', number>}
|
46
|
+
*/
|
47
|
+
function counters(fileResults) {
|
48
|
+
let warningCount = 0;
|
49
|
+
let errorCount = 0;
|
50
|
+
|
51
|
+
for (const fileResult of fileResults) {
|
52
|
+
warningCount += fileResult.warningCount;
|
53
|
+
errorCount += fileResult.errorCount;
|
54
|
+
}
|
55
|
+
|
56
|
+
return {
|
57
|
+
warningCount,
|
58
|
+
errorCount,
|
59
|
+
};
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @param {LintResult} fileResult The eslint single file result
|
64
|
+
* @returns {string[]}
|
65
|
+
*/
|
66
|
+
function formatFileResult(fileResult) {
|
67
|
+
/** @type {string[]} */
|
68
|
+
const lines = [];
|
69
|
+
const filePath = path.relative(
|
70
|
+
GITHUB_WORKSPACE,
|
71
|
+
fileResult.filePath,
|
72
|
+
);
|
73
|
+
|
74
|
+
for (const result of fileResult.messages) {
|
75
|
+
const message = result.ruleId == null || result.ruleId === ''
|
76
|
+
? `[${result.ruleId}] ${result.message}`
|
77
|
+
: result.message;
|
78
|
+
|
79
|
+
/** @type {import('@darksheep/github-actions').LineAnnotation} */
|
80
|
+
const context = {
|
81
|
+
file: filePath,
|
82
|
+
line: result.line,
|
83
|
+
col: result.column,
|
84
|
+
endLine: result.endLine,
|
85
|
+
endColumn: result.endColumn,
|
86
|
+
};
|
87
|
+
|
88
|
+
switch (result.severity) {
|
89
|
+
/* eslint-disable style/max-statements-per-line */
|
90
|
+
case 0: lines.push(setNotice(message, context)); break;
|
91
|
+
case 1: lines.push(setWarning(message, context)); break;
|
92
|
+
case 2: lines.push(setError(message, context)); break;
|
93
|
+
/* eslint-enable style/max-statements-per-line */
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
return lines;
|
98
|
+
}
|
99
|
+
|
43
100
|
/**
|
44
101
|
* @param {LintResult[]} fileResults The eslint results
|
45
102
|
* @returns {string}
|
46
103
|
*/
|
47
104
|
function formatter(fileResults) {
|
48
105
|
const lines = [];
|
49
|
-
let warningCount = 0;
|
50
|
-
let errorCount = 0;
|
51
106
|
|
52
107
|
const pkg = getPackageJson(undefined, `${process.cwd()}/package.json`);
|
53
108
|
if (pkg == null) {
|
54
109
|
throw new Error('Cannot resolve package name');
|
55
110
|
}
|
56
111
|
|
57
|
-
|
112
|
+
const { warningCount, errorCount } = counters(fileResults);
|
58
113
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
114
|
+
if (warningCount + errorCount > 0) {
|
115
|
+
lines.push(startGroup([
|
116
|
+
`Linted ${pkg.name} (`,
|
117
|
+
`${errorCount} ${plural('error', errorCount)}, `,
|
118
|
+
`${warningCount} ${plural('warning', warningCount)})`,
|
119
|
+
].join('')));
|
120
|
+
} else {
|
121
|
+
lines.push(`Linted ${pkg.name} (0 errors, 0 warnings)`);
|
122
|
+
}
|
64
123
|
|
65
|
-
|
66
|
-
errorCount += fileResult.errorCount;
|
124
|
+
lines.push(...fileResults.flatMap(formatFileResult));
|
67
125
|
|
68
|
-
|
69
|
-
|
70
|
-
? `[${result.ruleId}] ${result.message}`
|
71
|
-
: result.message;
|
72
|
-
|
73
|
-
/** @type {import('@darksheep/github-actions').LineAnnotation} */
|
74
|
-
const context = {
|
75
|
-
file: filePath,
|
76
|
-
line: result.line,
|
77
|
-
col: result.column,
|
78
|
-
endLine: result.endLine,
|
79
|
-
endColumn: result.endColumn,
|
80
|
-
};
|
81
|
-
|
82
|
-
switch (result.severity) {
|
83
|
-
case 0:
|
84
|
-
lines.push(setNotice(message, context));
|
85
|
-
break;
|
86
|
-
case 1:
|
87
|
-
lines.push(setWarning(message, context));
|
88
|
-
break;
|
89
|
-
case 2:
|
90
|
-
lines.push(setError(message, context));
|
91
|
-
break;
|
92
|
-
}
|
93
|
-
}
|
126
|
+
if (warningCount + errorCount > 0) {
|
127
|
+
lines.push(endGroup());
|
94
128
|
}
|
95
129
|
|
96
|
-
|
130
|
+
if (typeof process.exitCode !== 'number') {
|
131
|
+
process.exitCode = 0;
|
132
|
+
}
|
97
133
|
|
98
|
-
|
99
|
-
process.exitCode = errorCount;
|
134
|
+
process.exitCode += errorCount;
|
100
135
|
|
101
|
-
lines.push(`${total} problem(s) (${errorCount} ${plural('error', errorCount)}, ${warningCount} ${plural('warning', warningCount)})`);
|
102
136
|
return lines.join('\n');
|
103
137
|
}
|
104
138
|
|
package/types/index.d.ts
CHANGED
@@ -1,27 +1,4 @@
|
|
1
1
|
export = formatter;
|
2
|
-
/**
|
3
|
-
* @typedef {Object} LintMessage
|
4
|
-
* @property {number} column
|
5
|
-
* @property {number} line
|
6
|
-
* @property {number} [endColumn]
|
7
|
-
* @property {number} [endLine]
|
8
|
-
* @property {string | null} ruleId
|
9
|
-
* @property {string} message
|
10
|
-
* @property {string} [messageId]
|
11
|
-
* @property {string} [nodeType]
|
12
|
-
* @property {boolean} [fatal]
|
13
|
-
* @property {0 | 1 | 2} severity
|
14
|
-
*/
|
15
|
-
/**
|
16
|
-
* @typedef {Object} LintResult
|
17
|
-
* @property {string} filePath
|
18
|
-
* @property {LintMessage[]} messages
|
19
|
-
* @property {number} errorCount
|
20
|
-
* @property {number} fatalErrorCount
|
21
|
-
* @property {number} warningCount
|
22
|
-
* @property {number} fixableErrorCount
|
23
|
-
* @property {number} fixableWarningCount
|
24
|
-
*/
|
25
2
|
/**
|
26
3
|
* @param {LintResult[]} fileResults The eslint results
|
27
4
|
* @returns {string}
|