Skip to content

Commit

Permalink
refactor: code
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Dec 24, 2021
1 parent 35fb63a commit e10efd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/linter/apply-disable-directives.js
Expand Up @@ -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 }
Expand Down
19 changes: 16 additions & 3 deletions tests/lib/linter/apply-disable-directives.js
Expand Up @@ -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: value ? value.length : 10
}
},
value
},
ruleIds
};
}
Expand Down Expand Up @@ -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: [],
Expand All @@ -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: " "
Expand Down

0 comments on commit e10efd6

Please sign in to comment.