Skip to content

Commit 95bb51b

Browse files
committed
add tests and fix bugs
1 parent 28cc291 commit 95bb51b

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

lib/internal/utils.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ function divideDirectiveComment(value) {
181181
* @returns {object} The source code location.
182182
*/
183183
function getLoc(context, nodeOrToken) {
184-
const sourceCode = context.sourceCode || context.getSourceCode?.()
185-
if (typeof sourceCode?.getLoc === "function") {
184+
const sourceCode =
185+
context.sourceCode || (context.getSourceCode && context.getSourceCode())
186+
if (sourceCode && typeof sourceCode.getLoc === "function") {
186187
return sourceCode.getLoc(nodeOrToken)
187188
}
188189
return nodeOrToken.loc

lib/rules/disable-enable-pair.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ module.exports = {
4444
/** @type {import('@eslint/core').TextSourceCode} */
4545
const sourceCode = context.sourceCode || context.getSourceCode()
4646

47-
const firstToken = sourceCode.ast?.tokens?.[0]
47+
const firstToken =
48+
sourceCode.ast && sourceCode.ast.tokens && sourceCode.ast.tokens[0]
4849

4950
if (allowWholeFile && !firstToken) {
5051
return {}

lib/rules/no-aggregating-enable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434

3535
if (count >= 2) {
3636
context.report({
37-
loc: utils.toForceLocation(comment.loc),
37+
loc: utils.toForceLocation(utils.getLoc(context, comment)),
3838
messageId: "aggregatingEnable",
3939
data: { count },
4040
})

tests/lib/rules/no-aggregating-enable.js

+35
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ tester.run("no-aggregating-enable", rule, {
3232
/*eslint-enable no-redeclare*/
3333
/*eslint-enable no-shadow*/
3434
`,
35+
// Language plugin
36+
...(semver.satisfies(Linter.version, ">=9.6.0")
37+
? [
38+
{
39+
code: `
40+
/*eslint-disable no-redeclare, no-shadow*/
41+
/*eslint-enable no-redeclare*/
42+
/*eslint-enable no-shadow*/
43+
a {}`,
44+
plugins: {
45+
css: require("@eslint/css").default,
46+
},
47+
language: "css/css",
48+
},
49+
]
50+
: []),
3551
],
3652
invalid: [
3753
{
@@ -80,5 +96,24 @@ tester.run("no-aggregating-enable", rule, {
8096
},
8197
]
8298
: []),
99+
// Language plugin
100+
...(semver.satisfies(Linter.version, ">=9.6.0")
101+
? [
102+
{
103+
code: `
104+
/*eslint-disable no-redeclare*/
105+
/*eslint-disable no-shadow*/
106+
/*eslint-enable*/
107+
a {}`,
108+
plugins: {
109+
css: require("@eslint/css").default,
110+
},
111+
language: "css/css",
112+
errors: [
113+
"This `eslint-enable` comment affects 2 `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
114+
],
115+
},
116+
]
117+
: []),
83118
],
84119
})

0 commit comments

Comments
 (0)