|
1 | | -// Fork of 'stylish' plugin that prints relative paths. |
| 1 | +// Fork of 'compact' plugin that prints relative paths. |
2 | 2 | // This allows an editor to navigate to the location of the lint warning even though we present |
3 | 3 | // eslint with paths underneath a bazel sandbox folder. |
4 | | -// from https://github.com/eslint/eslint/blob/331cf62024b6c7ad4067c14c593f116576c3c861/lib/cli-engine/formatters/stylish.js |
| 4 | +// from https://github.com/eslint/eslint/blob/331cf62024b6c7ad4067c14c593f116576c3c861/lib/cli-engine/formatters/compact.js |
5 | 5 | const path = require("node:path"); |
6 | 6 |
|
7 | 7 | /** |
8 | | - * Given a word and a count, append an s if count is not one. |
9 | | - * @param {string} word A word in its singular form. |
10 | | - * @param {int} count A number controlling whether word should be pluralized. |
11 | | - * @returns {string} The original word with an s on the end if count is not one. |
| 8 | + * Returns the severity of warning or error |
| 9 | + * @param {Object} message message object to examine |
| 10 | + * @returns {string} severity level |
| 11 | + * @private |
12 | 12 | */ |
13 | | -function pluralize(word, count) { |
14 | | - return count === 1 ? word : `${word}s`; |
| 13 | +function getMessageType(message) { |
| 14 | + if (message.fatal || message.severity === 2) { |
| 15 | + return "Error"; |
| 16 | + } |
| 17 | + return "Warning"; |
15 | 18 | } |
16 | 19 |
|
17 | 20 | module.exports = function (results, context) { |
18 | 21 | let output = "", |
19 | | - errorCount = 0, |
20 | | - warningCount = 0, |
21 | | - fixableErrorCount = 0, |
22 | | - fixableWarningCount = 0; |
| 22 | + total = 0; |
23 | 23 |
|
24 | 24 | results.forEach((result) => { |
25 | 25 | const messages = result.messages; |
26 | 26 |
|
27 | | - if (messages.length === 0) { |
28 | | - return; |
29 | | - } |
30 | | - |
31 | | - errorCount += result.errorCount; |
32 | | - warningCount += result.warningCount; |
33 | | - fixableErrorCount += result.fixableErrorCount; |
34 | | - fixableWarningCount += result.fixableWarningCount; |
35 | | - |
36 | | - const relpath = path.relative(context.cwd, result.filePath); |
| 27 | + total += messages.length; |
37 | 28 |
|
38 | 29 | messages.forEach((message) => { |
39 | | - const msgtext = message.message.replace(/([^ ])\.$/u, "$1"); |
40 | | - const severity = |
41 | | - message.fatal || message.severity === 2 ? "error" : "warning"; |
42 | | - const location = [relpath, message.line, message.column].join(":"); |
43 | | - output += `${location}: ${msgtext} [${severity} from ${ |
44 | | - message.ruleId || "" |
45 | | - }]\n`; |
| 30 | + output += `${path.relative(context.cwd, result.filePath)}: `; |
| 31 | + output += `line ${message.line || 0}`; |
| 32 | + output += `, col ${message.column || 0}`; |
| 33 | + output += `, ${getMessageType(message)}`; |
| 34 | + output += ` - ${message.message}`; |
| 35 | + output += message.ruleId ? ` (${message.ruleId})` : ""; |
| 36 | + output += "\n"; |
46 | 37 | }); |
47 | 38 | }); |
48 | 39 |
|
49 | | - const total = errorCount + warningCount; |
50 | 40 | if (total > 0) { |
51 | | - output += [ |
52 | | - "\n", |
53 | | - "\u2716 ", |
54 | | - total, |
55 | | - pluralize(" problem", total), |
56 | | - " (", |
57 | | - errorCount, |
58 | | - pluralize(" error", errorCount), |
59 | | - ", ", |
60 | | - warningCount, |
61 | | - pluralize(" warning", warningCount), |
62 | | - ")\n", |
63 | | - ].join(""); |
64 | | - |
65 | | - if (fixableErrorCount > 0 || fixableWarningCount > 0) { |
66 | | - output += [ |
67 | | - " ", |
68 | | - fixableErrorCount, |
69 | | - pluralize(" error", fixableErrorCount), |
70 | | - " and ", |
71 | | - fixableWarningCount, |
72 | | - pluralize(" warning", fixableWarningCount), |
73 | | - " potentially fixable with the `--fix` option.\n", |
74 | | - ].join(""); |
75 | | - } |
| 41 | + output += `\n${total} problem${total !== 1 ? "s" : ""}`; |
76 | 42 | } |
| 43 | + |
77 | 44 | return output; |
78 | 45 | }; |
0 commit comments