Skip to content

Commit 937ddec

Browse files
authored
fix: add context.sourceCode fallback for ESLint 10 compatibility (#659)
Fixes #655.
1 parent 83cef82 commit 937ddec

12 files changed

+28
-12
lines changed

lib/rules/assert-args.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ module.exports = {
3737
create: function (context) {
3838
/** @type {Array<{assertContextVar: string | null}>} */
3939
const testStack = [],
40-
sourceCode = context.getSourceCode();
40+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
41+
sourceCode = context.sourceCode ?? context.getSourceCode();
4142

4243
/**
4344
* @param {import('estree').Node} argNode

lib/rules/literal-compare-order.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ module.exports = {
3838
create: function (context) {
3939
/** @type {Array<{assertContextVar: string | null}>} */
4040
const testStack = [],
41-
sourceCode = context.getSourceCode();
41+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
42+
sourceCode = context.sourceCode ?? context.getSourceCode();
4243

4344
function getAssertContext() {
4445
assert.ok(testStack.length);

lib/rules/no-arrow-tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ module.exports = {
4040
//--------------------------------------------------------------------------
4141

4242
// Fixer adapted from https://github.com/lo1tuma/eslint-plugin-mocha (MIT)
43-
const sourceCode = context.getSourceCode();
43+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
44+
const sourceCode = context.sourceCode ?? context.getSourceCode();
4445

4546
/**
4647
* @param {number} start

lib/rules/no-assert-equal-boolean.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ module.exports = {
117117
? "true"
118118
: "false";
119119

120-
const sourceCode = context.getSourceCode();
120+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
121+
const sourceCode =
122+
context.sourceCode ?? context.getSourceCode();
121123
if (node.type !== "CallExpression") {
122124
return null;
123125
}

lib/rules/no-commented-tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ module.exports = {
2525
},
2626

2727
create: function (context) {
28-
const sourceCode = context.getSourceCode(),
28+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
29+
const sourceCode = context.sourceCode ?? context.getSourceCode(),
2930
newlineRegExp = /\r\n|\r|\n/g,
3031
warningRegExp =
3132
/\b(QUnit\.test|QUnit\.asyncTest|QUnit\.skip|test|asyncTest)\s*\(\s*["'`]/g;

lib/rules/no-compare-relation-boolean.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ module.exports = {
102102
node: callExprNode,
103103
messageId: "redundantComparison",
104104
fix(fixer) {
105-
const sourceCode = context.getSourceCode();
105+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
106+
const sourceCode =
107+
context.sourceCode ?? context.getSourceCode();
106108
/* istanbul ignore next */
107109
if (callExprNode.type !== "CallExpression") {
108110
return null;

lib/rules/no-hooks-from-ancestor-modules.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ module.exports = {
125125
const description =
126126
arg.type === "Literal" && typeof arg.value === "string"
127127
? arg.value
128-
: context.getSourceCode().getText(arg);
128+
: /* istanbul ignore next: deprecated code paths only followed by old eslint versions */
129+
(
130+
context.sourceCode ?? context.getSourceCode()
131+
).getText(arg);
129132

130133
/** @type {{callExpression: import('eslint').Rule.Node, description: string, hookIdentifierName?: string | null}} */
131134
const moduleStackInfo = {

lib/rules/no-negated-ok.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ module.exports = {
4646
...POSITIVE_ASSERTIONS,
4747
...NEGATIVE_ASSERTIONS,
4848
]),
49-
sourceCode = context.getSourceCode();
49+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
50+
sourceCode = context.sourceCode ?? context.getSourceCode();
5051

5152
function getAssertVar() {
5253
let result = null;

lib/rules/no-ok-equality.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ module.exports = {
5050
allowGlobal: true,
5151
},
5252
options = context.options[0] || DEFAULT_OPTIONS,
53-
sourceCode = context.getSourceCode();
53+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
54+
sourceCode = context.sourceCode ?? context.getSourceCode();
5455

5556
const POSITIVE_ASSERTIONS = new Set(["ok", "true"]);
5657
const NEGATIVE_ASSERTIONS = new Set(["notOk", "false"]);

lib/rules/no-test-expect-argument.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ module.exports = {
3030
},
3131

3232
create: function (context) {
33-
const sourceCode = context.getSourceCode();
33+
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
34+
const sourceCode = context.sourceCode ?? context.getSourceCode();
3435

3536
return {
3637
CallExpression: function (node) {

0 commit comments

Comments
 (0)