Skip to content

Commit

Permalink
fix: Support older ESLint versions that don't support `context.source…
Browse files Browse the repository at this point in the history
…Code` (#180)
  • Loading branch information
mskelton authored Nov 30, 2023
1 parent c0ce87a commit 0419585
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/rules/expect-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function isAssertionCall(

export default {
create(context) {
const sourceCode = context.sourceCode ?? context.getSourceCode();
const unchecked: ESTree.CallExpression[] = [];
const additionalAssertFunctionNames =
getAdditionalAssertFunctionNames(context);
Expand All @@ -36,7 +37,11 @@ export default {
if (isTestCall(node, ['fixme', 'only', 'skip'])) {
unchecked.push(node);
} else if (isAssertionCall(node, additionalAssertFunctionNames)) {
checkExpressions(context.sourceCode.getAncestors(node));
const ancestors = sourceCode.getAncestors
? sourceCode.getAncestors(node)
: context.getAncestors();

checkExpressions(ancestors);
}
},
'Program:exit'() {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-to-contain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default {

context.report({
fix(fixer) {
const sourceCode = context.getSourceCode();
const sourceCode = context.sourceCode ?? context.getSourceCode();

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

0 comments on commit 0419585

Please sign in to comment.