]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/lib/linter/report-translator.js
import eslint 7.28.0
[pve-eslint.git] / eslint / lib / linter / report-translator.js
index bed5af81e5dcecef105f3f2d61a4fa55fcb41ebe..75005c16e5808992506da1a1bad6c9dbcc4f3992 100644 (file)
@@ -115,6 +115,17 @@ function normalizeReportLoc(descriptor) {
     return descriptor.node.loc;
 }
 
+/**
+ * Check that a fix has a valid range.
+ * @param {Fix|null} fix The fix to validate.
+ * @returns {void}
+ */
+function assertValidFix(fix) {
+    if (fix) {
+        assert(fix.range && typeof fix.range[0] === "number" && typeof fix.range[1] === "number", `Fix has invalid range: ${JSON.stringify(fix, null, 2)}`);
+    }
+}
+
 /**
  * Compares items in a fixes array by range.
  * @param {Fix} a The first message.
@@ -133,6 +144,10 @@ function compareFixesByRange(a, b) {
  * @returns {{text: string, range: number[]}} The merged fixes
  */
 function mergeFixes(fixes, sourceCode) {
+    for (const fix of fixes) {
+        assertValidFix(fix);
+    }
+
     if (fixes.length === 0) {
         return null;
     }
@@ -181,6 +196,8 @@ function normalizeFixes(descriptor, sourceCode) {
     if (fix && Symbol.iterator in fix) {
         return mergeFixes(Array.from(fix), sourceCode);
     }
+
+    assertValidFix(fix);
     return fix;
 }