auto-cr-rules 2.0.37 → 2.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -80,7 +80,10 @@ exports.noSwallowedErrors = (0, types_1.defineRule)('no-swallowed-errors', { tag
|
|
|
80
80
|
var body = handler.body;
|
|
81
81
|
var statements = body.stmts;
|
|
82
82
|
var report = function () {
|
|
83
|
-
var
|
|
83
|
+
var charIndex = bytePosToCharIndex(source, moduleStart, body.span.start);
|
|
84
|
+
var computedLine = resolveLine(lineIndex, charIndex);
|
|
85
|
+
var fallbackLine = findCatchLine(source, computedLine);
|
|
86
|
+
var line = selectLineNumber(computedLine, fallbackLine);
|
|
84
87
|
helpers.reportViolation({
|
|
85
88
|
description: messages.swallowedError(),
|
|
86
89
|
line: line,
|
|
@@ -159,3 +162,26 @@ var bytePosToCharIndex = function (source, moduleStart, bytePos) {
|
|
|
159
162
|
}
|
|
160
163
|
return source.length;
|
|
161
164
|
};
|
|
165
|
+
var findCatchLine = function (source, computedLine) {
|
|
166
|
+
var lines = source.split(/\r?\n/);
|
|
167
|
+
var startIndex = Math.max((computedLine !== null && computedLine !== void 0 ? computedLine : 1) - 1, 0);
|
|
168
|
+
var catchPattern = /\bcatch\b/;
|
|
169
|
+
for (var index = startIndex; index < lines.length; index += 1) {
|
|
170
|
+
if (catchPattern.test(lines[index])) {
|
|
171
|
+
return index + 1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
};
|
|
176
|
+
var selectLineNumber = function (computed, fallback) {
|
|
177
|
+
if (fallback === undefined) {
|
|
178
|
+
return computed;
|
|
179
|
+
}
|
|
180
|
+
if (computed === undefined) {
|
|
181
|
+
return fallback;
|
|
182
|
+
}
|
|
183
|
+
if (computed < fallback) {
|
|
184
|
+
return fallback;
|
|
185
|
+
}
|
|
186
|
+
return computed;
|
|
187
|
+
};
|
package/package.json
CHANGED