Skip to content

Commit

Permalink
Create more tooling (#578)
Browse files Browse the repository at this point in the history
* chore: create `generate-rules-table` script

* docs: update titles

* chore: update rule descriptions

* docs: regenerate rules table in README

* chore: `sort-package-json`
  • Loading branch information
G-Rath authored May 12, 2020
1 parent feac055 commit d7cc77e
Show file tree
Hide file tree
Showing 51 changed files with 312 additions and 202 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ module.exports = {
globals,
},
{
files: ['src/**/*', 'dangerfile.ts'],
files: ['src/**/*', 'dangerfile.ts', 'tools/*'],
parserOptions: {
sourceType: 'module',
},
},
{
files: ['tools/*'],
rules: {
'node/shebang': 'off',
},
},
{
files: ['.eslintrc.js', 'babel.config.js'],
rules: {
Expand Down
134 changes: 48 additions & 86 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/rules/consistent-test-it.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Have control over `test` and `it` usages (consistent-test-it)
# Have control over `test` and `it` usages (`consistent-test-it`)

Jest allows you to choose how you want to define your tests, using the `it` or
the `test` keywords, with multiple permutations for each:
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce assertion to be made in a test body (expect-expect)
# Enforce assertion to be made in a test body (`expect-expect`)

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

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/lowercase-name.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce lowercase test names (lowercase-name)
# Enforce lowercase test names (`lowercase-name`)

## Rule details

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-alias-methods.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Don't use alias methods (no-alias-methods)
# Don't use alias methods (`no-alias-methods`)

Several Jest methods have alias names, such as `toThrow` having the alias of
`toThrowError`. This rule ensures that only the canonical name as used in the
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-commented-out-tests.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow commented out tests (no-commented-out-tests)
# Disallow commented out tests (`no-commented-out-tests`)

This rule raises a warning about commented out tests. It's similar to
no-disabled-tests rule.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-disabled-tests.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow disabled tests (no-disabled-tests)
# Disallow disabled tests (`no-disabled-tests`)

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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-duplicate-hooks.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow duplicate setup and teardown hooks (no-duplicate-hooks)
# Disallow duplicate setup and teardown hooks (`no-duplicate-hooks`)

A describe block should not contain duplicate hooks.

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-expect-resolves.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Avoid using `expect().resolves` (no-expect-resolves)
# Avoid using `expect().resolves` (`no-expect-resolves`)

Jest allows you to test a promise resolve value using `await expect().resolves`.
For consistency and readability this rule bans `expect().resolves` in favor of
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-export.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# no export from test file (no-export)
# Prevent exporting from test files (`no-export`)

Prevents exports from test files. If a file has at least 1 test in it, then this
rule will prevent exports.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow focused tests (no-focused-tests)
# Disallow focused tests (`no-focused-tests`)

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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-hooks.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow setup and teardown hooks (no-hooks)
# Disallow setup and teardown hooks (`no-hooks`)

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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-identical-title.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow identical titles (no-identical-title)
# Disallow identical titles (`no-identical-title`)

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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-if.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow conditional logic. (no-if)
# Disallow conditional logic (`no-if`)

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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-jasmine-globals.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow Jasmine globals
# Disallow Jasmine globals (`no-jasmine-globals`)

`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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-jest-import.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow importing Jest(no-jest-import)
# Disallow importing Jest (`no-jest-import`)

The `jest` object is automatically in scope within every test file. The methods
in the `jest` object help create mocks and let you control Jest's overall
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-large-snapshots.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# disallow large snapshots (no-large-snapshots)
# disallow large snapshots (`no-large-snapshots`)

When using Jest's snapshot capability one should be mindful of the size of
created snapshots. As a best practice snapshots should be limited in size in
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-mocks-import.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow manually importing from `__mocks__` (no-mocks-import)
# Disallow manually importing from `__mocks__` (`no-mocks-import`)

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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-standalone-expect.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# No standalone expect in a describe block (no-standalone-expect)
# No standalone expect in a describe block (`no-standalone-expect`)

Prevents `expect` statements outside of a `test` or `it` block. An `expect`
within a helper function (but outside of a `test` or `it` block) will not
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-test-callback.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Avoid using a callback in asynchronous tests (no-test-callback)
# Avoid using a callback in asynchronous tests (`no-test-callback`)

Jest allows you to pass a callback to test definitions, typically called `done`,
that is later invoked to indicate that the asynchronous test is complete.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-test-prefixes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Use `.only` and `.skip` over `f` and `x` (no-test-prefixes)
# Use `.only` and `.skip` over `f` and `x` (`no-test-prefixes`)

Jest allows you to choose how you want to define focused and skipped tests, with
multiple permutations for each:
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-test-return-statement.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow explicitly returning from tests (no-test-return-statement)
# Disallow explicitly returning from tests (`no-test-return-statement`)

Tests in Jest should be void and not return values.

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-truthy-falsy.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow using `toBeTruthy()` & `toBeFalsy()` (no-truthy-falsy)
# Disallow using `toBeTruthy()` & `toBeFalsy()` (`no-truthy-falsy`)

Tests against boolean values should assert true or false. Asserting `toBeTruthy`
or `toBeFalsy` matches non-boolean values as well and encourages weaker tests.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-try-expect.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prevent catch assertions in tests (no-try-expect)
# Prevent catch assertions in tests (`no-try-expect`)

This rule prevents the use of `expect` inside `catch` blocks.

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-called-with.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toBeCalledWith` OR `toHaveBeenCalledWith` (prefer-called-with)
# Suggest using `toBeCalledWith` OR `toHaveBeenCalledWith` (`prefer-called-with`)

The `toBeCalled()` matcher is used to assert that a mock function has been
called one or more times, without checking the arguments passed. The assertion
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-expect-assertions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `expect.assertions()` OR `expect.hasAssertions()` (prefer-expect-assertions)
# Suggest using `expect.assertions()` OR `expect.hasAssertions()` (`prefer-expect-assertions`)

Ensure every test to have either `expect.assertions(<number of assertions>)` OR
`expect.hasAssertions()` as its first expression.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-hooks-on-top.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest to have all hooks at top-level before tests (prefer-hooks-on-top)
# Suggest to have all hooks at top-level before tests (`prefer-hooks-on-top`)

All hooks should be defined before the start of the tests

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-inline-snapshots.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using inline snapshots (prefer-inline-snapshots)
# Suggest using inline snapshots (`prefer-inline-snapshots`)

In order to make snapshot tests more managable and reviewable
`toMatchInlineSnapshot()` and `toThrowErrorMatchingInlineSnapshot` should be
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-spy-on.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `jest.spyOn()` (prefer-spy-on)
# Suggest using `jest.spyOn()` (`prefer-spy-on`)

When mocking a function by overwriting a property you have to manually restore
the original implementation when cleaning up. When using `jest.spyOn()` Jest
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-strict-equal.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toStrictEqual()` (prefer-strict-equal)
# Suggest using `toStrictEqual()` (`prefer-strict-equal`)

`toStrictEqual` not only checks that two objects contain the same data but also
that they have the same structure. It is common to expect objects to not only
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-be-null.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toBeNull()` (prefer-to-be-null)
# Suggest using `toBeNull()` (`prefer-to-be-null`)

In order to have a better failure message, `toBeNull()` should be used upon
asserting expections on null value.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-be-undefined.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toBeUndefined()` (prefer-to-be-undefined)
# Suggest using `toBeUndefined()` (`prefer-to-be-undefined`)

In order to have a better failure message, `toBeUndefined()` should be used upon
asserting expections on undefined value.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-contain.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toContain()` (prefer-to-contain)
# Suggest using `toContain()` (`prefer-to-contain`)

In order to have a better failure message, `toContain()` should be used upon
asserting expectations on an array containing an object.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-to-have-length.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `toHaveLength()` (prefer-to-have-length)
# Suggest using `toHaveLength()` (`prefer-to-have-length`)

In order to have a better failure message, `toHaveLength()` should be used upon
asserting expectations on object's length property.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-todo.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Suggest using `test.todo` (prefer-todo)
# Suggest using `test.todo` (`prefer-todo`)

When test cases are empty then it is better to mark them as `test.todo` as it
will be highlighted in the summary output.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/require-to-throw-message.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Require a message for `toThrow()` (require-to-throw-message)
# Require a message for `toThrow()` (`require-to-throw-message`)

`toThrow()`, and its alias `toThrowError()`, are used to check if an error is
thrown by a function call, such as in `expect(() => a()).toThrow()`. However, if
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/require-top-level-describe.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Require top-level describe block (require-top-level-describe)
# Require top-level describe block (`require-top-level-describe`)

Jest allows you to organise your test files the way you want it. However, the
more your codebase grows, the more it becomes hard to navigate in your test
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/valid-describe.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce valid `describe()` callback (valid-describe)
# Enforce valid `describe()` callback (`valid-describe`)

Using an improper `describe()` callback function can lead to unexpected test
errors.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/valid-expect-in-promise.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce having return statement when testing with promises (valid-expect-in-promise)
# Enforce having return statement when testing with promises (`valid-expect-in-promise`)

Ensure to return promise when having assertions in `then` or `catch` block of
promise
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/valid-expect.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Enforce valid `expect()` usage (valid-expect)
# Enforce valid `expect()` usage (`valid-expect`)

Ensure `expect()` is called with a single argument and there is an actual
expectation made.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/valid-title.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# describe/test titles should be valid (valid-title)
# describe/test titles should be valid (`valid-title`)

Checks that the title of Jest blocks are valid by ensuring that titles are:

Expand Down
Loading

0 comments on commit d7cc77e

Please sign in to comment.