Skip to content

Commit 2580563

Browse files
bmishG-Rath
andauthored
fix: consistent rule doc notices and sections (#1226)
Co-authored-by: Gareth Jones <[email protected]>
1 parent 90cdc0c commit 2580563

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+659
-41
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ installations requiring long-term consistency.
215215
| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended][] | ![suggest][] |
216216
| [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | |
217217
| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | |
218+
| [no-if](docs/rules/no-if.md) | Disallow conditional logic | ![deprecated][] | |
218219
| [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ![recommended][] | |
219220
| [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ![recommended][] | ![fixable][] |
220221
| [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | |
@@ -308,4 +309,5 @@ https://github.com/istanbuljs/eslint-plugin-istanbul
308309
[suggest]: https://img.shields.io/badge/-suggest-yellow.svg
309310
[fixable]: https://img.shields.io/badge/-fixable-green.svg
310311
[style]: https://img.shields.io/badge/-style-blue.svg
312+
[deprecated]: https://img.shields.io/badge/-deprecated-red.svg
311313
[`no-deprecated-functions`]: docs/rules/no-deprecated-functions.md

docs/rules/consistent-test-it.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
# Have control over `test` and `it` usages (`consistent-test-it`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
🔧 This rule is automatically fixable using the `--fix`
8+
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
9+
on the command line.
10+
11+
<!-- end rule header -->
12+
313
Jest allows you to choose how you want to define your tests, using the `it` or
414
the `test` keywords, with multiple permutations for each:
515

616
- **it:** `it`, `xit`, `fit`, `it.only`, `it.skip`.
717
- **test:** `test`, `xtest`, `test.only`, `test.skip`.
818

19+
## Rule details
20+
921
This rule gives you control over the usage of these keywords in your codebase.
1022

11-
## Rule Details
23+
## Options
1224

1325
This rule can be configured as follows
1426

docs/rules/expect-expect.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Enforce assertion to be made in a test body (`expect-expect`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
Ensure that there is at least one `expect` call made in a test.
410

511
## Rule details

docs/rules/max-expects.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Enforces a maximum number assertion calls in a test body (`max-expects`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
As more assertions are made, there is a possible tendency for the test to be
410
more likely to mix multiple objectives. To avoid this, this rule reports when
511
the maximum number of assertions is exceeded.
612

7-
## Rule Details
13+
## Rule details
814

915
This rule enforces a maximum number of `expect()` calls.
1016

docs/rules/max-nested-describe.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Enforces a maximum depth to nested describe calls (`max-nested-describe`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
While it's useful to be able to group your tests together within the same file
410
using `describe()`, having too many levels of nesting throughout your tests make
511
them difficult to read.
612

7-
## Rule Details
13+
## Rule details
814

915
This rule enforces a maximum depth to nested `describe()` calls to improve code
1016
clarity in your tests.

docs/rules/no-alias-methods.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Disallow alias methods (`no-alias-methods`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
🔧 This rule is automatically fixable using the `--fix`
8+
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
9+
on the command line.
10+
11+
<!-- end rule header -->
12+
313
> These aliases are going to be removed in the next major version of Jest - see
414
> https://github.com/facebook/jest/issues/13164 for more
515

docs/rules/no-commented-out-tests.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Disallow commented out tests (`no-commented-out-tests`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
This rule raises a warning about commented out tests. It's similar to
410
no-disabled-tests rule.
511

6-
## Rule Details
12+
## Rule details
713

814
The rule uses fuzzy matching to do its best to determine what constitutes a
915
commented out test, checking for a presence of `it(`, `describe(`, `it.skip(`,

docs/rules/no-conditional-expect.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Prevent calling `expect` conditionally (`no-conditional-expect`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
<!-- end rule header -->
8+
39
This rule prevents the use of `expect` in conditional blocks, such as `if`s &
410
`catch`s.
511

612
This includes using `expect` in callbacks to functions named `catch`, which are
713
assumed to be promises.
814

9-
## Rule Details
15+
## Rule details
1016

1117
Jest only considers a test to have failed if it throws an error, meaning if
1218
calls to assertion functions like `expect` occur in conditional code such as a

docs/rules/no-conditional-in-test.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Disallow conditional logic in tests (`no-conditional-in-test`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
Conditional logic in tests is usually an indication that a test is attempting to
410
cover too much, and not testing the logic it intends to. Each branch of code
511
executing within a conditional statement will usually be better served by a test
612
devoted to it.
713

8-
## Rule Details
14+
## Rule details
915

1016
This rule reports on any use of a conditional statement such as `if`, `switch`,
1117
and ternary expressions.

docs/rules/no-deprecated-functions.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Disallow use of deprecated functions (`no-deprecated-functions`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
🔧 This rule is automatically fixable using the `--fix`
8+
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
9+
on the command line.
10+
11+
<!-- end rule header -->
12+
313
Over the years Jest has accrued some debt in the form of functions that have
414
either been renamed for clarity, or replaced with more powerful APIs.
515

docs/rules/no-disabled-tests.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Disallow disabled tests (`no-disabled-tests`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
Jest has a feature that allows you to temporarily mark tests as disabled. This
410
feature is often helpful while debugging or to create placeholders for future
511
tests. Before committing changes we may want to check that all tests are
612
running.
713

814
This rule raises a warning about disabled tests.
915

10-
## Rule Details
16+
## Rule details
1117

1218
There are a number of ways to disable tests in Jest:
1319

docs/rules/no-done-callback.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Avoid using a callback in asynchronous tests and hooks (`no-done-callback`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
💡 This rule provides
8+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
9+
that can be applied manually.
10+
11+
<!-- end rule header -->
12+
313
When calling asynchronous code in hooks and tests, `jest` needs to know when the
414
asynchronous work is complete to progress the current run.
515

docs/rules/no-duplicate-hooks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Disallow duplicate setup and teardown hooks (`no-duplicate-hooks`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
A `describe` block should not contain duplicate hooks.
410

5-
## Rule Details
11+
## Rule details
612

713
Examples of **incorrect** code for this rule
814

docs/rules/no-export.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Disallow using `exports` in files containing tests (`no-export`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
<!-- end rule header -->
8+
39
Prevents using `exports` if a file has one or more tests in it.
410

5-
## Rule Details
11+
## Rule details
612

713
This rule aims to eliminate duplicate runs of tests by exporting things from
814
test files. If you import from a test file, then all the tests in that file will

docs/rules/no-focused-tests.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Disallow focused tests (`no-focused-tests`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
💡 This rule provides
8+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
9+
that can be applied manually.
10+
11+
<!-- end rule header -->
12+
13+
<!-- prettier-ignore -->
314
Jest has a feature that allows you to focus tests by appending `.only` or
415
prepending `f` to a test-suite or a test-case. This feature is really helpful to
516
debug a failing test, so you don’t have to execute all of your tests. After you
@@ -9,7 +20,7 @@ have fixed your test and before committing the changes you have to remove
920
This rule reminds you to remove `.only` from your tests by raising a warning
1021
whenever you are using the exclusivity feature.
1122

12-
## Rule Details
23+
## Rule details
1324

1425
This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`,
1526
and `fit` occurrences within the source code. Of course there are some

docs/rules/no-hooks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Disallow setup and teardown hooks (`no-hooks`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
Jest provides global functions for setup and teardown tasks, which are called
410
before/after each test case and each test suite. The use of these hooks promotes
511
shared state between tests.
612

7-
## Rule Details
13+
## Rule details
814

915
This rule reports for the following function calls:
1016

docs/rules/no-identical-title.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Disallow identical titles (`no-identical-title`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
<!-- end rule header -->
8+
39
Having identical titles for two different tests or test suites may create
410
confusion. For example, when a test with the same title as another test in the
511
same test suite fails, it is harder to know which one failed and thus harder to
612
fix.
713

8-
## Rule Details
14+
## Rule details
915

1016
This rule looks at the title of every test and test suite. It will report when
1117
two test suites or two test cases at the same level of a test suite have the

docs/rules/no-if.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Disallow conditional logic (`no-if`)
22

3-
## Deprecated
3+
❌ This rule is deprecated. It was replaced by
4+
[no-conditional-in-test](no-conditional-in-test.md).
45

5-
This rule has been deprecated in favor of
6-
[`no-conditional-in-test`](no-conditional-in-test.md).
6+
<!-- end rule header -->
77

88
Conditional logic in tests is usually an indication that a test is attempting to
99
cover too much, and not testing the logic it intends to. Each branch of code
@@ -13,7 +13,7 @@ to it.
1313
Conditionals are often used to satisfy the typescript type checker. In these
1414
cases, using the non-null assertion operator (!) would be best.
1515

16-
## Rule Details
16+
## Rule details
1717

1818
This rule prevents the use of if/ else statements and conditional (ternary)
1919
operations in tests.

docs/rules/no-interpolation-in-snapshots.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
<!-- end rule header -->
8+
39
Prevents the use of string interpolations in snapshots.
410

5-
## Rule Details
11+
## Rule details
612

713
Interpolation prevents snapshots from being updated. Instead, properties should
814
be overloaded with a matcher by using

docs/rules/no-jasmine-globals.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
# Disallow Jasmine globals (`no-jasmine-globals`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`, `recommended`.
6+
7+
🔧 This rule is automatically fixable using the `--fix`
8+
[option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix)
9+
on the command line.
10+
11+
<!-- end rule header -->
12+
313
`jest` uses `jasmine` as a test runner. A side effect of this is that both a
414
`jasmine` object, and some jasmine-specific globals, are exposed to the test
515
environment. Most functionality offered by Jasmine has been ported to Jest, and
616
the Jasmine globals will stop working in the future. Developers should therefore
717
migrate to Jest's documented API instead of relying on the undocumented Jasmine
818
API.
919

10-
### Rule details
20+
## Rule details
1121

1222
This rule reports on any usage of Jasmine globals, which is not ported to Jest,
1323
and suggests alternatives from Jest's own API.

docs/rules/no-large-snapshots.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# disallow large snapshots (`no-large-snapshots`)
22

3+
💼 This rule is enabled in the following
4+
[configs](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations):
5+
`all`.
6+
7+
<!-- end rule header -->
8+
39
When using Jest's snapshot capability one should be mindful of the size of
410
created snapshots. As a general best practice snapshots should be limited in
511
size in order to be more manageable and reviewable. A stored snapshot is only as
@@ -22,7 +28,7 @@ module.exports = {
2228
};
2329
```
2430

25-
## Rule Details
31+
## Rule details
2632

2733
This rule looks at all Jest inline and external snapshots (files with `.snap`
2834
extension) and validates that each stored snapshot within those files does not

0 commit comments

Comments
 (0)