Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# [29.0.0](https://github.com/jest-community/eslint-plugin-jest/compare/v28.14.0...v29.0.0) (2025-06-18)


### Bug Fixes

* remove `jest/no-alias-methods` from `styles` config ([d3bf1dc](https://github.com/jest-community/eslint-plugin-jest/commit/d3bf1dcec9322304a37fe45e6a5cdeee7775c543))


### Features

* drop support for `[@typescript-eslint](https://github.com/typescript-eslint)` v6 ([fe61a40](https://github.com/jest-community/eslint-plugin-jest/commit/fe61a409d41ef4e7ab8137b8b3d3f66cee6d40a6))
* drop support for `[@typescript-eslint](https://github.com/typescript-eslint)` v7 ([5ca65d3](https://github.com/jest-community/eslint-plugin-jest/commit/5ca65d3f941e5c0684876c20f251e2d467fc5a15))
* drop support for ESLint v7 ([b06e7d0](https://github.com/jest-community/eslint-plugin-jest/commit/b06e7d000fd730c24c7eb7a21d34e5cf92b30835))
* drop support for ESLint v8.x prior to v8.57.0 ([d79765a](https://github.com/jest-community/eslint-plugin-jest/commit/d79765af01e67db6646d3416cbf26df6bab414e7))
* drop support for Node v16 ([aaf62cd](https://github.com/jest-community/eslint-plugin-jest/commit/aaf62cd0da1ada072101d4d84b6a66a35d82425c))
* drop support for Node v18 ([598880c](https://github.com/jest-community/eslint-plugin-jest/commit/598880c4cb26eed177d1efdf3f8d4293956b58ac))
* drop support for Node v20.x prior to v20.12.0 ([2f2fb68](https://github.com/jest-community/eslint-plugin-jest/commit/2f2fb68db315388230fe5bcefbcafcc2716e07e4))
* drop support for Node v21 ([a366393](https://github.com/jest-community/eslint-plugin-jest/commit/a366393fb38a55c91d0200791315e727fcfe3e90))
* drop support for Node v23 ([1fb1a67](https://github.com/jest-community/eslint-plugin-jest/commit/1fb1a6747ed0f15ce4532624715c2b2a079e18f2))
* **unbound-method:** remove `docs.recommended` and `docs.requiresTypeChecking` properties ([945651c](https://github.com/jest-community/eslint-plugin-jest/commit/945651c36c471f424b743f0aae3ccca6271f21ba))


### BREAKING CHANGES

* dropped support for ESLint v8.x prior to v8.57.0
* dropped support for Node v20.x prior to v20.12.0
* dropped support for Node v23
* dropped support for Node v18
* **unbound-method:** removed `docs.recommend` and `docs.requiresTypeChecking` from `unbound-method`
* dropped support for `@typescript-eslint` v7
* dropped support for `@typescript-eslint` v6
* `jest/no-alias-methods` has been removed from the `styles` config as its already in
the `recommended` config
* dropped support for ESLint v7
* dropped support for Node v21
* dropped support for Node v16

# [28.14.0](https://github.com/jest-community/eslint-plugin-jest/compare/v28.13.5...v28.14.0) (2025-06-15)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | | | | |
Expand Down
4 changes: 1 addition & 3 deletions docs/rules/no-alias-methods.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-jest",
"version": "28.14.0",
"version": "29.0.0",
"description": "ESLint rules for Jest",
"keywords": [
"eslint",
Expand Down Expand Up @@ -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",
Expand All @@ -80,18 +80,18 @@
"@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",
"@typescript-eslint/utils": "^8.0.0",
"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",
Expand All @@ -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": {
Expand All @@ -129,7 +129,7 @@
},
"packageManager": "[email protected]",
"engines": {
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
"node": "^20.12.0 || ^22.0.0 || >=24.0.0"
},
"publishConfig": {
"provenance": true
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/__snapshots__/rules.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const recommendedRules = {
} satisfies Record<string, TSESLint.Linter.RuleLevel>;

const styleRules = {
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
Expand Down
45 changes: 3 additions & 42 deletions src/rules/__tests__/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -25,49 +24,11 @@ export class FlatCompatRuleTester extends TSESLint.RuleTester {
tests: TSESLint.RunTests<TMessageIds, TOptions>,
) {
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<unknown[]>
| TSESLint.InvalidTestCase<string, unknown[]>,
>(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
Expand Down
7 changes: 3 additions & 4 deletions src/rules/expect-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils';
import {
createRule,
getAncestors,
getDeclaredVariables,
getNodeName,
getTestCallExpressionsFromDeclaredVariables,
isSupportedAccessor,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'() {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-commented-out-tests.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)) {
Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-conditional-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils';
import {
type KnownCallExpression,
createRule,
getDeclaredVariables,
getTestCallExpressionsFromDeclaredVariables,
isSupportedAccessor,
isTypeOfJestFnCall,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/rules/no-confusing-set-timeout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type ParsedJestFnCall,
createRule,
getScope,
isIdentifier,
parseJestFnCall,
} from './utils';
Expand Down Expand Up @@ -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 });
}

Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-disabled-tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
createRule,
getAccessorValue,
getScope,
parseJestFnCall,
resolveScope,
} from './utils';
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 3 additions & 10 deletions src/rules/no-done-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand All @@ -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`,
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-jasmine-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import {
createRule,
getNodeName,
getScope,
isSupportedAccessor,
resolveScope,
} from './utils';
Expand Down Expand Up @@ -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;
}
Expand Down
Loading