Skip to content

Commit 8174b02

Browse files
rachelcarmenamheap
authored andcommitted
Fixes: Cannot read property 'severity' of undefined
1 parent 6ffc398 commit 8174b02

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function loopMatch(matcher, input) {
4848
continue;
4949
}
5050

51-
let r = runRegExp(re, line, x);
51+
let r = runRegExp(re, line, x, matcher);
5252

5353
// If the regexp didn't match, assume that the loop is over and start again
5454
if (!r) {

index.test.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ const eslintLoopMatcher = {
5151
]
5252
};
5353

54+
const loopMatcherWithDefaultSeverity = {
55+
owner: "test-matcher-loop",
56+
severity: 'error',
57+
pattern: [
58+
{
59+
// Matches the 1st line in the output
60+
regexp: "^([^\\s].*)$",
61+
file: 1
62+
},
63+
{
64+
// Matches the 2nd and 3rd line in the output
65+
regexp: "^\\s+(\\d+):(\\d+)\\s+\\s+(.*)\\s\\s+(.*)$",
66+
// File is carried through from above, so we define the rest of the groups
67+
line: 1,
68+
column: 2,
69+
message: 3,
70+
code: 4,
71+
loop: true
72+
}
73+
]
74+
};
75+
5476
test("throws an error if the matcher is missing", () => {
5577
actual = () => matcher(undefined, "error::Something went wrong");
5678
expect(actual).toThrow("No matcher provided");
@@ -168,6 +190,54 @@ foo.js
168190
]);
169191
});
170192

193+
test("loop line matcher with default severity, does match", () => {
194+
const input = `test.js
195+
1:0 Missing "use strict" statement strict
196+
5:10 'addOne' is defined but never used no-unused-vars
197+
198+
foo.js
199+
36:10 Expected parentheses around arrow function argument arrow-parens
200+
37:13 Expected parentheses around arrow function argument arrow-parens
201+
202+
✖ 4 problems (4 errors, 0 warnings)`;
203+
204+
actual = matcher(loopMatcherWithDefaultSeverity, input);
205+
expect(actual).toEqual([
206+
{
207+
file: "test.js",
208+
line: "1",
209+
column: "0",
210+
severity: "error",
211+
message: 'Missing "use strict" statement',
212+
code: "strict"
213+
},
214+
{
215+
file: "test.js",
216+
line: "5",
217+
column: "10",
218+
severity: "error",
219+
message: "'addOne' is defined but never used",
220+
code: "no-unused-vars"
221+
},
222+
{
223+
file: "foo.js",
224+
line: "36",
225+
column: "10",
226+
severity: "error",
227+
message: "Expected parentheses around arrow function argument",
228+
code: "arrow-parens"
229+
},
230+
{
231+
file: "foo.js",
232+
line: "37",
233+
column: "13",
234+
severity: "error",
235+
message: "Expected parentheses around arrow function argument",
236+
code: "arrow-parens"
237+
}
238+
]);
239+
});
240+
171241
test("uses default severity", () => {
172242
const input = "Some Message:/path/to/file.js:12";
173243
actual = matcher(validMatcher, input);

0 commit comments

Comments
 (0)