-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eslint-textmate-formatter.js
46 lines (39 loc) · 1.25 KB
/
.eslint-textmate-formatter.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
module.exports = function (results) {
let allMessages = [];
// Collect messages from all files
results.forEach((result) => {
const { filePath, messages } = result;
messages.forEach((message) => {
const { line, column, severity, ruleId, message: errorMessage } = message;
allMessages.push({
filePath,
line,
column,
severity,
ruleId,
errorMessage,
});
});
});
// Sort messages by ruleId + errorMessage
allMessages.sort((a, b) => {
if (`${a.ruleId} ${a.errorMessage}` < `${b.ruleId} ${b.errorMessage}`) {
return -1;
}
if (`${a.ruleId} ${a.errorMessage}` > `${b.ruleId} ${b.errorMessage}`) {
return 1;
}
return 0;
});
// Generate output
let output = '';
allMessages.forEach((message) => {
const { filePath, line, column, severity, ruleId, errorMessage } = message;
const messageType = severity === 1 ? 'Warning' : 'Error';
const textMateLink = `txmt://open?url=file://${encodeURIComponent(filePath)}&line=${line}&column=${column}`;
output += `${messageType}: ${errorMessage} (${ruleId})\n`;
output += `File: ${filePath.split('/').pop()}:${line}:${column}\n`;
output += `Link: ${textMateLink}\n\n`;
});
return output;
};