Skip to content

Commit 3a9c302

Browse files
committed
fix: Update ESLint peer requirements to 8.40.0
This was already required by certain rules which depend on features in ESLint 8.40.0, this release is merely adjusting the peer dependency range to accurately reflect that.
1 parent 50df5ba commit 3a9c302

7 files changed

+17
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"typescript": "^5.2.2"
5959
},
6060
"peerDependencies": {
61-
"eslint": ">=7",
61+
"eslint": ">=8.40.0",
6262
"eslint-plugin-jest": ">=25"
6363
},
6464
"peerDependenciesMeta": {

src/rules/expect-expect.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Rule } from 'eslint';
22
import ESTree from 'estree';
33
import { dig, isExpectCall, isTestCall } from '../utils/ast';
4-
import { getSourceCode } from '../utils/misc';
54

65
function isAssertionCall(
76
context: Rule.RuleContext,
@@ -21,7 +20,6 @@ export default {
2120
...((context.options?.[0] as Record<string, unknown>) ?? {}),
2221
};
2322

24-
const sourceCode = getSourceCode(context);
2523
const unchecked: ESTree.CallExpression[] = [];
2624

2725
function checkExpressions(nodes: ESTree.Node[]) {
@@ -43,10 +41,7 @@ export default {
4341
} else if (
4442
isAssertionCall(context, node, options.assertFunctionNames)
4543
) {
46-
const ancestors = sourceCode.getAncestors
47-
? sourceCode.getAncestors(node)
48-
: context.getAncestors();
49-
44+
const ancestors = context.sourceCode.getAncestors(node);
5045
checkExpressions(ancestors);
5146
}
5247
},

src/rules/missing-playwright-await.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
isIdentifier,
88
isPropertyAccessor,
99
} from '../utils/ast';
10-
import { getSourceCode } from '../utils/misc';
1110

1211
const validTypes = new Set([
1312
'AwaitExpression',
@@ -101,7 +100,6 @@ function getCallType(
101100

102101
export default {
103102
create(context) {
104-
const sourceCode = getSourceCode(context);
105103
const options = context.options[0] || {};
106104
const awaitableMatchers = new Set([
107105
...expectPlaywrightMatchers,
@@ -136,7 +134,7 @@ export default {
136134
// find where it is referenced. When we find the reference, we can
137135
// re-check validity.
138136
if (node.parent.type === 'VariableDeclarator') {
139-
const scope = sourceCode.getScope(node.parent.parent);
137+
const scope = context.sourceCode.getScope(node.parent.parent);
140138

141139
for (const ref of scope.references) {
142140
const refParent = (ref.identifier as Rule.Node).parent;

src/rules/no-unsafe-references.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { AST, Rule, Scope, SourceCode } from 'eslint';
1+
import { AST, Rule, Scope } from 'eslint';
22
import * as ESTree from 'estree';
33
import { getStringValue, isFunction, isPageMethod } from '../utils/ast';
4-
import { getSourceCode, truthy } from '../utils/misc';
4+
import { truthy } from '../utils/misc';
55

66
/** Collect all variable references in the parent scopes recursively. */
77
function collectVariables(scope: Scope.Scope | null): string[] {
@@ -48,19 +48,22 @@ function addArgument(
4848
}
4949

5050
/** Get the opening parenthesis of the function. */
51-
function getParen(sourceCode: SourceCode, node: ESTree.Node): AST.Token | null {
52-
let token: AST.Token | null = sourceCode.getFirstToken(node);
51+
function getParen(
52+
context: Rule.RuleContext,
53+
node: ESTree.Node,
54+
): AST.Token | null {
55+
let token: AST.Token | null = context.sourceCode.getFirstToken(node);
5356

5457
while (token && token.value !== '(') {
55-
token = sourceCode.getTokenAfter(token);
58+
token = context.sourceCode.getTokenAfter(token);
5659
}
5760

5861
return token;
5962
}
6063

6164
/** Add a parameter to the function. */
6265
function addParam(
63-
sourceCode: SourceCode,
66+
context: Rule.RuleContext,
6467
fixer: Rule.RuleFixer,
6568
node: ESTree.ArrowFunctionExpression | ESTree.FunctionExpression,
6669
refs: string,
@@ -77,7 +80,7 @@ function addParam(
7780
}
7881

7982
// If the function has no params, add the reference after the opening parenthesis
80-
const token = getParen(sourceCode, node);
83+
const token = getParen(context, node);
8184
return token ? fixer.insertTextAfter(token, `[${refs}]`) : null;
8285
}
8386

@@ -90,8 +93,7 @@ export default {
9093
const [fn] = node.arguments;
9194
if (!fn || !isFunction(fn)) return;
9295

93-
const sourceCode = getSourceCode(context);
94-
const { through, upper } = sourceCode.getScope(fn.body);
96+
const { through, upper } = context.sourceCode.getScope(fn.body);
9597
const allRefs = new Set(collectVariables(upper));
9698

9799
// This logic is confusing at first. If we find a variable within the
@@ -120,7 +122,7 @@ export default {
120122

121123
return [
122124
addArgument(fixer, node, refs),
123-
addParam(sourceCode, fixer, fn, refs),
125+
addParam(context, fixer, fn, refs),
124126
].filter(truthy);
125127
},
126128
});

src/rules/prefer-to-contain.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
isBooleanLiteral,
66
isPropertyAccessor,
77
} from '../utils/ast';
8-
import { getSourceCode } from '../utils/misc';
98
import { parseExpectCall } from '../utils/parseExpectCall';
109
import { KnownCallExpression } from '../utils/types';
1110

@@ -49,8 +48,6 @@ export default {
4948

5049
context.report({
5150
fix(fixer) {
52-
const sourceCode = getSourceCode(context);
53-
5451
// We need to negate the expectation if the current expected
5552
// value is itself negated by the "not" modifier
5653
const addNotModifier =
@@ -71,7 +68,7 @@ export default {
7168
// replace the matcher argument with the value from the "includes"
7269
fixer.replaceText(
7370
expectCall.args[0],
74-
sourceCode.getText(includesCall.arguments[0]),
71+
context.sourceCode.getText(includesCall.arguments[0]),
7572
),
7673
];
7774

src/rules/prefer-web-first-assertions.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Rule } from 'eslint';
22
import ESTree from 'estree';
33
import { getRawValue, getStringValue, isBooleanLiteral } from '../utils/ast';
4-
import { getSourceCode } from '../utils/misc';
54
import { parseExpectCall } from '../utils/parseExpectCall';
65

76
type MethodConfig = {
@@ -63,8 +62,7 @@ function dereference(context: Rule.RuleContext, node: ESTree.Node) {
6362
return node;
6463
}
6564

66-
const sourceCode = getSourceCode(context);
67-
const scope = sourceCode.getScope(node);
65+
const scope = context.sourceCode.getScope(node);
6866

6967
// Find the variable declaration and return the initializer
7068
for (const ref of scope.references) {

src/utils/misc.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import { Rule } from 'eslint';
2-
31
export const getAmountData = (amount: number) => ({
42
amount: amount.toString(),
53
s: amount === 1 ? '' : 's',
64
});
75

8-
export function getSourceCode(context: Rule.RuleContext) {
9-
return context.sourceCode ?? context.getSourceCode();
10-
}
11-
126
export const truthy = Boolean as unknown as <T>(
137
value: T | undefined | null | false | 0 | '',
148
) => value is T;

0 commit comments

Comments
 (0)