Skip to content

Commit d7194c1

Browse files
committed
Add column index
1 parent af450d7 commit d7194c1

File tree

7 files changed

+130
-46
lines changed

7 files changed

+130
-46
lines changed

src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ module.exports = (results = []) => {
2121
}
2222

2323
function reportMessage(result) {
24+
const lineColumn = `#${result.line}|${result.column}`;
2425
switch (result.severity) {
2526
case 2:
26-
return ` ${prefixes.error} ${error("#" + result.line)}: ${
27-
result.message
28-
}`;
27+
return ` ${prefixes.error} ${error(lineColumn)}: ${result.message}`;
2928
case 1:
30-
return ` ${prefixes.warning} ${warning("#" + result.line)}: ${
29+
return ` ${prefixes.warning} ${warning(lineColumn)}: ${
3130
result.message
3231
}`;
3332
}

tests/fixtures/mixed.json

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,65 @@
11
[
22
{
3+
"errorCount": 0,
34
"filePath": "index1.js",
45
"messages": [
5-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." },
6-
{ "line": 2, "severity": 1, "message": "Unexpected console statement." }
6+
{
7+
"column": 1,
8+
"line": 1,
9+
"message": "Unexpected console statement.",
10+
"severity": 1
11+
},
12+
{
13+
"column": 2,
14+
"line": 2,
15+
"message": "Unexpected console statement.",
16+
"severity": 1
17+
}
718
],
8-
"errorCount": 0,
919
"warningCount": 2
1020
},
1121
{
22+
"errorCount": 2,
1223
"filePath": "index2.js",
1324
"messages": [
14-
{ "line": 1, "severity": 2, "message": "Unexpected console statement." },
15-
{ "line": 2, "severity": 2, "message": "Unexpected console statement." }
25+
{
26+
"column": 1,
27+
"line": 1,
28+
"message": "Unexpected console statement.",
29+
"severity": 2
30+
},
31+
{
32+
"column": 2,
33+
"line": 2,
34+
"message": "Unexpected console statement.",
35+
"severity": 2
36+
}
1637
],
17-
"errorCount": 2,
1838
"warningCount": 0
1939
},
2040
{
41+
"errorCount": 1,
2142
"filePath": "index3.js",
2243
"messages": [
23-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." },
24-
{ "line": 2, "severity": 2, "message": "Unexpected console statement." }
44+
{
45+
"column": 1,
46+
"line": 1,
47+
"message": "Unexpected console statement.",
48+
"severity": 1
49+
},
50+
{
51+
"column": 2,
52+
"line": 2,
53+
"message": "Unexpected console statement.",
54+
"severity": 2
55+
}
2556
],
26-
"errorCount": 1,
2757
"warningCount": 1
2858
},
2959
{
60+
"errorCount": 0,
3061
"filePath": "index4.js",
3162
"messages": [],
32-
"errorCount": 0,
3363
"warningCount": 0
3464
}
3565
]

tests/fixtures/multiple-errors.json

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,37 @@
22
{
33
"filePath": "index1.js",
44
"messages": [
5-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." },
6-
{ "line": 2, "severity": 2, "message": "Unexpected console statement." }
5+
{
6+
"column": 1,
7+
"line": 1,
8+
"severity": 1,
9+
"message": "Unexpected console statement."
10+
},
11+
{
12+
"column": 2,
13+
"line": 2,
14+
"severity": 2,
15+
"message": "Unexpected console statement."
16+
}
717
],
818
"errorCount": 1,
919
"warningCount": 1
1020
},
1121
{
1222
"filePath": "index2.js",
1323
"messages": [
14-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." },
15-
{ "line": 2, "severity": 2, "message": "Unexpected console statement." }
24+
{
25+
"column": 1,
26+
"line": 1,
27+
"severity": 1,
28+
"message": "Unexpected console statement."
29+
},
30+
{
31+
"column": 2,
32+
"line": 2,
33+
"severity": 2,
34+
"message": "Unexpected console statement."
35+
}
1636
],
1737
"errorCount": 1,
1838
"warningCount": 1
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
[
22
{
3+
"errorCount": 0,
34
"filePath": "index1.js",
45
"messages": [
5-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." },
6-
{ "line": 2, "severity": 1, "message": "Unexpected console statement." }
6+
{
7+
"column": 1,
8+
"line": 1,
9+
"message": "Unexpected console statement.",
10+
"severity": 1
11+
},
12+
{
13+
"column": 2,
14+
"line": 2,
15+
"message": "Unexpected console statement.",
16+
"severity": 1
17+
}
718
],
8-
"errorCount": 0,
919
"warningCount": 2
1020
},
1121
{
22+
"errorCount": 0,
1223
"filePath": "index2.js",
1324
"messages": [
14-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." },
15-
{ "line": 2, "severity": 1, "message": "Unexpected console statement." }
25+
{
26+
"column": 1,
27+
"line": 1,
28+
"message": "Unexpected console statement.",
29+
"severity": 1
30+
},
31+
{
32+
"column": 2,
33+
"line": 2,
34+
"message": "Unexpected console statement.",
35+
"severity": 1
36+
}
1637
],
17-
"errorCount": 0,
1838
"warningCount": 2
1939
}
2040
]

tests/fixtures/single-error.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
[
22
{
3+
"errorCount": 1,
34
"filePath": "index1.js",
45
"messages": [
5-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." },
6-
{ "line": 2, "severity": 2, "message": "Unexpected console statement." }
6+
{
7+
"column": 1,
8+
"line": 1,
9+
"message": "Unexpected console statement.",
10+
"severity": 1
11+
},
12+
{
13+
"column": 2,
14+
"line": 2,
15+
"message": "Unexpected console statement.",
16+
"severity": 2
17+
}
718
],
8-
"errorCount": 1,
919
"warningCount": 1
1020
}
1121
]

tests/fixtures/single-warning.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
[
22
{
3+
"errorCount": 0,
34
"filePath": "index1.js",
45
"messages": [
5-
{ "line": 1, "severity": 1, "message": "Unexpected console statement." }
6+
{
7+
"column": 1,
8+
"line": 1,
9+
"message": "Unexpected console statement.",
10+
"severity": 1
11+
}
612
],
7-
"errorCount": 0,
813
"warningCount": 1
914
}
1015
]

tests/index.test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe("single file", () => {
1414
const output = formatter(fixtureSingleError);
1515
expect(output).toBe(`\
1616
${error("index1.js")}
17-
${warning("#1")}: Unexpected console statement.
18-
${error("#2")}: Unexpected console statement.
17+
${warning("#1|1")}: Unexpected console statement.
18+
${error("#2|2")}: Unexpected console statement.
1919
2020
${error("Error!")} » 1 error and 1 warning in 1 file`);
2121
});
@@ -24,7 +24,7 @@ describe("single file", () => {
2424
const output = formatter(fixtureSingleWarning);
2525
expect(output).toBe(`\
2626
${warning("index1.js")}
27-
${warning("#1")}: Unexpected console statement.
27+
${warning("#1|1")}: Unexpected console statement.
2828
2929
${warning("Warning!")} » 0 errors and 1 warning in 1 file`);
3030
});
@@ -43,11 +43,11 @@ describe("multiple files", () => {
4343
const output = formatter(fixtureMultipleErrors);
4444
expect(output).toBe(`\
4545
${error("index1.js")}
46-
${warning("#1")}: Unexpected console statement.
47-
${error("#2")}: Unexpected console statement.
46+
${warning("#1|1")}: Unexpected console statement.
47+
${error("#2|2")}: Unexpected console statement.
4848
${error("index2.js")}
49-
${warning("#1")}: Unexpected console statement.
50-
${error("#2")}: Unexpected console statement.
49+
${warning("#1|1")}: Unexpected console statement.
50+
${error("#2|2")}: Unexpected console statement.
5151
5252
${error("Error!")} » 2 errors and 2 warnings in 2 files`);
5353
});
@@ -56,11 +56,11 @@ describe("multiple files", () => {
5656
const output = formatter(fixtureMultipleWarnings);
5757
expect(output).toBe(`\
5858
${warning("index1.js")}
59-
${warning("#1")}: Unexpected console statement.
60-
${warning("#2")}: Unexpected console statement.
59+
${warning("#1|1")}: Unexpected console statement.
60+
${warning("#2|2")}: Unexpected console statement.
6161
${warning("index2.js")}
62-
${warning("#1")}: Unexpected console statement.
63-
${warning("#2")}: Unexpected console statement.
62+
${warning("#1|1")}: Unexpected console statement.
63+
${warning("#2|2")}: Unexpected console statement.
6464
6565
${warning("Warning!")} » 0 errors and 4 warnings in 2 files`);
6666
});
@@ -78,14 +78,14 @@ describe("multiple files", () => {
7878
const output = formatter(fixtureMixed);
7979
expect(output).toBe(`\
8080
${warning("index1.js")}
81-
${warning("#1")}: Unexpected console statement.
82-
${warning("#2")}: Unexpected console statement.
81+
${warning("#1|1")}: Unexpected console statement.
82+
${warning("#2|2")}: Unexpected console statement.
8383
${error("index2.js")}
84-
${error("#1")}: Unexpected console statement.
85-
${error("#2")}: Unexpected console statement.
84+
${error("#1|1")}: Unexpected console statement.
85+
${error("#2|2")}: Unexpected console statement.
8686
${error("index3.js")}
87-
${warning("#1")}: Unexpected console statement.
88-
${error("#2")}: Unexpected console statement.
87+
${warning("#1|1")}: Unexpected console statement.
88+
${error("#2|2")}: Unexpected console statement.
8989
${success("index4.js")}
9090
9191
${error("Error!")} » 3 errors and 3 warnings in 4 files`);

0 commit comments

Comments
 (0)