eslint-plugin-jest-formatting 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +110 -0
- package/CHANGELOG.md +33 -0
- package/README.md +44 -1
- package/docs/rules/padding-around-after-all-blocks.md +73 -11
- package/docs/rules/padding-around-after-each-blocks.md +67 -11
- package/docs/rules/padding-around-all.md +102 -9
- package/docs/rules/padding-around-before-all-blocks.md +67 -13
- package/docs/rules/padding-around-before-each-blocks.md +65 -11
- package/docs/rules/padding-around-describe-blocks.md +64 -5
- package/docs/rules/padding-around-expect-groups.md +64 -6
- package/docs/rules/padding-around-test-blocks.md +76 -13
- package/lib/ast-utils.js +15 -8
- package/lib/index.js +84 -54
- package/lib/rules/padding.js +47 -21
- package/llms.txt +29 -0
- package/package.json +28 -21
- package/.circleci/config.yml +0 -67
- package/.eslintignore +0 -3
- package/.eslintrc +0 -34
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/.github/ISSUE_TEMPLATE/rule-request.md +0 -21
- package/.prettierignore +0 -4
- package/.prettierrc +0 -4
- package/docs/rules/padding-before-after-all-blocks.md +0 -24
- package/docs/rules/padding-before-after-each-blocks.md +0 -24
- package/docs/rules/padding-before-all.md +0 -15
- package/docs/rules/padding-before-before-all-blocks.md +0 -24
- package/docs/rules/padding-before-before-each-blocks.md +0 -24
- package/docs/rules/padding-before-describe-blocks.md +0 -28
- package/docs/rules/padding-before-expect-statements.md +0 -22
- package/docs/rules/padding-before-test-blocks.md +0 -31
- package/jest.config.js +0 -4
- package/renovate.json +0 -3
- package/src/ast-utils.ts +0 -80
- package/src/index.ts +0 -182
- package/src/rules/padding.ts +0 -357
- package/tests/catfood.js +0 -41
- package/tests/dogfood.spec.js +0 -32
- package/tests/lib/ast-utils.spec.ts +0 -94
- package/tests/lib/rules/padding-around-after-all-blocks.spec.js +0 -115
- package/tests/lib/rules/padding-around-after-each-blocks.spec.js +0 -113
- package/tests/lib/rules/padding-around-before-all-blocks.spec.js +0 -115
- package/tests/lib/rules/padding-around-before-each-blocks.spec.js +0 -115
- package/tests/lib/rules/padding-around-describe-blocks.spec.js +0 -153
- package/tests/lib/rules/padding-around-expect-groups.spec.js +0 -217
- package/tests/lib/rules/padding-around-test-blocks.spec.js +0 -162
- package/tsconfig.json +0 -12
package/AGENTS.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Briefing for AI coding agents working with or on `eslint-plugin-jest-formatting`. Everything here is also in [README.md](README.md) and [docs/rules](docs/rules); this is the short version.
|
|
4
|
+
|
|
5
|
+
## What this plugin does
|
|
6
|
+
|
|
7
|
+
`eslint-plugin-jest-formatting` provides ESLint rules that require a blank line before and after Jest blocks: `describe`, `test`/`it`, `beforeAll`, `beforeEach`, `afterAll`, `afterEach`, and groups of `expect` statements. That is its whole scope. It does not check test correctness, naming, or structure; [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) does that, and the two are used together.
|
|
8
|
+
|
|
9
|
+
Facts that hold for every rule:
|
|
10
|
+
|
|
11
|
+
- No options. Configure severity only.
|
|
12
|
+
- Autofixable with `eslint --fix`. The fixer only inserts newlines; it never removes or moves code.
|
|
13
|
+
- Only neighbouring statements in the same block are compared. The first statement in a block needs no blank line before it and the last needs none after it. One blank line is enough.
|
|
14
|
+
- A statement counts as a Jest call when it starts with the identifier (`describe(...)`, `describe.each(...)`, `await expect(...)`), not when the identifier appears later (`return expect(...)`, `const p = describe(...)`).
|
|
15
|
+
- Works with ESLint 8, 9, and 10. Flat config (`eslint.config.js`) works on ESLint 8.57, 9, and 10. Legacy `.eslintrc` works on ESLint 8 and 9 only (9 needs `ESLINT_USE_FLAT_CONFIG=false`). Requires Node 22 or later. There is no Jest version requirement: nothing is imported from Jest.
|
|
16
|
+
|
|
17
|
+
## Rules
|
|
18
|
+
|
|
19
|
+
| Rule | Requires a blank line | `recommended` | `strict` |
|
|
20
|
+
| ----------------------------------- | ------------------------------------------------------------------------------ | ------------- | -------- |
|
|
21
|
+
| `padding-around-after-all-blocks` | before and after each `afterAll` call | yes | yes |
|
|
22
|
+
| `padding-around-after-each-blocks` | before and after each `afterEach` call | yes | yes |
|
|
23
|
+
| `padding-around-before-all-blocks` | before and after each `beforeAll` call | yes | yes |
|
|
24
|
+
| `padding-around-before-each-blocks` | before and after each `beforeEach` call | yes | yes |
|
|
25
|
+
| `padding-around-describe-blocks` | before and after each `describe`, `fdescribe`, or `xdescribe` block | yes | yes |
|
|
26
|
+
| `padding-around-expect-groups` | before and after each run of consecutive `expect` statements, not between them | no | yes |
|
|
27
|
+
| `padding-around-test-blocks` | before and after each `test`, `it`, `fit`, `xit`, or `xtest` block | yes | yes |
|
|
28
|
+
| `padding-around-all` | everything above, as one rule (one report per gap) | no | yes |
|
|
29
|
+
|
|
30
|
+
`recommended` enables the six rules marked yes individually. `strict` enables `padding-around-all` only, which covers the same statements plus `expect` groups. Each rule's page in `docs/rules/<rule>.md` has the same sections in the same order: Rule summary, Why, Incorrect examples, Correct examples, Options, Fixability.
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
Flat config (ESLint 9+, `eslint.config.js`):
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import jestFormatting from 'eslint-plugin-jest-formatting';
|
|
38
|
+
|
|
39
|
+
export default [
|
|
40
|
+
jestFormatting.configs['flat/recommended'], // or 'flat/strict'
|
|
41
|
+
];
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The flat configs set no `files`, so they apply wherever ESLint already lints. To limit them to test files, spread the config into an object with your own `files` (name the extensions; a bare `**/*.test.*` would also match Jest snapshot files). These patterns cover the same file names as the legacy presets:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
export default [
|
|
48
|
+
{
|
|
49
|
+
files: [
|
|
50
|
+
'**/*{.test,_test,Test,.spec,_spec,Spec}.{js,jsx,mjs,cjs,mts,cts,ts,tsx}',
|
|
51
|
+
'**/__tests__/**/*.{js,jsx,mjs,cjs,mts,cts,ts,tsx}',
|
|
52
|
+
],
|
|
53
|
+
...jestFormatting.configs['flat/recommended'],
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Legacy config (`.eslintrc`, ESLint 8 and 9 only), already scoped to common test-file globs:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"extends": ["plugin:jest-formatting/recommended"]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Use `"plugin:jest-formatting/strict"` for everything. Individual rules go in `rules` as `"jest-formatting/<rule>": "error"` in either style; flat config also needs `plugins: { 'jest-formatting': jestFormatting }`.
|
|
67
|
+
|
|
68
|
+
Fixing a tree: `npx eslint --fix .`
|
|
69
|
+
|
|
70
|
+
## Reading the output
|
|
71
|
+
|
|
72
|
+
Every report uses one of two messages. `{{token}}` is the Jest identifier that matched (`describe`, `xit`, `expect`, ...). Both are reported on the statement that should have a blank line above it.
|
|
73
|
+
|
|
74
|
+
- `missingPaddingBefore`: Missing blank line before `{{token}}`. Expected at least one blank line between the previous statement and this `{{token}}` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
75
|
+
- `missingPaddingAfter`: Missing blank line after `{{token}}`. Expected at least one blank line between the `{{token}}` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
76
|
+
|
|
77
|
+
The message contains the fix, so there is no need to open the docs to act on it, and `eslint --fix` resolves all of them. When two rules both cover a gap (for example `beforeEach` followed by `describe` under `recommended`), the same line is reported twice, once per rule; one inserted blank line satisfies both.
|
|
78
|
+
|
|
79
|
+
## Working in this repository
|
|
80
|
+
|
|
81
|
+
Layout:
|
|
82
|
+
|
|
83
|
+
- `src/index.ts`: plugin entry. The rule table (`ruleDefinitions`), the preset rule lists, and the legacy and flat config objects. Exported with `export = plugin` (CommonJS).
|
|
84
|
+
- `src/rules/padding.ts`: the single rule factory `createRule`, the shared `messages`, and the statement-matching logic. All eight rules are instances of it.
|
|
85
|
+
- `src/ast-utils.ts`: token and blank-line helpers.
|
|
86
|
+
- `tests/lib/rules/*.spec.js`: one `RuleTester` spec per rule. `tests/lib/ast-utils.spec.ts`: helper tests.
|
|
87
|
+
- `tests/dogfood.spec.js` and `tests/catfood.js`: linted by `yarn lint` through the repo's own `.eslintrc`, which extends `plugin:jest-formatting/recommended`. The spec must pass clean; `catfood.js` has bad padding on purpose and must be ignored, because it does not match the legacy config's test-file globs.
|
|
88
|
+
- `docs/rules/*.md`: one page per rule in the fixed section order above. Each rule's `meta.docs.url` points at its page on the `master` branch.
|
|
89
|
+
- `lib/`: `tsc` output, git-ignored, and the package `main`. Build before loading the plugin.
|
|
90
|
+
|
|
91
|
+
Commands (Yarn 1, `yarn.lock` is checked in; without Yarn installed, `npx -y yarn@1 <script>` works):
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
yarn install --frozen-lockfile
|
|
95
|
+
yarn test # tsc build, then jest
|
|
96
|
+
yarn lint # build, prettier --check, eslint over the repo
|
|
97
|
+
yarn format # the same, writing fixes
|
|
98
|
+
yarn build # tsc only, into lib/
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
CI (`.github/workflows/ci.yml`) runs `yarn test` on each supported Node version and `yarn lint`; a `CI passed` job gates merges to `master`.
|
|
102
|
+
|
|
103
|
+
Guardrails:
|
|
104
|
+
|
|
105
|
+
- Rule behaviour is the public contract. Do not change what is reported, where it is reported, or what the fixer writes outside a major release. Rule names, the `recommended`, `strict`, `flat/recommended`, and `flat/strict` configs, and the two message IDs are public API.
|
|
106
|
+
- Never weaken or delete a spec assertion to make a build green; fix the cause.
|
|
107
|
+
- A rule change touches all of: `ruleDefinitions` in `src/index.ts`, its spec in `tests/lib/rules`, its page in `docs/rules`, and the rule lists in `README.md`, `AGENTS.md`, and `llms.txt`.
|
|
108
|
+
- Messages are shared by all rules and live in `src/rules/padding.ts`; specs assert `messageId` and `data.token`, so update them together.
|
|
109
|
+
- Specs use `parserOptions` because the dev dependency is ESLint 8. Under an ESLint 9+ `RuleTester` they need `languageOptions` instead.
|
|
110
|
+
- Releases are manual. Do not run `npm publish` or push `v*` tags.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v4.0.0 - November 2, 2026
|
|
4
|
+
|
|
5
|
+
Lint output is read by AI coding agents as often as by people, and agents act on rule messages literally. This release makes the plugin's messages, documentation and package easier for an agent, or a person, to understand and act on. The same code is reported at the same positions and `eslint --fix` writes the same output as in 3.1.0; the message text is new. Breaking Changes below lists what else can affect an upgrade.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Flat config presets for ESLint 9 and 10: `configs['flat/recommended']` and `configs['flat/strict']`. Unlike the legacy presets they set no `files`, so your own config decides which files are linted. The legacy `plugin:jest-formatting/recommended` and `plugin:jest-formatting/strict` configs are unchanged. (#122, #120)
|
|
10
|
+
- Every report carries a `messageId`, `missingPaddingBefore` or `missingPaddingAfter`, and a message that names the matched Jest call, states the expected form, and says how to fix it. For example: Missing blank line before `describe`. Expected at least one blank line between the previous statement and this `describe` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
11
|
+
- Every rule declares `meta.type`, `meta.docs.description`, `meta.docs.url` and an empty `meta.schema`.
|
|
12
|
+
- Every rule page in `docs/rules` has the same sections: Rule summary, Why, Incorrect examples, Correct examples, Options, Fixability. The "ESLint reports" block under each incorrect example is real output, and a test keeps it that way.
|
|
13
|
+
- `AGENTS.md` and `llms.txt` for AI coding agents, and a README section on using the plugin with them.
|
|
14
|
+
- The plugin object exposes `meta.name` and `meta.version`.
|
|
15
|
+
|
|
16
|
+
### Breaking Changes
|
|
17
|
+
|
|
18
|
+
- Requires ESLint 8, 9 or 10 and Node 22 or later. ESLint 7 and earlier, and Node 20 and earlier, are no longer supported. npm warns on an `engines` mismatch; Yarn 1 refuses to install unless `--ignore-engines` is passed.
|
|
19
|
+
- The package exports one plugin object (`module.exports = plugin`) with `rules`, `configs` and `meta`, following eslint-plugin-jest. `require(...)`, `import plugin from ...` and `import { rules, configs } from ...` under TypeScript or a bundler keep working. In a native ESM file such as `eslint.config.mjs`, named imports (`import { configs } from 'eslint-plugin-jest-formatting'`) no longer resolve, and a namespace import (`import * as jestFormatting from ...`) no longer has `rules` or `configs`, so ESLint fails with `Could not find "<rule>" in plugin`. Use the default import.
|
|
20
|
+
- Rules now declare an empty `meta.schema`, so ESLint 8 rejects a rule configured with options, such as `["error", {}]`, and stops with `Configuration for rule ... is invalid`. These options never had any effect (ESLint 9 and later already rejected them); configure severity only.
|
|
21
|
+
- Rules now declare `meta.type: 'layout'`, so `eslint --fix-type layout` applies their fixes. It skipped them in 3.1.0.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- The npm package contains only the compiled code, the rule docs, `AGENTS.md`, `llms.txt` and this changelog: 17 files, down from 47. Sources, tests and CI config are no longer shipped. The `module` field, which pointed at an unshipped TypeScript file, is gone.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- Rules load on ESLint 10, where `context.getSourceCode()` was removed.
|
|
30
|
+
|
|
31
|
+
### Internal
|
|
32
|
+
|
|
33
|
+
- CI runs on GitHub Actions against Node 22, 24 and 26. The CircleCI configuration, including its tag-triggered publish job, is gone; releases are manual.
|
|
34
|
+
- New tests load the plugin through ESLint's own config loading under flat and legacy config, and check every rule's metadata and documentation page against the built plugin.
|
|
35
|
+
|
|
3
36
|
## v3.0.0 - May 4, 2021
|
|
4
37
|
|
|
5
38
|
### Breaking Changes
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://github.com/dangreenisrael/eslint-plugin-jest-formatting/actions/workflows/ci.yml)
|
|
2
2
|

|
|
3
3
|
|
|
4
4
|
# eslint-plugin-jest-formatting
|
|
@@ -13,6 +13,8 @@ Like this plugin? [Say thanks with a ⭐️](https://github.com/dangreenisrael/e
|
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
|
+
Requires Node 22 or later and ESLint 8, 9, or 10. There is no Jest version requirement: the rules match identifiers such as `describe` and `expect` and import nothing from Jest.
|
|
17
|
+
|
|
16
18
|
You'll first need to install [ESLint](http://eslint.org):
|
|
17
19
|
|
|
18
20
|
```
|
|
@@ -29,6 +31,37 @@ $ yarn add eslint-plugin-jest-formatting --dev
|
|
|
29
31
|
|
|
30
32
|
## Usage
|
|
31
33
|
|
|
34
|
+
### Flat config (ESLint 9+, `eslint.config.js`)
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import jestFormatting from 'eslint-plugin-jest-formatting';
|
|
38
|
+
|
|
39
|
+
export default [
|
|
40
|
+
// ...your other config objects
|
|
41
|
+
jestFormatting.configs['flat/recommended'],
|
|
42
|
+
];
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`flat/strict` enables every rule via `padding-around-all`. The flat configs do not set `files`, so the rules run on every file ESLint already lints. To scope them to test files, spread the config into your own object (name the extensions explicitly: in flat config a `files` glob opts matching files into linting, and a bare `**/*.test.*` would also match Jest snapshot files). These patterns cover the same file names as the legacy presets:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
export default [
|
|
49
|
+
{
|
|
50
|
+
files: [
|
|
51
|
+
'**/*{.test,_test,Test,.spec,_spec,Spec}.{js,jsx,mjs,cjs,mts,cts,ts,tsx}',
|
|
52
|
+
'**/__tests__/**/*.{js,jsx,mjs,cjs,mts,cts,ts,tsx}',
|
|
53
|
+
],
|
|
54
|
+
...jestFormatting.configs['flat/recommended'],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
With CommonJS use `const jestFormatting = require('eslint-plugin-jest-formatting');`.
|
|
60
|
+
|
|
61
|
+
### Legacy config (`.eslintrc`)
|
|
62
|
+
|
|
63
|
+
For ESLint 8 and 9 only: ESLint 10 no longer reads `.eslintrc`, and ESLint 9 needs `ESLINT_USE_FLAT_CONFIG=false` to read it.
|
|
64
|
+
|
|
32
65
|
Add `jest-formatting` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
|
|
33
66
|
|
|
34
67
|
```json
|
|
@@ -77,6 +110,16 @@ We also support a "strict" settings which enabled all of the rules for you
|
|
|
77
110
|
- [padding-around-test-blocks](docs/rules/padding-around-test-blocks.md)
|
|
78
111
|
- [padding-around-all](docs/rules/padding-around-all.md)
|
|
79
112
|
|
|
113
|
+
## Using with AI coding agents
|
|
114
|
+
|
|
115
|
+
This plugin is built to be driven by coding agents as well as people:
|
|
116
|
+
|
|
117
|
+
- **Self-describing messages.** Every report says what is missing, where, and how to fix it, for example: `` Missing blank line before `describe`. Expected at least one blank line between the previous statement and this `describe` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). `` An agent can act on the message without opening the docs.
|
|
118
|
+
- **Everything is autofixable.** `eslint --fix` resolves every report from this plugin by inserting blank lines. The fixer never removes or reorders code.
|
|
119
|
+
- **Fixed documentation shape.** Each page in [docs/rules](docs/rules) has the same sections in the same order: Rule summary, Why, Incorrect examples, Correct examples, Options, Fixability. Each rule's `meta.docs.url` points at its page.
|
|
120
|
+
- **[AGENTS.md](AGENTS.md)** is a one-page briefing: what the plugin does, every rule in one line, flat and legacy config snippets, and how to build and test.
|
|
121
|
+
- **[llms.txt](llms.txt)** lists the documentation in the [llms.txt](https://llmstxt.org) format for tools that fetch context automatically.
|
|
122
|
+
|
|
80
123
|
## Related Projects
|
|
81
124
|
|
|
82
125
|
### eslint-plugin-jest
|
|
@@ -1,25 +1,87 @@
|
|
|
1
1
|
# padding-around-after-all-blocks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
- **Rule ID:** `jest-formatting/padding-around-after-all-blocks`
|
|
4
|
+
- **Presets:** `recommended`; covered by `padding-around-all` in `strict`
|
|
5
|
+
- **Fixable:** yes, `eslint --fix` inserts the missing blank lines
|
|
6
|
+
- **Options:** none
|
|
7
|
+
- **Message IDs:** `missingPaddingBefore`, `missingPaddingAfter`
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
## Rule summary
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
Require a blank line before and after every `afterAll` call.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
- Matches every statement that starts with the identifier `afterAll`.
|
|
14
|
+
- Only neighbouring statements in the same block are compared: the top level of the file, a `{ ... }` block such as a callback body, or a `switch` case. The first statement in a block needs no blank line before it, and the last needs none after it.
|
|
15
|
+
- One blank line is enough; extra blank lines are never reported.
|
|
16
|
+
- Two consecutive `afterAll` calls also need a blank line between them.
|
|
17
|
+
- A comment on its own line is not a blank line, but a blank line on either side of a comment satisfies the rule.
|
|
18
|
+
|
|
19
|
+
## Why
|
|
20
|
+
|
|
21
|
+
`afterAll` runs once, after every test in its scope, so it is part of the suite's skeleton rather than of any one test. A blank line on each side keeps that teardown visually separate from the declarations and tests around it, which makes the setup and teardown structure of a file readable at a glance and keeps cleanup code from being mistaken for part of a neighbouring block.
|
|
22
|
+
|
|
23
|
+
## Incorrect examples
|
|
10
24
|
|
|
11
25
|
```js
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
/* eslint jest-formatting/padding-around-after-all-blocks: "error" */
|
|
27
|
+
const server = startServer();
|
|
28
|
+
afterAll(() => {
|
|
29
|
+
server.close();
|
|
30
|
+
});
|
|
31
|
+
describe('GET /health', () => {
|
|
32
|
+
test('responds with 200', async () => {
|
|
33
|
+
expect(await server.get('/health')).toBe(200);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
ESLint reports:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
3:1 error Missing blank line before `afterAll`. Expected at least one blank line between the previous statement and this `afterAll` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-after-all-blocks
|
|
42
|
+
6:1 error Missing blank line after `afterAll`. Expected at least one blank line between the `afterAll` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-after-all-blocks
|
|
15
43
|
```
|
|
16
44
|
|
|
17
|
-
|
|
45
|
+
## Correct examples
|
|
18
46
|
|
|
19
47
|
```js
|
|
20
|
-
|
|
48
|
+
/* eslint jest-formatting/padding-around-after-all-blocks: "error" */
|
|
49
|
+
const server = startServer();
|
|
50
|
+
|
|
51
|
+
afterAll(() => {
|
|
52
|
+
server.close();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('GET /health', () => {
|
|
56
|
+
test('responds with 200', async () => {
|
|
57
|
+
expect(await server.get('/health')).toBe(200);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Options
|
|
21
63
|
|
|
22
|
-
|
|
64
|
+
This rule has no options; configure only the severity. Passing options makes ESLint reject the configuration, because the rule's schema is empty.
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
// eslint.config.js (flat); the same `rules` entry works in a legacy .eslintrc
|
|
68
|
+
import jestFormatting from 'eslint-plugin-jest-formatting';
|
|
23
69
|
|
|
24
|
-
|
|
70
|
+
export default [
|
|
71
|
+
{
|
|
72
|
+
plugins: { 'jest-formatting': jestFormatting },
|
|
73
|
+
rules: {
|
|
74
|
+
'jest-formatting/padding-around-after-all-blocks': 'error',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
25
78
|
```
|
|
79
|
+
|
|
80
|
+
## Fixability
|
|
81
|
+
|
|
82
|
+
Fixable (`meta.fixable` is `"whitespace"`). `eslint --fix` resolves every report from this rule by inserting a newline after the last token of the statement before the gap, after any comment that trails on the same line, so that a blank line separates the two statements. The fix only adds whitespace; it never removes, moves, or reformats code.
|
|
83
|
+
|
|
84
|
+
Both messages are reported on the statement that should have a blank line above it. `{{token}}` is the identifier that matched, for example `afterAll`.
|
|
85
|
+
|
|
86
|
+
- `missingPaddingBefore`, reported on the `afterAll` call: Missing blank line before `{{token}}`. Expected at least one blank line between the previous statement and this `{{token}}` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
87
|
+
- `missingPaddingAfter`, reported on the statement after the `afterAll` call: Missing blank line after `{{token}}`. Expected at least one blank line between the `{{token}}` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
@@ -1,29 +1,85 @@
|
|
|
1
1
|
# padding-around-after-each-blocks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
- **Rule ID:** `jest-formatting/padding-around-after-each-blocks`
|
|
4
|
+
- **Presets:** `recommended`; covered by `padding-around-all` in `strict`
|
|
5
|
+
- **Fixable:** yes, `eslint --fix` inserts the missing blank lines
|
|
6
|
+
- **Options:** none
|
|
7
|
+
- **Message IDs:** `missingPaddingBefore`, `missingPaddingAfter`
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
## Rule summary
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
Require a blank line before and after every `afterEach` call.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
- Matches every statement that starts with the identifier `afterEach`.
|
|
14
|
+
- Only neighbouring statements in the same block are compared: the top level of the file, a `{ ... }` block such as a callback body, or a `switch` case. The first statement in a block needs no blank line before it, and the last needs none after it.
|
|
15
|
+
- One blank line is enough; extra blank lines are never reported.
|
|
16
|
+
- Two consecutive `afterEach` calls also need a blank line between them.
|
|
17
|
+
- A comment on its own line is not a blank line, but a blank line on either side of a comment satisfies the rule.
|
|
18
|
+
|
|
19
|
+
## Why
|
|
20
|
+
|
|
21
|
+
`afterEach` runs after every test in its scope. Padding it on both sides makes the per-test cleanup stand out from the tests it applies to and from suite-level code, so a reader scanning the file can see what resets between tests without reading each block's body.
|
|
22
|
+
|
|
23
|
+
## Incorrect examples
|
|
10
24
|
|
|
11
25
|
```js
|
|
12
|
-
|
|
26
|
+
/* eslint jest-formatting/padding-around-after-each-blocks: "error" */
|
|
27
|
+
const spy = jest.spyOn(console, 'warn');
|
|
13
28
|
afterEach(() => {
|
|
14
|
-
|
|
29
|
+
spy.mockClear();
|
|
30
|
+
});
|
|
31
|
+
test('warns once', () => {
|
|
32
|
+
warnOnce('x');
|
|
33
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
15
34
|
});
|
|
16
|
-
describe('foo', () => {});
|
|
17
35
|
```
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
ESLint reports:
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
3:1 error Missing blank line before `afterEach`. Expected at least one blank line between the previous statement and this `afterEach` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-after-each-blocks
|
|
41
|
+
6:1 error Missing blank line after `afterEach`. Expected at least one blank line between the `afterEach` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-after-each-blocks
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Correct examples
|
|
20
45
|
|
|
21
46
|
```js
|
|
22
|
-
|
|
47
|
+
/* eslint jest-formatting/padding-around-after-each-blocks: "error" */
|
|
48
|
+
const spy = jest.spyOn(console, 'warn');
|
|
23
49
|
|
|
24
50
|
afterEach(() => {
|
|
25
|
-
|
|
51
|
+
spy.mockClear();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('warns once', () => {
|
|
55
|
+
warnOnce('x');
|
|
56
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
26
57
|
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Options
|
|
61
|
+
|
|
62
|
+
This rule has no options; configure only the severity. Passing options makes ESLint reject the configuration, because the rule's schema is empty.
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
// eslint.config.js (flat); the same `rules` entry works in a legacy .eslintrc
|
|
66
|
+
import jestFormatting from 'eslint-plugin-jest-formatting';
|
|
27
67
|
|
|
28
|
-
|
|
68
|
+
export default [
|
|
69
|
+
{
|
|
70
|
+
plugins: { 'jest-formatting': jestFormatting },
|
|
71
|
+
rules: {
|
|
72
|
+
'jest-formatting/padding-around-after-each-blocks': 'error',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
];
|
|
29
76
|
```
|
|
77
|
+
|
|
78
|
+
## Fixability
|
|
79
|
+
|
|
80
|
+
Fixable (`meta.fixable` is `"whitespace"`). `eslint --fix` resolves every report from this rule by inserting a newline after the last token of the statement before the gap, after any comment that trails on the same line, so that a blank line separates the two statements. The fix only adds whitespace; it never removes, moves, or reformats code.
|
|
81
|
+
|
|
82
|
+
Both messages are reported on the statement that should have a blank line above it. `{{token}}` is the identifier that matched, for example `afterEach`.
|
|
83
|
+
|
|
84
|
+
- `missingPaddingBefore`, reported on the `afterEach` call: Missing blank line before `{{token}}`. Expected at least one blank line between the previous statement and this `{{token}}` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
85
|
+
- `missingPaddingAfter`, reported on the statement after the `afterEach` call: Missing blank line after `{{token}}`. Expected at least one blank line between the `{{token}}` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
@@ -1,13 +1,106 @@
|
|
|
1
1
|
# padding-around-all
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
- **Rule ID:** `jest-formatting/padding-around-all`
|
|
4
|
+
- **Presets:** `strict`
|
|
5
|
+
- **Fixable:** yes, `eslint --fix` inserts the missing blank lines
|
|
6
|
+
- **Options:** none
|
|
7
|
+
- **Message IDs:** `missingPaddingBefore`, `missingPaddingAfter`
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
## Rule summary
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [padding-around-before-all-blocks](padding-around-before-all-blocks.md)
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
11
|
+
Require a blank line before and after every Jest hook, `describe` block, `test` or `it` block, and group of `expect` statements, as a single rule that combines the seven `padding-around-*` rules.
|
|
12
|
+
|
|
13
|
+
- Covers exactly the statements matched by [padding-around-after-all-blocks](padding-around-after-all-blocks.md), [padding-around-after-each-blocks](padding-around-after-each-blocks.md), [padding-around-before-all-blocks](padding-around-before-all-blocks.md), [padding-around-before-each-blocks](padding-around-before-each-blocks.md), [padding-around-describe-blocks](padding-around-describe-blocks.md), [padding-around-expect-groups](padding-around-expect-groups.md), and [padding-around-test-blocks](padding-around-test-blocks.md).
|
|
14
|
+
- It is one rule, not an alias for seven: a gap is reported once even where two of the individual rules would both report it, and an `eslint-disable` comment must name `padding-around-all`.
|
|
15
|
+
- Only neighbouring statements in the same block are compared: the top level of the file, a `{ ... }` block such as a callback body, or a `switch` case. The first statement in a block needs no blank line before it, and the last needs none after it.
|
|
16
|
+
- One blank line is enough; extra blank lines are never reported.
|
|
17
|
+
- Consecutive `expect` statements need no blank line between them; every other pair of consecutive Jest calls does.
|
|
18
|
+
- A comment on its own line is not a blank line, but a blank line on either side of a comment satisfies the rule.
|
|
19
|
+
|
|
20
|
+
## Why
|
|
21
|
+
|
|
22
|
+
Using one rule for all Jest blocks gives a file a single consistent rhythm: every hook, suite, test, and assertion group is set off by blank lines. It is the rule behind the `strict` configs. Because it is a single rule, a gap between two different kinds of block (for example `beforeEach` followed by `describe`) is reported once, whereas enabling the seven individual rules reports that gap twice. To pad only some kinds of block, enable the individual rules instead of this one.
|
|
23
|
+
|
|
24
|
+
## Incorrect examples
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
/* eslint jest-formatting/padding-around-all: "error" */
|
|
28
|
+
const db = connect();
|
|
29
|
+
beforeAll(() => db.migrate());
|
|
30
|
+
afterAll(() => db.close());
|
|
31
|
+
describe('users', () => {
|
|
32
|
+
beforeEach(() => db.reset());
|
|
33
|
+
test('creates a user', async () => {
|
|
34
|
+
const user = await db.users.create({ name: 'Ada' });
|
|
35
|
+
expect(user.id).toBeDefined();
|
|
36
|
+
expect(user.name).toBe('Ada');
|
|
37
|
+
});
|
|
38
|
+
test('rejects an empty name', async () => {
|
|
39
|
+
await expect(db.users.create({ name: '' })).rejects.toThrow();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
ESLint reports:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
3:1 error Missing blank line before `beforeAll`. Expected at least one blank line between the previous statement and this `beforeAll` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-all
|
|
48
|
+
4:1 error Missing blank line after `beforeAll`. Expected at least one blank line between the `beforeAll` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-all
|
|
49
|
+
5:1 error Missing blank line before `describe`. Expected at least one blank line between the previous statement and this `describe` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-all
|
|
50
|
+
7:3 error Missing blank line before `test`. Expected at least one blank line between the previous statement and this `test` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-all
|
|
51
|
+
9:5 error Missing blank line before `expect`. Expected at least one blank line between the previous statement and this `expect` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-all
|
|
52
|
+
12:3 error Missing blank line after `test`. Expected at least one blank line between the `test` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-all
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Correct examples
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
/* eslint jest-formatting/padding-around-all: "error" */
|
|
59
|
+
const db = connect();
|
|
60
|
+
|
|
61
|
+
beforeAll(() => db.migrate());
|
|
62
|
+
|
|
63
|
+
afterAll(() => db.close());
|
|
64
|
+
|
|
65
|
+
describe('users', () => {
|
|
66
|
+
beforeEach(() => db.reset());
|
|
67
|
+
|
|
68
|
+
test('creates a user', async () => {
|
|
69
|
+
const user = await db.users.create({ name: 'Ada' });
|
|
70
|
+
|
|
71
|
+
expect(user.id).toBeDefined();
|
|
72
|
+
expect(user.name).toBe('Ada');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('rejects an empty name', async () => {
|
|
76
|
+
await expect(db.users.create({ name: '' })).rejects.toThrow();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Options
|
|
82
|
+
|
|
83
|
+
This rule has no options; configure only the severity. Passing options makes ESLint reject the configuration, because the rule's schema is empty.
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
// eslint.config.js (flat); the same `rules` entry works in a legacy .eslintrc
|
|
87
|
+
import jestFormatting from 'eslint-plugin-jest-formatting';
|
|
88
|
+
|
|
89
|
+
export default [
|
|
90
|
+
{
|
|
91
|
+
plugins: { 'jest-formatting': jestFormatting },
|
|
92
|
+
rules: {
|
|
93
|
+
'jest-formatting/padding-around-all': 'error',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Fixability
|
|
100
|
+
|
|
101
|
+
Fixable (`meta.fixable` is `"whitespace"`). `eslint --fix` resolves every report from this rule by inserting a newline after the last token of the statement before the gap, after any comment that trails on the same line, so that a blank line separates the two statements. The fix only adds whitespace; it never removes, moves, or reformats code.
|
|
102
|
+
|
|
103
|
+
Both messages are reported on the statement that should have a blank line above it. `{{token}}` is the identifier that matched, for example `beforeEach`.
|
|
104
|
+
|
|
105
|
+
- `missingPaddingBefore`, reported on the Jest call: Missing blank line before `{{token}}`. Expected at least one blank line between the previous statement and this `{{token}}` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
106
|
+
- `missingPaddingAfter`, reported on the statement after the Jest call: Missing blank line after `{{token}}`. Expected at least one blank line between the `{{token}}` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
@@ -1,29 +1,83 @@
|
|
|
1
1
|
# padding-around-before-all-blocks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
- **Rule ID:** `jest-formatting/padding-around-before-all-blocks`
|
|
4
|
+
- **Presets:** `recommended`; covered by `padding-around-all` in `strict`
|
|
5
|
+
- **Fixable:** yes, `eslint --fix` inserts the missing blank lines
|
|
6
|
+
- **Options:** none
|
|
7
|
+
- **Message IDs:** `missingPaddingBefore`, `missingPaddingAfter`
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
## Rule summary
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
Require a blank line before and after every `beforeAll` call.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
- Matches every statement that starts with the identifier `beforeAll`.
|
|
14
|
+
- Only neighbouring statements in the same block are compared: the top level of the file, a `{ ... }` block such as a callback body, or a `switch` case. The first statement in a block needs no blank line before it, and the last needs none after it.
|
|
15
|
+
- One blank line is enough; extra blank lines are never reported.
|
|
16
|
+
- Two consecutive `beforeAll` calls also need a blank line between them.
|
|
17
|
+
- A comment on its own line is not a blank line, but a blank line on either side of a comment satisfies the rule.
|
|
18
|
+
|
|
19
|
+
## Why
|
|
20
|
+
|
|
21
|
+
`beforeAll` is one-time setup shared by every test in its scope. Separating it with blank lines makes the shared setup easy to spot and keeps it from reading as the first step of whichever test happens to follow it.
|
|
22
|
+
|
|
23
|
+
## Incorrect examples
|
|
10
24
|
|
|
11
25
|
```js
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
/* eslint jest-formatting/padding-around-before-all-blocks: "error" */
|
|
27
|
+
let db;
|
|
28
|
+
beforeAll(async () => {
|
|
29
|
+
db = await connect();
|
|
30
|
+
});
|
|
31
|
+
test('reads a row', async () => {
|
|
32
|
+
expect(await db.get(1)).toBeDefined();
|
|
15
33
|
});
|
|
16
|
-
describe('foo', () => {});
|
|
17
34
|
```
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
ESLint reports:
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
3:1 error Missing blank line before `beforeAll`. Expected at least one blank line between the previous statement and this `beforeAll` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-before-all-blocks
|
|
40
|
+
6:1 error Missing blank line after `beforeAll`. Expected at least one blank line between the `beforeAll` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix). jest-formatting/padding-around-before-all-blocks
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Correct examples
|
|
20
44
|
|
|
21
45
|
```js
|
|
22
|
-
|
|
46
|
+
/* eslint jest-formatting/padding-around-before-all-blocks: "error" */
|
|
47
|
+
let db;
|
|
48
|
+
|
|
49
|
+
beforeAll(async () => {
|
|
50
|
+
db = await connect();
|
|
51
|
+
});
|
|
23
52
|
|
|
24
|
-
|
|
25
|
-
|
|
53
|
+
test('reads a row', async () => {
|
|
54
|
+
expect(await db.get(1)).toBeDefined();
|
|
26
55
|
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
This rule has no options; configure only the severity. Passing options makes ESLint reject the configuration, because the rule's schema is empty.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
// eslint.config.js (flat); the same `rules` entry works in a legacy .eslintrc
|
|
64
|
+
import jestFormatting from 'eslint-plugin-jest-formatting';
|
|
27
65
|
|
|
28
|
-
|
|
66
|
+
export default [
|
|
67
|
+
{
|
|
68
|
+
plugins: { 'jest-formatting': jestFormatting },
|
|
69
|
+
rules: {
|
|
70
|
+
'jest-formatting/padding-around-before-all-blocks': 'error',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
29
74
|
```
|
|
75
|
+
|
|
76
|
+
## Fixability
|
|
77
|
+
|
|
78
|
+
Fixable (`meta.fixable` is `"whitespace"`). `eslint --fix` resolves every report from this rule by inserting a newline after the last token of the statement before the gap, after any comment that trails on the same line, so that a blank line separates the two statements. The fix only adds whitespace; it never removes, moves, or reformats code.
|
|
79
|
+
|
|
80
|
+
Both messages are reported on the statement that should have a blank line above it. `{{token}}` is the identifier that matched, for example `beforeAll`.
|
|
81
|
+
|
|
82
|
+
- `missingPaddingBefore`, reported on the `beforeAll` call: Missing blank line before `{{token}}`. Expected at least one blank line between the previous statement and this `{{token}}` call. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|
|
83
|
+
- `missingPaddingAfter`, reported on the statement after the `beforeAll` call: Missing blank line after `{{token}}`. Expected at least one blank line between the `{{token}}` call above and this statement. Fix: insert an empty line between the statements, before any comments leading the next statement (autofixable with --fix).
|