Skip to content

Commit 0419585

Browse files
authored
fix: Support older ESLint versions that don't support context.sourceCode (#180)
1 parent c0ce87a commit 0419585

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/rules/expect-expect.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function isAssertionCall(
1515

1616
export default {
1717
create(context) {
18+
const sourceCode = context.sourceCode ?? context.getSourceCode();
1819
const unchecked: ESTree.CallExpression[] = [];
1920
const additionalAssertFunctionNames =
2021
getAdditionalAssertFunctionNames(context);
@@ -36,7 +37,11 @@ export default {
3637
if (isTestCall(node, ['fixme', 'only', 'skip'])) {
3738
unchecked.push(node);
3839
} else if (isAssertionCall(node, additionalAssertFunctionNames)) {
39-
checkExpressions(context.sourceCode.getAncestors(node));
40+
const ancestors = sourceCode.getAncestors
41+
? sourceCode.getAncestors(node)
42+
: context.getAncestors();
43+
44+
checkExpressions(ancestors);
4045
}
4146
},
4247
'Program:exit'() {

src/rules/prefer-to-contain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default {
4848

4949
context.report({
5050
fix(fixer) {
51-
const sourceCode = context.getSourceCode();
51+
const sourceCode = context.sourceCode ?? context.getSourceCode();
5252

5353
// We need to negate the expectation if the current expected
5454
// value is itself negated by the "not" modifier

0 commit comments

Comments
 (0)