1 | import { diagnose } from "./diagnose.js";
|
2 | export function lint(result) {
|
3 | const nodeType = "Unknown";
|
4 | const ruleId = "prettier/prettier";
|
5 | if (result.type === "success") {
|
6 | const { input, output } = result;
|
7 | const diagnostics = diagnose(input, output);
|
8 | const messages = diagnostics.map(({ message, start: { line, column } }) => ({
|
9 | ruleId,
|
10 | severity: 1 ,
|
11 | line,
|
12 | column,
|
13 | message,
|
14 | nodeType,
|
15 | }));
|
16 | return {
|
17 | filePath: result.filename,
|
18 | source: input,
|
19 | ...(messages.length === 0 ? {} : { output }),
|
20 | messages,
|
21 | errorCount: 0,
|
22 | warningCount: messages.length,
|
23 | };
|
24 | }
|
25 | const { input, error } = result;
|
26 | const message = {
|
27 | ruleId,
|
28 | severity: 2 ,
|
29 | nodeType,
|
30 | ...(error.loc
|
31 | ?
|
32 | {
|
33 | line: error.loc.start.line,
|
34 | column: error.loc.start.column,
|
35 | message: error.message.split("\n", 1)[0],
|
36 | }
|
37 | : {
|
38 | line: 0,
|
39 | column: 0,
|
40 | message: typeof error?.message === "string" ? error.message : error,
|
41 | }) ,
|
42 | };
|
43 | return {
|
44 | filePath: result.filename,
|
45 | source: input,
|
46 | messages: [message],
|
47 | errorCount: 1,
|
48 | warningCount: 0,
|
49 | };
|
50 | }
|