Skip to content

Commit 95bd95d

Browse files
committed
fix
1 parent de328c8 commit 95bd95d

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

lib/internal/get-all-directive-comments.js

+26-17
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,21 @@ function getAllDirectiveCommentsFromInlineConfigNodes(sourceCode) {
6464
if (
6565
result.some(
6666
(comment) =>
67-
comment.range[0] > range[1] && range[0] < comment.range[1]
67+
comment.range[0] <= range[1] && range[0] <= comment.range[1]
6868
)
6969
) {
7070
continue
7171
}
7272
const nodeText = sourceCode.text.slice(range[0], range[1])
73-
// Extract comment content from the comment text.
74-
// The comment format was based on the language comment definition in vscode-eslint.
75-
// See https://github.com/microsoft/vscode-eslint/blob/c0e753713ea9935667e849d91e549adbff213e7e/server/src/languageDefaults.ts#L14
76-
const commentValue =
77-
nodeText.startsWith("/*") && nodeText.startsWith("*/")
78-
? nodeText.slice(2, -2)
79-
: nodeText.startsWith("//")
80-
? nodeText.slice(2)
81-
: nodeText.startsWith("<!--") && nodeText.endsWith("-->")
82-
? nodeText.slice(4, -3)
83-
: nodeText.startsWith("###") && nodeText.endsWith("###")
84-
? nodeText.slice(1)
85-
: nodeText.startsWith("#")
86-
? nodeText.slice(1)
87-
: nodeText
73+
const commentValue = extractCommentContent(nodeText)
8874
const directiveComment = utils.parseDirectiveText(commentValue)
89-
if (directiveComment != null) {
75+
if (
76+
directiveComment != null &&
77+
directiveComment.kind !== "eslint-disable" &&
78+
directiveComment.kind !== "eslint-disable-line" &&
79+
directiveComment.kind !== "eslint-disable-next-line" &&
80+
directiveComment.kind !== "eslint-enable"
81+
) {
9082
result.push({
9183
kind: directiveComment.kind,
9284
value: directiveComment.value,
@@ -102,6 +94,23 @@ function getAllDirectiveCommentsFromInlineConfigNodes(sourceCode) {
10294
return result
10395
}
10496

97+
function extractCommentContent(text) {
98+
// Extract comment content from the comment text.
99+
// The comment format was based on the language comment definition in vscode-eslint.
100+
// See https://github.com/microsoft/vscode-eslint/blob/c0e753713ea9935667e849d91e549adbff213e7e/server/src/languageDefaults.ts#L14
101+
return text.startsWith("/*") && text.endsWith("*/")
102+
? text.slice(2, -2)
103+
: text.startsWith("//")
104+
? text.slice(2)
105+
: text.startsWith("<!--") && text.endsWith("-->")
106+
? text.slice(4, -3)
107+
: text.startsWith("###") && text.endsWith("###")
108+
? text.slice(1)
109+
: text.startsWith("#")
110+
? text.slice(1)
111+
: text
112+
}
113+
105114
module.exports = {
106115
/**
107116
* Get all directive comments for the given rule context.

lib/internal/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module.exports = {
119119
}
120120

121121
if (
122-
lineCommentSupported &&
122+
parsed.kind === "eslint-disable-line" &&
123123
comment.loc.start.line !== comment.loc.end.line
124124
) {
125125
// disable-line comment should not span multiple lines.

tests/lib/illegal-eslint-disable-line.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ describe("multi-line eslint-disable-line comments", () => {
7777
for (const code of [
7878
`/* eslint @eslint-community/eslint-comments/no-use:[error, {allow: ['eslint']}] */
7979
/* eslint-disable-line
80-
*/
81-
/* eslint-disable-next-line
8280
*/`,
8381
`/* eslint @eslint-community/eslint-comments/no-duplicate-disable:error */
8482
/*eslint-disable no-undef*/
@@ -92,7 +90,7 @@ no-undef*/
9290
const normalMessages = messages.filter(
9391
(message) => message.ruleId != null
9492
)
95-
assert.strictEqual(normalMessages.length, 0)
93+
assert.deepStrictEqual(normalMessages, [])
9694
})
9795
)
9896
}

0 commit comments

Comments
 (0)