diff --git a/lib/linter/apply-disable-directives.js b/lib/linter/apply-disable-directives.js index 552c3dc4adba..636626711d0f 100644 --- a/lib/linter/apply-disable-directives.js +++ b/lib/linter/apply-disable-directives.js @@ -263,15 +263,14 @@ function applyDirectives(options) { const unusedDisableDirectives = processed .map(({ description, fix, position }) => { const { parentComment, type, line, column } = position; - const { commentToken } = parentComment; return { ruleId: null, message: description ? `Unused eslint-disable directive (no problems were reported from ${description}).` : "Unused eslint-disable directive (no problems were reported).", - line: type === "disable-next-line" && commentToken.loc ? commentToken.loc.start.line : line, - column: type === "disable-next-line" && commentToken.loc ? commentToken.loc.start.column + 1 : column, + line: type === "disable-next-line" ? parentComment.commentToken.loc.start.line : line, + column: type === "disable-next-line" ? parentComment.commentToken.loc.start.column + 1 : column, severity: options.reportUnusedDisableDirectives === "warn" ? 1 : 2, nodeType: null, ...options.disableFixes ? {} : { fix } diff --git a/tests/lib/linter/apply-disable-directives.js b/tests/lib/linter/apply-disable-directives.js index 72708bcbddc8..a3d1051e5042 100644 --- a/tests/lib/linter/apply-disable-directives.js +++ b/tests/lib/linter/apply-disable-directives.js @@ -25,7 +25,20 @@ const applyDisableDirectives = require("../../../lib/linter/apply-disable-direct */ function createParentComment(range, value, ruleIds = []) { return { - commentToken: { range, value }, + commentToken: { + range, + loc: { + start: { + line: 1, + column: 1 + }, + end: { + line: 1, + column: 10 + } + }, + value + }, ruleIds }; } @@ -1294,7 +1307,7 @@ describe("apply-disable-directives", () => { parentComment: createParentComment([0, 27]), type: "disable-next-line", line: 1, - column: 1, + column: 2, ruleId: null }], problems: [], @@ -1305,7 +1318,7 @@ describe("apply-disable-directives", () => { ruleId: null, message: "Unused eslint-disable directive (no problems were reported).", line: 1, - column: 1, + column: 2, fix: { range: [0, 27], text: " "