Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,10 @@ Manually fixable by

### Requires Type Checking

| Name           | Description | 💼 | ⚠️ | 🔧 | 💡 |
| :--------------------------------------------- | :----------------------------------------------------------- | :-- | :-- | :-- | :-- |
| [unbound-method](docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | | | | |
| Name                     | Description | 💼 | ⚠️ | 🔧 | 💡 |
| :----------------------------------------------------------------- | :----------------------------------------------------------- | :-- | :-- | :-- | :-- |
| [no-unnecessary-assertion](docs/rules/no-unnecessary-assertion.md) | Disallow unnecessary assertions based on types | | | | |
| [unbound-method](docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | | | | |

<!-- end auto-generated rules list -->

Expand Down
34 changes: 34 additions & 0 deletions docs/rules/no-unnecessary-assertion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Disallow unnecessary assertions based on types (`no-unnecessary-assertion`)

💭 This rule requires
[type information](https://typescript-eslint.io/linting/typed-linting).

<!-- end auto-generated rule header -->

When using TypeScript, it is possible to ...

## Rule details

This rule warns when you do an assertion about being `null` or `undefined` on
something that cannot be those types, as that indicates either the assertion can
be removed or the types need to be adjusted.

The following patterns are considered warnings:

```ts
expect('hello world'.match('sunshine') ?? []).toBeNull();

expect(User.findOrThrow(1)).toBeDefined();

expect(map.getOrInsert('key', 'default')).not.toBeUndefined();
```

The following patterns are not considered warnings:

```ts
expect('hello world'.match('sunshine')).toBeNull();

expect(User.findOrNull(1)).toBeDefined();

expect(map.get('key')).not.toBeUndefined();
```
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/rules.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest/no-standalone-expect": "error",
"jest/no-test-prefixes": "error",
"jest/no-test-return-statement": "error",
"jest/no-unnecessary-assertion": "error",
"jest/no-unneeded-async-expect-function": "error",
"jest/no-untyped-mock-factory": "error",
"jest/padding-around-after-all-blocks": "error",
Expand Down Expand Up @@ -132,6 +133,7 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest/no-standalone-expect": "error",
"jest/no-test-prefixes": "error",
"jest/no-test-return-statement": "error",
"jest/no-unnecessary-assertion": "error",
"jest/no-unneeded-async-expect-function": "error",
"jest/no-untyped-mock-factory": "error",
"jest/padding-around-after-all-blocks": "error",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync } from 'fs';
import { resolve } from 'path';
import plugin from '../';

const numberOfRules = 67;
const numberOfRules = 68;
const ruleNames = Object.keys(plugin.rules);
const deprecatedRules = Object.entries(plugin.rules)
.filter(([, rule]) => rule.meta.deprecated)
Expand Down
Loading
Loading