Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consistent rule doc notices and sections #1226

Merged
merged 26 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a16aa6a
docs: consistent rule doc notices and sections
bmish Aug 28, 2022
6727301
docs: switch to automatic rule notice generation
bmish Sep 2, 2022
df8ed6e
docs: switch to Rule details
bmish Sep 3, 2022
707afdc
docs: reword suggestions
bmish Sep 3, 2022
e2ef23c
docs: change rule notice marker
bmish Sep 3, 2022
302cc3b
test: not.toContain
bmish Sep 3, 2022
50765e6
docs: ending marker only, no prettier disable, refactor rule doc head…
bmish Sep 5, 2022
9285ee8
Merge branch 'main' into docs-consistent-notices-sections
bmish Sep 5, 2022
c8a8c63
docs: add more comments
bmish Sep 5, 2022
c328298
chore: test coverage ignore tools
bmish Sep 5, 2022
cbaa909
docs: remove generated by comment
bmish Sep 5, 2022
1529b66
refactor: address feedback
bmish Sep 5, 2022
15f7add
chore: remove tsconfig.json include for tools
bmish Sep 5, 2022
c87c2db
refactor: remove RuleName type
bmish Sep 5, 2022
d966ec1
refactor: getNoticesForRule should return object
bmish Sep 6, 2022
dd5a274
test: switch rule doc test to generator failure
bmish Sep 6, 2022
86ca6b3
docs: fix comment
bmish Sep 6, 2022
a1b3f10
docs: deprecated rule notice show replaced by rules
bmish Sep 6, 2022
c346d05
chore: remove coveragePathIgnorePatterns
bmish Sep 7, 2022
9c901b2
docs: config link README
bmish Sep 7, 2022
e1105cc
test: ensure rule docs mention named options
bmish Sep 7, 2022
34e692a
Update tools/regenerate-docs.ts
SimenB Sep 9, 2022
8f6a402
Merge branch 'main' into docs-consistent-notices-sections
SimenB Sep 9, 2022
de63782
Apply suggestions from code review
SimenB Sep 10, 2022
e96211a
chore(release): 27.0.3 [skip ci]
semantic-release-bot Sep 9, 2022
b2cf0bc
Merge branch 'main' into docs-consistent-notices-sections
SimenB Sep 10, 2022
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ installations requiring long-term consistency.
| [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended][] | ![suggest][] |
| [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | |
| [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | |
| [no-if](docs/rules/no-if.md) | Disallow conditional logic | ![deprecated][] | |
bmish marked this conversation as resolved.
Show resolved Hide resolved
SimenB marked this conversation as resolved.
Show resolved Hide resolved
| [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ![recommended][] | |
| [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ![recommended][] | ![fixable][] |
| [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | |
Expand Down Expand Up @@ -308,4 +309,5 @@ https://github.com/istanbuljs/eslint-plugin-istanbul
[suggest]: https://img.shields.io/badge/-suggest-yellow.svg
[fixable]: https://img.shields.io/badge/-fixable-green.svg
[style]: https://img.shields.io/badge/-style-blue.svg
[deprecated]: https://img.shields.io/badge/-deprecated-red.svg
[`no-deprecated-functions`]: docs/rules/no-deprecated-functions.md
14 changes: 13 additions & 1 deletion docs/rules/consistent-test-it.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# Have control over `test` and `it` usages (`consistent-test-it`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
bmish marked this conversation as resolved.
Show resolved Hide resolved
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

<!-- /RULE_NOTICE -->
bmish marked this conversation as resolved.
Show resolved Hide resolved

Jest allows you to choose how you want to define your tests, using the `it` or
the `test` keywords, with multiple permutations for each:

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

## Rule Details

This rule gives you control over the usage of these keywords in your codebase.

## Rule Details
## Options

This rule can be configured as follows

Expand Down
9 changes: 8 additions & 1 deletion docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Enforce assertion to be made in a test body (`expect-expect`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

Ensure that there is at least one `expect` call made in a test.

## Rule details
## Rule Details
bmish marked this conversation as resolved.
Show resolved Hide resolved

This rule triggers when there is no call made to `expect` in a test, to prevent
users from forgetting to add assertions.
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/max-expects.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Enforces a maximum number assertion calls in a test body (`max-expects`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

As more assertions are made, there is a possible tendency for the test to be
more likely to mix multiple objectives. To avoid this, this rule reports when
the maximum number of assertions is exceeded.
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/max-nested-describe.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Enforces a maximum depth to nested describe calls (`max-nested-describe`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

While it's useful to be able to group your tests together within the same file
using `describe()`, having too many levels of nesting throughout your tests make
them difficult to read.
Expand Down
12 changes: 11 additions & 1 deletion docs/rules/no-alias-methods.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Disallow alias methods (`no-alias-methods`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

<!-- /RULE_NOTICE -->

> These aliases are going to be removed in the next major version of Jest - see
> https://github.com/facebook/jest/issues/13164 for more

Expand All @@ -9,7 +19,7 @@ Jest documentation is used in the code. This makes it easier to search for all
occurrences of the method within code, and it ensures consistency among the
method names used.

## Rule details
## Rule Details

This rule triggers a warning if the alias name, rather than the canonical name,
of a method is used.
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-commented-out-tests.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow commented out tests (`no-commented-out-tests`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

This rule raises a warning about commented out tests. It's similar to
no-disabled-tests rule.

Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-conditional-expect.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Prevent calling `expect` conditionally (`no-conditional-expect`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- /RULE_NOTICE -->

This rule prevents the use of `expect` in conditional blocks, such as `if`s &
`catch`s.

Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-conditional-in-test.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow conditional logic in tests (`no-conditional-in-test`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

Conditional logic in tests is usually an indication that a test is attempting to
cover too much, and not testing the logic it intends to. Each branch of code
executing within a conditional statement will usually be better served by a test
Expand Down
12 changes: 11 additions & 1 deletion docs/rules/no-deprecated-functions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Disallow use of deprecated functions (`no-deprecated-functions`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

<!-- /RULE_NOTICE -->

Over the years Jest has accrued some debt in the form of functions that have
either been renamed for clarity, or replaced with more powerful APIs.

Expand All @@ -11,7 +21,7 @@ This rule requires knowing which version of Jest you're using - see
on how that is obtained automatically and how you can explicitly provide a
version if needed.

## Rule details
## Rule Details

This rule warns about calls to deprecated functions, and provides details on
what to replace them with, based on the version of Jest that is installed.
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-disabled-tests.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow disabled tests (`no-disabled-tests`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

Jest has a feature that allows you to temporarily mark tests as disabled. This
feature is often helpful while debugging or to create placeholders for future
tests. Before committing changes we may want to check that all tests are
Expand Down
12 changes: 11 additions & 1 deletion docs/rules/no-done-callback.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Avoid using a callback in asynchronous tests and hooks (`no-done-callback`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
bmish marked this conversation as resolved.
Show resolved Hide resolved

<!-- /RULE_NOTICE -->

When calling asynchronous code in hooks and tests, `jest` needs to know when the
asynchronous work is complete to progress the current run.

Expand Down Expand Up @@ -49,7 +59,7 @@ test('the data is peanut butter', async () => {
});
```

## Rule details
## Rule Details

This rule checks the function parameter of hooks & tests for use of the `done`
argument, suggesting you return a promise instead.
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-duplicate-hooks.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow duplicate setup and teardown hooks (`no-duplicate-hooks`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

A `describe` block should not contain duplicate hooks.

## Rule Details
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-export.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow using `exports` in files containing tests (`no-export`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- /RULE_NOTICE -->

Prevents using `exports` if a file has one or more tests in it.

## Rule Details
Expand Down
11 changes: 11 additions & 0 deletions docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Disallow focused tests (`no-focused-tests`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
💡 This rule is manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).

<!-- /RULE_NOTICE -->

<!-- prettier-ignore -->
Jest has a feature that allows you to focus tests by appending `.only` or
prepending `f` to a test-suite or a test-case. This feature is really helpful to
debug a failing test, so you don’t have to execute all of your tests. After you
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-hooks.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow setup and teardown hooks (`no-hooks`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

Jest provides global functions for setup and teardown tasks, which are called
before/after each test case and each test suite. The use of these hooks promotes
shared state between tests.
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-identical-title.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow identical titles (`no-identical-title`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- /RULE_NOTICE -->

Having identical titles for two different tests or test suites may create
confusion. For example, when a test with the same title as another test in the
same test suite fails, it is harder to know which one failed and thus harder to
Expand Down
6 changes: 5 additions & 1 deletion docs/rules/no-if.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Disallow conditional logic (`no-if`)

## Deprecated
<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

❌ This rule is deprecated.
bmish marked this conversation as resolved.
Show resolved Hide resolved

<!-- /RULE_NOTICE -->

This rule has been deprecated in favor of
[`no-conditional-in-test`](no-conditional-in-test.md).
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-interpolation-in-snapshots.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- /RULE_NOTICE -->

Prevents the use of string interpolations in snapshots.

## Rule Details
Expand Down
12 changes: 11 additions & 1 deletion docs/rules/no-jasmine-globals.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Disallow Jasmine globals (`no-jasmine-globals`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- prettier-ignore -->
🔧 This rule is automatically fixable using the `--fix` [option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

<!-- /RULE_NOTICE -->

`jest` uses `jasmine` as a test runner. A side effect of this is that both a
`jasmine` object, and some jasmine-specific globals, are exposed to the test
environment. Most functionality offered by Jasmine has been ported to Jest, and
the Jasmine globals will stop working in the future. Developers should therefore
migrate to Jest's documented API instead of relying on the undocumented Jasmine
API.

### Rule details
## Rule Details

This rule reports on any usage of Jasmine globals, which is not ported to Jest,
and suggests alternatives from Jest's own API.
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-large-snapshots.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# disallow large snapshots (`no-large-snapshots`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

When using Jest's snapshot capability one should be mindful of the size of
created snapshots. As a general best practice snapshots should be limited in
size in order to be more manageable and reviewable. A stored snapshot is only as
Expand Down
9 changes: 8 additions & 1 deletion docs/rules/no-mocks-import.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Disallow manually importing from `__mocks__` (`no-mocks-import`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`, `recommended`.

<!-- /RULE_NOTICE -->

When using `jest.mock`, your tests (just like the code being tested) should
import from `./x`, not `./__mocks__/x`. Not following this rule can lead to
confusion, because you will have multiple instances of the mocked module:
Expand All @@ -14,7 +21,7 @@ test('x', () => {
});
```

### Rule details
## Rule Details

This rule reports imports from a path containing a `__mocks__` component.

Expand Down
13 changes: 12 additions & 1 deletion docs/rules/no-restricted-matchers.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# Disallow specific matchers & modifiers (`no-restricted-matchers`)

<!-- RULE_NOTICE -- Generated by `yarn tools:regenerate-docs` -->

<!-- prettier-ignore -->
💼 This rule is enabled in the following [configs](https://github.com/jest-community/eslint-plugin-jest#shareable-configurations): `all`.

<!-- /RULE_NOTICE -->

You may want to ban specific matchers & modifiers from being used.

## Rule Details

This rule bans specific matchers & modifiers from being used, and can suggest
alternatives.

## Rule Details
## Options

Bans are expressed in the form of a map, with the value being either a string
message to be shown, or `null` if the default rule message should be used.
Expand Down
Loading