| 1 | # Enforces unbound methods are called with their expected scope (`unbound-method`)
|
|---|
| 2 |
|
|---|
| 3 | ## Rule Details
|
|---|
| 4 |
|
|---|
| 5 | This rule extends the base [`@typescript-eslint/unbound-method`][original-rule]
|
|---|
| 6 | rule, meaning you must depend on `@typescript-eslint/eslint-plugin` for it to
|
|---|
| 7 | work. It adds support for understanding when it's ok to pass an unbound method
|
|---|
| 8 | to `expect` calls.
|
|---|
| 9 |
|
|---|
| 10 | See the [`@typescript-eslint` documentation][original-rule] for more details on
|
|---|
| 11 | the `unbound-method` rule.
|
|---|
| 12 |
|
|---|
| 13 | Note that while this rule requires type information to work, it will fail
|
|---|
| 14 | silently when not available allowing you to safely enable it on projects that
|
|---|
| 15 | are not using TypeScript.
|
|---|
| 16 |
|
|---|
| 17 | ## How to use
|
|---|
| 18 |
|
|---|
| 19 | ```json5
|
|---|
| 20 | {
|
|---|
| 21 | parser: '@typescript-eslint/parser',
|
|---|
| 22 | parserOptions: {
|
|---|
| 23 | project: 'tsconfig.json',
|
|---|
| 24 | ecmaVersion: 2020,
|
|---|
| 25 | sourceType: 'module',
|
|---|
| 26 | },
|
|---|
| 27 | overrides: [
|
|---|
| 28 | {
|
|---|
| 29 | files: ['test/**'],
|
|---|
| 30 | plugins: ['jest'],
|
|---|
| 31 | rules: {
|
|---|
| 32 | // you should turn the original rule off *only* for test files
|
|---|
| 33 | '@typescript-eslint/unbound-method': 'off',
|
|---|
| 34 | 'jest/unbound-method': 'error',
|
|---|
| 35 | },
|
|---|
| 36 | },
|
|---|
| 37 | ],
|
|---|
| 38 | rules: {
|
|---|
| 39 | '@typescript-eslint/unbound-method': 'error',
|
|---|
| 40 | },
|
|---|
| 41 | }
|
|---|
| 42 | ```
|
|---|
| 43 |
|
|---|
| 44 | This rule should be applied to your test files in place of the original rule,
|
|---|
| 45 | which should be applied to the rest of your codebase.
|
|---|
| 46 |
|
|---|
| 47 | ## Options
|
|---|
| 48 |
|
|---|
| 49 | See [`@typescript-eslint/unbound-method`][original-rule] options.
|
|---|
| 50 |
|
|---|
| 51 | <sup>Taken with ❤️ [from `@typescript-eslint` core][original-rule]</sup>
|
|---|
| 52 |
|
|---|
| 53 | [original-rule]:
|
|---|
| 54 | https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md
|
|---|