diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 222b2f8ff..20bf68d8d 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -72,25 +72,9 @@ jobs: strategy: fail-fast: false matrix: - node-version: [16.x, 18.x, 20.x, 21.x, 22.x, 23.x, 24.x] - eslint-version: [7, 8, 9] - ts-eslint-plugin-version: [6, 7, 8] - exclude: - # ts-eslint/plugin@7 doesn't support node@16 - - node-version: 16.x - ts-eslint-plugin-version: 7 - # ts-eslint/plugin@8 doesn't support node@16 - - node-version: 16.x - ts-eslint-plugin-version: 8 - # eslint@9 doesn't support node@16 - - node-version: 16.x - eslint-version: 9 - # ts-eslint/plugin@7 doesn't support eslint@7 - - eslint-version: 7 - ts-eslint-plugin-version: 7 - # ts-eslint/plugin@8 doesn't support eslint@7 - - eslint-version: 7 - ts-eslint-plugin-version: 8 + node-version: [20.x, 22.x, 24.x] + eslint-version: [8, 9] + ts-eslint-plugin-version: [8] runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 7687b1cb3..79064c319 100644 --- a/README.md +++ b/README.md @@ -329,7 +329,7 @@ Manually fixable by | [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | | ✅ | | | | [max-expects](docs/rules/max-expects.md) | Enforces a maximum number assertion calls in a test body | | | | | | [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | | | | -| [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ✅ | 🎨 | 🔧 | | +| [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ✅ | | 🔧 | | | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | | ✅ | | | | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Disallow calling `expect` conditionally | ✅ | | | | | [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | | | | diff --git a/docs/rules/no-alias-methods.md b/docs/rules/no-alias-methods.md index 0df4fcb32..6796de373 100644 --- a/docs/rules/no-alias-methods.md +++ b/docs/rules/no-alias-methods.md @@ -1,8 +1,6 @@ # Disallow alias methods (`no-alias-methods`) -💼⚠️ This rule is enabled in the ✅ `recommended` -[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations). -This rule _warns_ in the 🎨 `style` +💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations). 🔧 This rule is automatically fixable by the diff --git a/package.json b/package.json index 06b32b635..9defcec7f 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ ] }, "dependencies": { - "@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0" + "@typescript-eslint/utils": "^8.0.0" }, "devDependencies": { "@babel/cli": "^7.4.4", @@ -80,10 +80,10 @@ "@schemastore/package": "^0.0.10", "@semantic-release/changelog": "^6.0.0", "@semantic-release/git": "^10.0.0", - "@tsconfig/node16": "^16.0.0", + "@tsconfig/node20": "^20.0.0", "@types/eslint": "^8.4.6", "@types/jest": "^29.0.0", - "@types/node": "^16.0.0", + "@types/node": "^20.0.0", "@types/semver": "^7.5.8", "@typescript-eslint/eslint-plugin": "^8.0.0", "@typescript-eslint/parser": "^8.0.0", @@ -91,7 +91,7 @@ "babel-jest": "^29.0.0", "babel-plugin-replace-ts-export-assignment": "^0.0.2", "dedent": "^1.5.0", - "eslint": "^7.0.0 || ^8.0.0", + "eslint": "^8.57.0", "eslint-config-prettier": "^10.0.0", "eslint-doc-generator": "^2.0.0", "eslint-plugin-eslint-plugin": "^6.0.0", @@ -115,8 +115,8 @@ "typescript": "^5.0.4" }, "peerDependencies": { - "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0 || ^8.0.0", - "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0", + "@typescript-eslint/eslint-plugin": "^8.0.0", + "eslint": "^8.57.0 || ^9.0.0", "jest": "*" }, "peerDependenciesMeta": { @@ -129,7 +129,7 @@ }, "packageManager": "yarn@3.8.7", "engines": { - "node": "^16.10.0 || ^18.12.0 || >=20.0.0" + "node": "^20.12.0 || ^22.0.0 || >=24.0.0" }, "publishConfig": { "provenance": true diff --git a/src/__tests__/__snapshots__/rules.test.ts.snap b/src/__tests__/__snapshots__/rules.test.ts.snap index 06883704c..9e436ad59 100644 --- a/src/__tests__/__snapshots__/rules.test.ts.snap +++ b/src/__tests__/__snapshots__/rules.test.ts.snap @@ -242,7 +242,6 @@ exports[`rules should export configs that refer to actual rules 1`] = ` }, }, "rules": { - "jest/no-alias-methods": "warn", "jest/prefer-to-be": "error", "jest/prefer-to-contain": "error", "jest/prefer-to-have-length": "error", @@ -285,7 +284,6 @@ exports[`rules should export configs that refer to actual rules 1`] = ` "jest", ], "rules": { - "jest/no-alias-methods": "warn", "jest/prefer-to-be": "error", "jest/prefer-to-contain": "error", "jest/prefer-to-have-length": "error", diff --git a/src/index.ts b/src/index.ts index 52b142983..e32f97b52 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,7 +53,6 @@ const recommendedRules = { } satisfies Record; const styleRules = { - 'jest/no-alias-methods': 'warn', 'jest/prefer-to-be': 'error', 'jest/prefer-to-contain': 'error', 'jest/prefer-to-have-length': 'error', diff --git a/src/rules/__tests__/test-utils.ts b/src/rules/__tests__/test-utils.ts index e4fe80132..2acaeb51c 100644 --- a/src/rules/__tests__/test-utils.ts +++ b/src/rules/__tests__/test-utils.ts @@ -8,8 +8,7 @@ const eslintRequire = createRequire(require.resolve('eslint')); export const espreeParser = eslintRequire.resolve('espree'); -export const eslintMajorVersion = semver.major(eslintVersion); -export const usingFlatConfig = eslintMajorVersion >= 9; +export const usingFlatConfig = semver.major(eslintVersion) >= 9; export class FlatCompatRuleTester extends TSESLint.RuleTester { public constructor(testerConfig?: TSESLint.RuleTesterConfig) { @@ -25,49 +24,11 @@ export class FlatCompatRuleTester extends TSESLint.RuleTester { tests: TSESLint.RunTests, ) { super.run(ruleName, rule, { - valid: FlatCompatRuleTester._filterCases( - tests.valid.map(t => FlatCompatRuleTester._flatCompat(t)), - ), - invalid: FlatCompatRuleTester._filterCases( - tests.invalid.map(t => FlatCompatRuleTester._flatCompat(t)), - ), + valid: tests.valid.map(t => FlatCompatRuleTester._flatCompat(t)), + invalid: tests.invalid.map(t => FlatCompatRuleTester._flatCompat(t)), }); } - /* istanbul ignore next */ - /** - * Filters out test cases that are using ecma version 2022 or higher when running - * on ESLint v7 - * @private - */ - private static _filterCases< - T extends - | string - | TSESLint.ValidTestCase - | TSESLint.InvalidTestCase, - >(tests: T[]): T[] { - if (semver.major(eslintVersion) > 7) { - return tests; - } - - const filtered = tests.filter( - t => - typeof t === 'string' || - !t.parserOptions?.ecmaVersion || - t.parserOptions.ecmaVersion === 'latest' || - t.parserOptions.ecmaVersion < 2022, - ); - - // print the number of tests that were filtered - if (filtered.length !== tests.length) { - console.warn( - `Filtered ${tests.length - filtered.length} tests due to unsupported parser options.`, - ); - } - - return filtered; - } - /* istanbul ignore next */ private static _flatCompat< T extends diff --git a/src/rules/expect-expect.ts b/src/rules/expect-expect.ts index 73f097889..94145bfc2 100644 --- a/src/rules/expect-expect.ts +++ b/src/rules/expect-expect.ts @@ -6,8 +6,6 @@ import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils'; import { createRule, - getAncestors, - getDeclaredVariables, getNodeName, getTestCallExpressionsFromDeclaredVariables, isSupportedAccessor, @@ -94,7 +92,8 @@ export default createRule< : -1; if (node.type === AST_NODE_TYPES.FunctionDeclaration) { - const declaredVariables = getDeclaredVariables(context, node); + const declaredVariables = + context.sourceCode.getDeclaredVariables(node); const testCallExpressions = getTestCallExpressionsFromDeclaredVariables( declaredVariables, @@ -129,7 +128,7 @@ export default createRule< unchecked.push(node); } else if (matchesAssertFunctionName(name, assertFunctionNames)) { // Return early in case of nested `it` statements. - checkCallExpressionUsed(getAncestors(context, node)); + checkCallExpressionUsed(context.sourceCode.getAncestors(node)); } }, 'Program:exit'() { diff --git a/src/rules/no-commented-out-tests.ts b/src/rules/no-commented-out-tests.ts index 5b8cd9a50..39428ac72 100644 --- a/src/rules/no-commented-out-tests.ts +++ b/src/rules/no-commented-out-tests.ts @@ -1,5 +1,5 @@ import type { TSESTree } from '@typescript-eslint/utils'; -import { createRule, getSourceCode } from './utils'; +import { createRule } from './utils'; function hasTests(node: TSESTree.Comment) { return /^\s*[xf]?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/mu.test( @@ -21,7 +21,7 @@ export default createRule({ }, defaultOptions: [], create(context) { - const sourceCode = getSourceCode(context); + const { sourceCode } = context; function checkNode(node: TSESTree.Comment) { if (!hasTests(node)) { diff --git a/src/rules/no-conditional-expect.ts b/src/rules/no-conditional-expect.ts index 31e7d3ada..0281467d3 100644 --- a/src/rules/no-conditional-expect.ts +++ b/src/rules/no-conditional-expect.ts @@ -2,7 +2,6 @@ import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils'; import { type KnownCallExpression, createRule, - getDeclaredVariables, getTestCallExpressionsFromDeclaredVariables, isSupportedAccessor, isTypeOfJestFnCall, @@ -38,7 +37,7 @@ export default createRule({ return { FunctionDeclaration(node) { - const declaredVariables = getDeclaredVariables(context, node); + const declaredVariables = context.sourceCode.getDeclaredVariables(node); const testCallExpressions = getTestCallExpressionsFromDeclaredVariables( declaredVariables, context, diff --git a/src/rules/no-confusing-set-timeout.ts b/src/rules/no-confusing-set-timeout.ts index f295a36fb..e67d1721f 100644 --- a/src/rules/no-confusing-set-timeout.ts +++ b/src/rules/no-confusing-set-timeout.ts @@ -1,7 +1,6 @@ import { type ParsedJestFnCall, createRule, - getScope, isIdentifier, parseJestFnCall, } from './utils'; @@ -49,7 +48,9 @@ export default createRule({ return; } - if (!['global', 'module'].includes(getScope(context, node).type)) { + if ( + !['global', 'module'].includes(context.sourceCode.getScope(node).type) + ) { context.report({ messageId: 'globalSetTimeout', node }); } diff --git a/src/rules/no-disabled-tests.ts b/src/rules/no-disabled-tests.ts index cfce626b0..093db7812 100644 --- a/src/rules/no-disabled-tests.ts +++ b/src/rules/no-disabled-tests.ts @@ -1,7 +1,6 @@ import { createRule, getAccessorValue, - getScope, parseJestFnCall, resolveScope, } from './utils'; @@ -50,7 +49,7 @@ export default createRule({ } }, 'CallExpression[callee.name="pending"]'(node) { - if (resolveScope(getScope(context, node), 'pending')) { + if (resolveScope(context.sourceCode.getScope(node), 'pending')) { return; } diff --git a/src/rules/no-done-callback.ts b/src/rules/no-done-callback.ts index c7a43d34e..0806eaafe 100644 --- a/src/rules/no-done-callback.ts +++ b/src/rules/no-done-callback.ts @@ -3,14 +3,7 @@ import { type TSESLint, type TSESTree, } from '@typescript-eslint/utils'; -import { - createRule, - getFilename, - getNodeName, - getSourceCode, - isFunction, - parseJestFnCall, -} from './utils'; +import { createRule, getNodeName, isFunction, parseJestFnCall } from './utils'; const findCallbackArg = ( node: TSESTree.CallExpression, @@ -109,7 +102,7 @@ export default createRule({ fix(fixer) { const { body, params } = callback; - const sourceCode = getSourceCode(context); + const { sourceCode } = context; const firstBodyToken = sourceCode.getFirstToken(body); const lastBodyToken = sourceCode.getLastToken(body); @@ -133,7 +126,7 @@ export default createRule({ !tokenAfterLastParam ) { throw new Error( - `Unexpected null when attempting to fix ${getFilename(context)} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`, + `Unexpected null when attempting to fix ${context.filename} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`, ); } diff --git a/src/rules/no-jasmine-globals.ts b/src/rules/no-jasmine-globals.ts index 6d0d122dd..59be150d4 100644 --- a/src/rules/no-jasmine-globals.ts +++ b/src/rules/no-jasmine-globals.ts @@ -2,7 +2,6 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import { createRule, getNodeName, - getScope, isSupportedAccessor, resolveScope, } from './utils'; @@ -45,7 +44,7 @@ export default createRule({ calleeName === 'fail' || calleeName === 'pending' ) { - if (resolveScope(getScope(context, node), calleeName)) { + if (resolveScope(context.sourceCode.getScope(node), calleeName)) { // It's a local variable, not a jasmine global. return; } diff --git a/src/rules/no-large-snapshots.ts b/src/rules/no-large-snapshots.ts index c9aee9b87..3d7c89630 100644 --- a/src/rules/no-large-snapshots.ts +++ b/src/rules/no-large-snapshots.ts @@ -7,7 +7,6 @@ import { import { createRule, getAccessorValue, - getFilename, isSupportedAccessor, parseJestFnCall, } from './utils'; @@ -47,7 +46,7 @@ const reportOnViolation = ( node.expression.left.type === AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.expression.left.property) ) { - const fileName = getFilename(context); + const fileName = context.filename; const allowedSnapshotsInFile = allowedSnapshots[fileName]; if (allowedSnapshotsInFile) { @@ -106,7 +105,7 @@ export default createRule<[RuleOptions], MessageId>({ }, defaultOptions: [{}], create(context, [options]) { - if (getFilename(context).endsWith('.snap')) { + if (context.filename.endsWith('.snap')) { return { ExpressionStatement(node) { reportOnViolation(context, node, options); diff --git a/src/rules/no-test-return-statement.ts b/src/rules/no-test-return-statement.ts index 6cde8e75d..759290283 100644 --- a/src/rules/no-test-return-statement.ts +++ b/src/rules/no-test-return-statement.ts @@ -1,7 +1,6 @@ import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils'; import { createRule, - getDeclaredVariables, getTestCallExpressionsFromDeclaredVariables, isFunction, isTypeOfJestFnCall, @@ -53,7 +52,7 @@ export default createRule({ context.report({ messageId: 'noReturnValue', node: returnStmt }); }, FunctionDeclaration(node) { - const declaredVariables = getDeclaredVariables(context, node); + const declaredVariables = context.sourceCode.getDeclaredVariables(node); const testCallExpressions = getTestCallExpressionsFromDeclaredVariables( declaredVariables, context, diff --git a/src/rules/prefer-comparison-matcher.ts b/src/rules/prefer-comparison-matcher.ts index ec356f656..a303d019f 100644 --- a/src/rules/prefer-comparison-matcher.ts +++ b/src/rules/prefer-comparison-matcher.ts @@ -4,7 +4,6 @@ import { createRule, getAccessorValue, getFirstMatcherArg, - getSourceCode, isBooleanLiteral, isStringNode, parseJestFnCall, @@ -115,7 +114,7 @@ export default createRule({ context.report({ fix(fixer) { - const sourceCode = getSourceCode(context); + const { sourceCode } = context; // preserve the existing modifier if it's not a negation const modifierText = diff --git a/src/rules/prefer-equality-matcher.ts b/src/rules/prefer-equality-matcher.ts index 02932692e..4b482801a 100644 --- a/src/rules/prefer-equality-matcher.ts +++ b/src/rules/prefer-equality-matcher.ts @@ -5,7 +5,6 @@ import { createRule, getAccessorValue, getFirstMatcherArg, - getSourceCode, isBooleanLiteral, parseJestFnCall, } from './utils'; @@ -73,7 +72,7 @@ export default createRule({ const buildFixer = (equalityMatcher: string): TSESLint.ReportFixFunction => fixer => { - const sourceCode = getSourceCode(context); + const { sourceCode } = context; // preserve the existing modifier if it's not a negation let modifierText = diff --git a/src/rules/prefer-importing-jest-globals.ts b/src/rules/prefer-importing-jest-globals.ts index 862a7d5fb..836c7fbc3 100644 --- a/src/rules/prefer-importing-jest-globals.ts +++ b/src/rules/prefer-importing-jest-globals.ts @@ -3,7 +3,6 @@ import { type JestFnType, createRule, getAccessorValue, - getSourceCode, isIdentifier, isStringNode, isSupportedAccessor, @@ -94,7 +93,7 @@ export default createRule({ messageId: 'preferImportingJestGlobal', data: { jestFunctions: Array.from(functionsToImport).join(', ') }, fix(fixer) { - const sourceCode = getSourceCode(context); + const { sourceCode } = context; const [firstNode] = sourceCode.ast.body; // check if "use strict" directive exists diff --git a/src/rules/prefer-jest-mocked.ts b/src/rules/prefer-jest-mocked.ts index 6389871a5..d462a696c 100644 --- a/src/rules/prefer-jest-mocked.ts +++ b/src/rules/prefer-jest-mocked.ts @@ -1,5 +1,5 @@ import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils'; -import { createRule, followTypeAssertionChain, getSourceCode } from './utils'; +import { createRule, followTypeAssertionChain } from './utils'; const mockTypes = ['Mock', 'MockedFunction', 'MockedClass', 'MockedObject']; @@ -42,7 +42,7 @@ export default createRule({ return; } - const fnName = getSourceCode(context).text.slice( + const fnName = context.sourceCode.text.slice( ...followTypeAssertionChain(node.expression).range, ); diff --git a/src/rules/prefer-mock-promise-shorthand.ts b/src/rules/prefer-mock-promise-shorthand.ts index c32a456b7..008d276aa 100644 --- a/src/rules/prefer-mock-promise-shorthand.ts +++ b/src/rules/prefer-mock-promise-shorthand.ts @@ -5,7 +5,6 @@ import { createRule, getAccessorValue, getNodeName, - getSourceCode, isFunction, isSupportedAccessor, } from './utils'; @@ -69,7 +68,7 @@ export default createRule({ messageId: 'useMockShorthand', data: { replacement }, fix(fixer) { - const sourceCode = getSourceCode(context); + const { sourceCode } = context; // there shouldn't be more than one argument, but if there is don't try // fixing since we have no idea what to do with the extra arguments diff --git a/src/rules/prefer-spy-on.ts b/src/rules/prefer-spy-on.ts index c01ae1157..98b14a529 100644 --- a/src/rules/prefer-spy-on.ts +++ b/src/rules/prefer-spy-on.ts @@ -3,7 +3,7 @@ import { type TSESLint, type TSESTree, } from '@typescript-eslint/utils'; -import { createRule, getNodeName, getSourceCode } from './utils'; +import { createRule, getNodeName } from './utils'; const findNodeObject = ( node: TSESTree.CallExpression | TSESTree.MemberExpression, @@ -57,7 +57,7 @@ const getAutoFixMockImplementation = ( } const [arg] = jestFnCall.arguments; - const argSource = arg && getSourceCode(context).getText(arg); + const argSource = arg && context.sourceCode.getText(arg); return argSource ? `.mockImplementation(${argSource})` diff --git a/src/rules/prefer-to-contain.ts b/src/rules/prefer-to-contain.ts index b062e1f8b..c31e967aa 100644 --- a/src/rules/prefer-to-contain.ts +++ b/src/rules/prefer-to-contain.ts @@ -7,7 +7,6 @@ import { createRule, getAccessorValue, getFirstMatcherArg, - getSourceCode, hasOnlyOneArgument, isBooleanLiteral, isSupportedAccessor, @@ -88,7 +87,7 @@ export default createRule({ context.report({ fix(fixer) { - const sourceCode = getSourceCode(context); + const { sourceCode } = context; // we need to negate the expectation if the current expected // value is itself negated by the "not" modifier diff --git a/src/rules/unbound-method.ts b/src/rules/unbound-method.ts index 862c66df1..ddb7587e4 100644 --- a/src/rules/unbound-method.ts +++ b/src/rules/unbound-method.ts @@ -48,16 +48,6 @@ export type MessageIds = 'unbound' | 'unboundWithoutThisAnnotation'; const DEFAULT_MESSAGE = 'This rule requires `@typescript-eslint/eslint-plugin`'; -// todo: remove these along with the actual runtime properties below in new major -declare module '@typescript-eslint/utils/ts-eslint' { - interface RuleMetaDataDocs { - /** @deprecated */ - requiresTypeChecking?: boolean; - /** @deprecated */ - recommended?: unknown; - } -} - export default createRule({ defaultOptions: [{ ignoreStatic: false }], ...baseRule, @@ -73,12 +63,7 @@ export default createRule({ docs: { description: 'Enforce unbound methods are called with their expected scope', - /** @deprecated */ - requiresTypeChecking: true, ...baseRule?.meta.docs, - // mark this as not recommended - /** @deprecated */ - recommended: undefined, }, }, create(context) { diff --git a/src/rules/utils/misc.ts b/src/rules/utils/misc.ts index 15c886487..71c8c91e1 100644 --- a/src/rules/utils/misc.ts +++ b/src/rules/utils/misc.ts @@ -174,7 +174,7 @@ export const removeExtraArgumentsFixer = ( const firstArg = func.arguments[from]; const lastArg = func.arguments[func.arguments.length - 1]; - const sourceCode = getSourceCode(context); + const { sourceCode } = context; let tokenAfterLastParam = sourceCode.getTokenAfter(lastArg)!; if (tokenAfterLastParam.value === ',') { @@ -225,44 +225,3 @@ export const getFirstMatcherArg = ( return followTypeAssertionChain(firstArg); }; - -/* istanbul ignore next */ -export const getFilename = ( - context: TSESLint.RuleContext, -) => { - return context.filename ?? context.getFilename(); -}; - -/* istanbul ignore next */ -export const getSourceCode = ( - context: TSESLint.RuleContext, -) => { - return context.sourceCode ?? context.getSourceCode(); -}; - -/* istanbul ignore next */ -export const getScope = ( - context: TSESLint.RuleContext, - node: TSESTree.Node, -) => { - return getSourceCode(context).getScope?.(node) ?? context.getScope(); -}; - -/* istanbul ignore next */ -export const getAncestors = ( - context: TSESLint.RuleContext, - node: TSESTree.Node, -) => { - return getSourceCode(context).getAncestors?.(node) ?? context.getAncestors(); -}; - -/* istanbul ignore next */ -export const getDeclaredVariables = ( - context: TSESLint.RuleContext, - node: TSESTree.Node, -) => { - return ( - getSourceCode(context).getDeclaredVariables?.(node) ?? - context.getDeclaredVariables(node) - ); -}; diff --git a/src/rules/utils/padding.ts b/src/rules/utils/padding.ts index edd071b05..43fb9a130 100644 --- a/src/rules/utils/padding.ts +++ b/src/rules/utils/padding.ts @@ -15,7 +15,7 @@ import { type TSESTree, } from '@typescript-eslint/utils'; import * as astUtils from './ast-utils'; -import { createRule, getSourceCode } from './misc'; +import { createRule } from './misc'; // Statement types we'll respond to export const enum StatementType { @@ -353,7 +353,7 @@ export const createPaddingRule = ( create(context) { const paddingContext = { ruleContext: context, - sourceCode: getSourceCode(context), + sourceCode: context.sourceCode, scopeInfo: createScopeInfo(), configs, }; diff --git a/src/rules/utils/parseJestFnCall.ts b/src/rules/utils/parseJestFnCall.ts index 720907d7d..c74ea1426 100644 --- a/src/rules/utils/parseJestFnCall.ts +++ b/src/rules/utils/parseJestFnCall.ts @@ -12,7 +12,6 @@ import { TestCaseName, findTopMostCallExpression, getAccessorValue, - getScope, getStringValue, isIdentifier, isStringNode, @@ -578,7 +577,10 @@ const resolveToJestFn = ( accessor: AccessorNode, ): ResolvedJestFn | null => { const identifier = getAccessorValue(accessor); - const maybeImport = resolveScope(getScope(context, accessor), identifier); + const maybeImport = resolveScope( + context.sourceCode.getScope(accessor), + identifier, + ); // the identifier was found as a local variable or function declaration // meaning it's not a function from jest diff --git a/src/rules/valid-expect.ts b/src/rules/valid-expect.ts index b31496411..a643467aa 100644 --- a/src/rules/valid-expect.ts +++ b/src/rules/valid-expect.ts @@ -13,7 +13,6 @@ import { ModifierName, createRule, getAccessorValue, - getSourceCode, isFunction, isSupportedAccessor, parseJestFnCallWithReason, @@ -416,7 +415,7 @@ export default createRule<[Options], MessageIds>({ if (alwaysAwait && returnStatement) { const sourceCodeText = - getSourceCode(context).getText(returnStatement); + context.sourceCode.getText(returnStatement); const replacedText = sourceCodeText.replace('return', 'await'); fixes.push(fixer.replaceText(returnStatement, replacedText)); diff --git a/tsconfig.json b/tsconfig.json index bf3a1fbf5..57a4175f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "@tsconfig/node16/tsconfig.json", + "extends": "@tsconfig/node20/tsconfig.json", "compilerOptions": { "noEmit": true, "stripInternal": true, diff --git a/yarn.lock b/yarn.lock index a89a3780a..7ae0f1f07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2667,10 +2667,10 @@ __metadata: languageName: node linkType: hard -"@tsconfig/node16@npm:^16.0.0": - version: 16.1.4 - resolution: "@tsconfig/node16@npm:16.1.4" - checksum: 99ed9232899f6e92b2c05cd7c7d16bae7dd9250d14d1af5d8f280023a47960c14c1ba4184e600231a21d70f02c2b2dba3ceb92e643b57aede1eaee2232a732c4 +"@tsconfig/node20@npm:^20.0.0": + version: 20.1.5 + resolution: "@tsconfig/node20@npm:20.1.5" + checksum: 6d689785f7b6ffd09d2cd0565290235ddc650932f6c110701dd38732b3c0b57ba039a3663268ae4a16b855d55ec2fbd48a53910e5a5fc7f196caaa4074dd0a53 languageName: node linkType: hard @@ -2830,10 +2830,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^16.0.0": - version: 16.18.126 - resolution: "@types/node@npm:16.18.126" - checksum: 86112e7499f8a4d1bb60696cab0bf464adf3c141fca4bc5451e8f3aba5736529b76d4b4396edb21e5d7c19592852f7d6cb81ee70074fd13bde2db2d0db720467 +"@types/node@npm:^20.0.0": + version: 20.19.1 + resolution: "@types/node@npm:20.19.1" + dependencies: + undici-types: ~6.21.0 + checksum: f2883d8e2325af18424c625cc01ba2276c933ae8fc7aba93042fb757da075eabef0d2e22775e5706a74b67687d3cb06d6d42248d966c1e6bf8a2755457e537c7 languageName: node linkType: hard @@ -2889,39 +2891,52 @@ __metadata: linkType: hard "@typescript-eslint/eslint-plugin@npm:^8.0.0": - version: 8.34.0 - resolution: "@typescript-eslint/eslint-plugin@npm:8.34.0" + version: 8.33.1 + resolution: "@typescript-eslint/eslint-plugin@npm:8.33.1" dependencies: "@eslint-community/regexpp": ^4.10.0 - "@typescript-eslint/scope-manager": 8.34.0 - "@typescript-eslint/type-utils": 8.34.0 - "@typescript-eslint/utils": 8.34.0 - "@typescript-eslint/visitor-keys": 8.34.0 + "@typescript-eslint/scope-manager": 8.33.1 + "@typescript-eslint/type-utils": 8.33.1 + "@typescript-eslint/utils": 8.33.1 + "@typescript-eslint/visitor-keys": 8.33.1 graphemer: ^1.4.0 ignore: ^7.0.0 natural-compare: ^1.4.0 ts-api-utils: ^2.1.0 peerDependencies: - "@typescript-eslint/parser": ^8.34.0 + "@typescript-eslint/parser": ^8.33.1 eslint: ^8.57.0 || ^9.0.0 typescript: ">=4.8.4 <5.9.0" - checksum: f5d4a57d0661bea3b15b8842abeae3327828647540e8127c882d44cbf793e84d4c9e33b6740f682891ddf20ca664a634b7016289e1bc98ae21f02808498a28ec + checksum: 8732c42790728335c7f07947892302b5454340f0d4d80b2afaca33d1612e4ac8ad8c46b123337c207fe16b80964bd860992fc63b74addf8495bc6a61f7b9a18c languageName: node linkType: hard "@typescript-eslint/parser@npm:^8.0.0": - version: 8.34.0 - resolution: "@typescript-eslint/parser@npm:8.34.0" + version: 8.33.1 + resolution: "@typescript-eslint/parser@npm:8.33.1" dependencies: - "@typescript-eslint/scope-manager": 8.34.0 - "@typescript-eslint/types": 8.34.0 - "@typescript-eslint/typescript-estree": 8.34.0 - "@typescript-eslint/visitor-keys": 8.34.0 + "@typescript-eslint/scope-manager": 8.33.1 + "@typescript-eslint/types": 8.33.1 + "@typescript-eslint/typescript-estree": 8.33.1 + "@typescript-eslint/visitor-keys": 8.33.1 debug: ^4.3.4 peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: ">=4.8.4 <5.9.0" - checksum: 7b6797c4d87e8b2e24f99bd2e9c4102366b8f77f4a2912f810df01d7b655524304859e0adef12c21dbbe986bacc7e45d35845d8c4439193350c38d8a14bb7ef7 + checksum: 2b527529a11738001a85494ceb56352a902d02989394ad480311fc273aa06ac282c039649433ed6396008a93c37b5d4d1c9bb5598b1526674e4d08dc2fccabe2 + languageName: node + linkType: hard + +"@typescript-eslint/project-service@npm:8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/project-service@npm:8.33.1" + dependencies: + "@typescript-eslint/tsconfig-utils": ^8.33.1 + "@typescript-eslint/types": ^8.33.1 + debug: ^4.3.4 + peerDependencies: + typescript: ">=4.8.4 <5.9.0" + checksum: 237618a025c11587d079ce82c289a43579c422ff134a32b08ef3804e5bac7632c692f7acd49d1e6520c55f41edfdabf54069c9d460d1a5e05e051027657c96b0 languageName: node linkType: hard @@ -2938,6 +2953,16 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/scope-manager@npm:8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/scope-manager@npm:8.33.1" + dependencies: + "@typescript-eslint/types": 8.33.1 + "@typescript-eslint/visitor-keys": 8.33.1 + checksum: fbc3ec340f4a0a9541f5898e44137ce1cb10678a8347ebce9b216342e50041c54d59515e34335fb3869db56ec3c2807408894d19a4aee53fd4ca183316008ffb + languageName: node + linkType: hard + "@typescript-eslint/scope-manager@npm:8.34.0": version: 8.34.0 resolution: "@typescript-eslint/scope-manager@npm:8.34.0" @@ -2948,6 +2973,15 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/tsconfig-utils@npm:8.33.1, @typescript-eslint/tsconfig-utils@npm:^8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/tsconfig-utils@npm:8.33.1" + peerDependencies: + typescript: ">=4.8.4 <5.9.0" + checksum: 9e0e348af4d54b7e42a015bf36e08965c8fa389ac7b179c2ccf2bec5fce4b31e951397394dcbaea6fb0ddf782f4f2f2ee71df108173742f756705f82d653cc9d + languageName: node + linkType: hard + "@typescript-eslint/tsconfig-utils@npm:8.34.0, @typescript-eslint/tsconfig-utils@npm:^8.34.0": version: 8.34.0 resolution: "@typescript-eslint/tsconfig-utils@npm:8.34.0" @@ -2957,18 +2991,25 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:8.34.0": - version: 8.34.0 - resolution: "@typescript-eslint/type-utils@npm:8.34.0" +"@typescript-eslint/type-utils@npm:8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/type-utils@npm:8.33.1" dependencies: - "@typescript-eslint/typescript-estree": 8.34.0 - "@typescript-eslint/utils": 8.34.0 + "@typescript-eslint/typescript-estree": 8.33.1 + "@typescript-eslint/utils": 8.33.1 debug: ^4.3.4 ts-api-utils: ^2.1.0 peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: ">=4.8.4 <5.9.0" - checksum: 97046c06edc6d15363f9a1e08ace2f774def8b903b42bf32db6e7f944f0f308273583b0ddd86c013e3f945bc15862d11625ff0d63578cc0b6f94a881f7337cef + checksum: 54099177a52d69fdb19bf12006c3ef543f54dde0772166e7986d085b11acc03eec7cc321450b3d98808c860b555b63476c1739409a4ca36c2635452c1f941cf2 + languageName: node + linkType: hard + +"@typescript-eslint/types@npm:8.33.1, @typescript-eslint/types@npm:^8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/types@npm:8.33.1" + checksum: 80ad8b857324da1778e0dd7af213b18ff18abb0a4fd600a80379e68fdec17c1f0dc2e2bb29667b0c4d9f1a113978d0bef71eb380fe95d239247f4b58d24af32f languageName: node linkType: hard @@ -2979,6 +3020,26 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/typescript-estree@npm:8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/typescript-estree@npm:8.33.1" + dependencies: + "@typescript-eslint/project-service": 8.33.1 + "@typescript-eslint/tsconfig-utils": 8.33.1 + "@typescript-eslint/types": 8.33.1 + "@typescript-eslint/visitor-keys": 8.33.1 + debug: ^4.3.4 + fast-glob: ^3.3.2 + is-glob: ^4.0.3 + minimatch: ^9.0.4 + semver: ^7.6.0 + ts-api-utils: ^2.1.0 + peerDependencies: + typescript: ">=4.8.4 <5.9.0" + checksum: aacb9252572be7079252dd3798e99ec0f8b7eee6875ab431fe2f646705ea1f9f968d26a0611b9d02080ed1da1986280f3b9df5ad15e9a7b54026ae274fc435fd + languageName: node + linkType: hard + "@typescript-eslint/typescript-estree@npm:8.34.0": version: 8.34.0 resolution: "@typescript-eslint/typescript-estree@npm:8.34.0" @@ -2999,7 +3060,22 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/utils@npm:8.34.0, @typescript-eslint/utils@npm:^8.0.0, @typescript-eslint/utils@npm:^8.26.1": +"@typescript-eslint/utils@npm:8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/utils@npm:8.33.1" + dependencies: + "@eslint-community/eslint-utils": ^4.7.0 + "@typescript-eslint/scope-manager": 8.33.1 + "@typescript-eslint/types": 8.33.1 + "@typescript-eslint/typescript-estree": 8.33.1 + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + typescript: ">=4.8.4 <5.9.0" + checksum: aef41fe93d7137336cd8bcc05ea56b55dfa86e2616a86176f51ee867607263a33eee025a2130d586a6a27d7e0564c9593bb3786073425dccd82b910e43984fae + languageName: node + linkType: hard + +"@typescript-eslint/utils@npm:^8.0.0, @typescript-eslint/utils@npm:^8.26.1": version: 8.34.0 resolution: "@typescript-eslint/utils@npm:8.34.0" dependencies: @@ -3014,6 +3090,16 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/visitor-keys@npm:8.33.1": + version: 8.33.1 + resolution: "@typescript-eslint/visitor-keys@npm:8.33.1" + dependencies: + "@typescript-eslint/types": 8.33.1 + eslint-visitor-keys: ^4.2.0 + checksum: d8bbb35ff28aaa11313d1bf6871efe343862836a0ca1083d833227a7426be7c8c791a4abc1cd0e3d86c5c0ad371fd72a3ef018e92c73e17fc75a789ca40a2e41 + languageName: node + linkType: hard + "@typescript-eslint/visitor-keys@npm:8.34.0": version: 8.34.0 resolution: "@typescript-eslint/visitor-keys@npm:8.34.0" @@ -5146,10 +5232,10 @@ __metadata: "@schemastore/package": ^0.0.10 "@semantic-release/changelog": ^6.0.0 "@semantic-release/git": ^10.0.0 - "@tsconfig/node16": ^16.0.0 + "@tsconfig/node20": ^20.0.0 "@types/eslint": ^8.4.6 "@types/jest": ^29.0.0 - "@types/node": ^16.0.0 + "@types/node": ^20.0.0 "@types/semver": ^7.5.8 "@typescript-eslint/eslint-plugin": ^8.0.0 "@typescript-eslint/parser": ^8.0.0 @@ -5157,7 +5243,7 @@ __metadata: babel-jest: ^29.0.0 babel-plugin-replace-ts-export-assignment: ^0.0.2 dedent: ^1.5.0 - eslint: ^7.0.0 || ^8.0.0 + eslint: ^8.57.0 eslint-config-prettier: ^10.0.0 eslint-doc-generator: ^2.0.0 eslint-plugin-eslint-plugin: ^6.0.0 @@ -5180,8 +5266,8 @@ __metadata: ts-node: ^10.2.1 typescript: ^5.0.4 peerDependencies: - "@typescript-eslint/eslint-plugin": ^6.0.0 || ^7.0.0 || ^8.0.0 - eslint: ^7.0.0 || ^8.0.0 || ^9.0.0 + "@typescript-eslint/eslint-plugin": ^8.0.0 + eslint: ^8.57.0 || ^9.0.0 jest: "*" peerDependenciesMeta: "@typescript-eslint/eslint-plugin": @@ -5285,7 +5371,7 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^7.0.0 || ^8.0.0": +"eslint@npm:^8.57.0": version: 8.57.1 resolution: "eslint@npm:8.57.1" dependencies: @@ -11399,6 +11485,13 @@ __metadata: languageName: node linkType: hard +"undici-types@npm:~6.21.0": + version: 6.21.0 + resolution: "undici-types@npm:6.21.0" + checksum: 46331c7d6016bf85b3e8f20c159d62f5ae471aba1eb3dc52fff35a0259d58dcc7d592d4cc4f00c5f9243fa738a11cfa48bd20203040d4a9e6bc25e807fab7ab3 + languageName: node + linkType: hard + "undici-types@npm:~7.8.0": version: 7.8.0 resolution: "undici-types@npm:7.8.0"