Skip to content

Commit

Permalink
Merge branch 'jest-community:main' into prefer-jest-globals
Browse files Browse the repository at this point in the history
  • Loading branch information
MadeinFrance committed Mar 8, 2024
2 parents fa44e3b + a5ca480 commit cddb7f3
Show file tree
Hide file tree
Showing 15 changed files with 1,192 additions and 466 deletions.
Binary file removed .DS_Store
Binary file not shown.
8 changes: 7 additions & 1 deletion .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ const { prettier: prettierRC } = require('./package.json');

/** @type {import('eslint-doc-generator').GenerateOptions} */
const config = {
ignoreConfig: ['all'],
ignoreConfig: [
'all',
'flat/all',
'flat/recommended',
'flat/style',
'flat/snapshots',
],
ruleDocTitleFormat: 'desc-parens-name',
ruleDocSectionInclude: ['Rule details'],
ruleListColumns: [
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,23 @@ jobs:
matrix:
node-version: [14.x, 16.x, 18.x, 19.x, 20.x, 21.x]
eslint-version: [7, 8]
ts-eslint-plugin-version: [5, 6]
ts-eslint-plugin-version: [5, 6, 7]
exclude:
# ts-eslint/plugin@6 doesn't support node@14
- node-version: 14.x
ts-eslint-plugin-version: 6
# ts-eslint/plugin@7 doesn't support node@14
- node-version: 14.x
ts-eslint-plugin-version: 7
# ts-eslint/plugin@7 doesn't support node@16
- node-version: 16.x
ts-eslint-plugin-version: 7
# ts-eslint/plugin@7 doesn't support node@19
- node-version: 19.x
ts-eslint-plugin-version: 7
# ts-eslint/plugin@7 doesn't support eslint@7
- eslint-version: 7
ts-eslint-plugin-version: 7
runs-on: ubuntu-latest

steps:
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# [27.9.0](https://github.com/jest-community/eslint-plugin-jest/compare/v27.8.0...v27.9.0) (2024-02-16)


### Features

* add should-be-fine support for flat configs ([#1505](https://github.com/jest-community/eslint-plugin-jest/issues/1505)) ([4cc2a1b](https://github.com/jest-community/eslint-plugin-jest/commit/4cc2a1b680507ff006b5d2b02fa6d262584bb263))

# [27.8.0](https://github.com/jest-community/eslint-plugin-jest/compare/v27.7.0...v27.8.0) (2024-02-13)


### Features

* support `failing.each` ([#1499](https://github.com/jest-community/eslint-plugin-jest/issues/1499)) ([9e9cf83](https://github.com/jest-community/eslint-plugin-jest/commit/9e9cf8302ae182402da853a11b05e1560ccc63ee))

# [27.7.0](https://github.com/jest-community/eslint-plugin-jest/compare/v27.6.3...v27.7.0) (2024-02-13)


### Features

* allow `[@typescript-eslint](https://github.com/typescript-eslint)` v7 ([#1500](https://github.com/jest-community/eslint-plugin-jest/issues/1500)) ([6be2928](https://github.com/jest-community/eslint-plugin-jest/commit/6be2928816c69afca88a598e302910b113068ee9))

## [27.6.3](https://github.com/jest-community/eslint-plugin-jest/compare/v27.6.2...v27.6.3) (2024-01-12)


Expand Down
123 changes: 117 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ yarn add --dev eslint eslint-plugin-jest

## Usage

> [!NOTE]
>
> `eslint.config.js` is supported, though most of the plugin documentation still
> currently uses `.eslintrc` syntax.
>
> Refer to the
> [ESLint documentation on the new configuration file format](https://eslint.org/docs/latest/use/configure/configuration-files-new)
> for more.
Add `jest` to the plugins section of your `.eslintrc` configuration file. You
can omit the `eslint-plugin-` prefix:

Expand Down Expand Up @@ -85,7 +94,7 @@ test-related. This means it's generally not suitable to include them in your
top-level configuration as that applies to all files being linted which can
include source files.

You can use
For `.eslintrc` configs you can use
[overrides](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work)
to have ESLint apply additional rules to specific files:

Expand All @@ -106,6 +115,30 @@ to have ESLint apply additional rules to specific files:
}
```

For `eslint.config.js` you can use
[`files` and `ignores`](https://eslint.org/docs/latest/use/configure/configuration-files-new#specifying-files-and-ignores):

```js
const jest = require('eslint-plugin-jest');

module.exports = [
...require('@eslint/js').configs.recommended,
{
files: ['test/**'],
...jest.configs['flat/recommended'],
rules: {
...jest.configs['flat/recommended'].rules,
'jest/prefer-expect-assertions': 'off',
},
},
// you can also configure jest rules in other objects, so long as some of the `files` match
{
files: ['test/**'],
rules: { 'jest/prefer-expect-assertions': 'off' },
},
];
```

### Jest `version` setting

The behaviour of some rules (specifically [`no-deprecated-functions`][]) change
Expand Down Expand Up @@ -145,20 +178,41 @@ module.exports = {

## Shareable configurations

> [!NOTE]
>
> `eslint.config.js` compatible versions of configs are available prefixed with
> `flat/` and may be subject to small breaking changes while ESLint v9 is being
> finalized.
### Recommended

This plugin exports a recommended configuration that enforces good testing
practices.

To enable this configuration use the `extends` property in your `.eslintrc`
config file:
To enable this configuration with `.eslintrc`, use the `extends` property:

```json
{
"extends": ["plugin:jest/recommended"]
}
```

To enable this configuration with `eslint.config.js`, use
`jest.configs['flat/recommended']`:

```js
const jest = require('eslint-plugin-jest');

module.exports = [
{
files: [
/* glob matching your test files */
],
...jest.configs['flat/recommended'],
},
];
```

### Style

This plugin also exports a configuration named `style`, which adds some
Expand All @@ -174,9 +228,21 @@ config file:
}
```

See
[ESLint documentation](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files)
for more information about extending configuration files.
To enable this configuration with `eslint.config.js`, use
`jest.configs['flat/style']`:

```js
const jest = require('eslint-plugin-jest');

module.exports = [
{
files: [
/* glob matching your test files */
],
...jest.configs['flat/style'],
},
];
```

### All

Expand All @@ -189,10 +255,55 @@ If you want to enable all rules instead of only some you can do so by adding the
}
```

To enable this configuration with `eslint.config.js`, use
`jest.configs['flat/all']`:

```js
const jest = require('eslint-plugin-jest');

module.exports = [
{
files: [
/* glob matching your test files */
],
...jest.configs['flat/all'],
},
];
```

While the `recommended` and `style` configurations only change in major versions
the `all` configuration may change in any release and is thus unsuited for
installations requiring long-term consistency.

## Snapshot processing

> [!NOTE]
>
> This is only relevant for `eslint.config.js`
This plugin provides a
[custom processor](https://eslint.org/docs/latest/extend/custom-processors) to
allow rules to "lint" snapshot files.

For `.eslintrc` based configs, this is automatically enabled out of the box but
must be opted into for `eslint.config.js` using the `flat/snapshots` config:

```js
const jest = require('eslint-plugin-jest');

module.exports = [
{
...jest.configs['flat/snapshots'],
rules: {
'jest/no-large-snapshots': ['error', { maxSize: 1 }],
},
},
];
```

Unlike other configs, this includes a `files` array that matches `.snap` files
meaning you can use it directly

## Rules

<!-- begin auto-generated rules list -->
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-jest",
"version": "27.6.3",
"version": "27.9.0",
"description": "ESLint rules for Jest",
"keywords": [
"eslint",
Expand Down Expand Up @@ -142,7 +142,7 @@
"typescript": "^5.0.4"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0 || ^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.0.0 || ^6.0.0 || ^7.0.0",
"eslint": "^7.0.0 || ^8.0.0",
"jest": "*"
},
Expand Down

0 comments on commit cddb7f3

Please sign in to comment.