-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
81 lines (69 loc) · 1.96 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*eslint-env node*/
const ERROR_SEVERITY = 2;
function logIssue(issue) {
const attributes = Object.entries(issue)
.map((pair) => {
const [key, value] = pair;
if (key === 'message' || value === undefined) {
return null;
}
return `${key}=${value};`;
})
.filter((attribute) => Boolean(attribute));
return `##vso[task.logissue ${attributes.join('')}]${issue.message}`;
}
function shouldLogTaskComplete() {
return Boolean(process.env.ESLINT_AZDO_LOG_TASK_COMPLETE);
}
function formatResults(results, resultsMeta) {
let hasError = false;
let hasWarning = false;
const formattedResults = results
.filter((result) => result.messages.length > 0)
.map((result) =>
result.messages.map((message) => {
const type =
message.fatal || message.severity === ERROR_SEVERITY
? 'error'
: 'warning';
if (type === 'error') {
hasError = true;
} else {
hasWarning = true;
}
return logIssue({
type,
sourcepath: result.filePath,
linenumber: message.line,
columnnumber: message.column,
code: message.ruleId,
message: message.message,
});
})
)
.reduce((allMessages, messages) => {
if (messages != null && messages.length > 0) {
return allMessages.concat(messages);
}
return allMessages;
}, []);
if (resultsMeta?.maxWarningsExceeded) {
const { maxWarnings, foundWarnings } = resultsMeta.maxWarningsExceeded;
if (maxWarnings < foundWarnings) {
hasError = true;
formattedResults.push(
logIssue({
type: 'error',
message: `ESLint found too many warnings (maximum: ${maxWarnings}, found: ${foundWarnings}).`,
})
);
}
}
if (formatResults.shouldLogTaskComplete() && (hasError || hasWarning)) {
const result = hasError ? 'Failed' : 'SucceededWithIssues';
formattedResults.push(`##vso[task.complete result=${result};]`);
}
return formattedResults.join('\n');
}
formatResults.shouldLogTaskComplete = shouldLogTaskComplete;
module.exports = formatResults;