Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v24.2.1
Choose a base ref
...
head repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v24.3.0
Choose a head ref
  • 2 commits
  • 23 files changed
  • 2 contributors

Commits on Mar 13, 2021

  1. feat(unbound-method): create rule (#765)

    * feat(unbound-method): add original `unbound-method` rule
    
    * feat(unbound-method): modify rule for `jest`
    
    * refactor(unbound-method): extend base rule
    
    * docs(readme): add section about type-based rules
    
    * chore: add `@typescript-eslint/eslint-plugin` as an optional peer dep
    
    * fix(unbound-method): re-throw errors that are not `MODULE_NOT_FOUND`
    
    * chore(unbound-method): use early return instead of empty string
    
    * test(unbound-method): adjust test
    
    * build: ignore test fixtures
    
    * test: add end of file newline to fixture
    
    * docs(unbound-method): mention `@typescript-eslint/eslint-plugin` dep
    
    * refactor(unbound-method): improve method & variable name
    G-Rath authored Mar 13, 2021
    Copy the full SHA
    b1f4ed3 View commit details
  2. chore(release): 24.3.0 [skip ci]

    # [24.3.0](v24.2.1...v24.3.0) (2021-03-13)
    
    ### Features
    
    * **unbound-method:** create rule ([#765](#765)) ([b1f4ed3](b1f4ed3))
    semantic-release-bot committed Mar 13, 2021
    Copy the full SHA
    68b3550 View commit details
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
lib/
!.eslintrc.js
src/rules/__tests__/fixtures/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [24.3.0](https://github.com/jest-community/eslint-plugin-jest/compare/v24.2.1...v24.3.0) (2021-03-13)


### Features

* **unbound-method:** create rule ([#765](https://github.com/jest-community/eslint-plugin-jest/issues/765)) ([b1f4ed3](https://github.com/jest-community/eslint-plugin-jest/commit/b1f4ed3f6bb0264fdefb5138ba913fa2bacc725c))

## [24.2.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.2.0...v24.2.1) (2021-03-10)


29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ installations requiring long-term consistency.

## Rules

<!-- begin rules list -->
<!-- begin base rules list -->

| Rule | Description | Configurations | Fixable |
| ---------------------------------------------------------------------------- | --------------------------------------------------------------- | ---------------- | ------------ |
@@ -173,7 +173,32 @@ installations requiring long-term consistency.
| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Enforce having return statement when testing with promises | ![recommended][] | |
| [valid-title](docs/rules/valid-title.md) | Enforce valid titles | ![recommended][] | ![fixable][] |

<!-- end rules list -->
<!-- end base rules list -->

## TypeScript Rules

In addition to the above rules, this plugin also includes a few advanced rules
that are powered by type-checking information provided by TypeScript.

In order to use these rules, you must be using `@typescript-eslint/parser` &
adjust your eslint config as outlined
[here](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md)

Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
the rules here will fallback to doing nothing if type information is not
available, meaning its safe to include them in shared configs that could be used
on JavaScript and TypeScript projects.

Also note that `unbound-method` depends on `@typescript-eslint/eslint-plugin`,
as it extends the original `unbound-method` rule from that plugin.

<!-- begin type rules list -->

| Rule | Description | Configurations | Fixable |
| ---------------------------------------------- | ------------------------------------------------------------- | -------------- | ------- |
| [unbound-method](docs/rules/unbound-method.md) | Enforces unbound methods are called with their expected scope | | |

<!-- end type rules list -->

## Credit

1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -7,4 +7,5 @@ module.exports = {
'@babel/preset-typescript',
['@babel/preset-env', { targets: { node: 10 } }],
],
ignore: ['src/**/__tests__/fixtures/**'],
};
54 changes: 54 additions & 0 deletions docs/rules/unbound-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Enforces unbound methods are called with their expected scope (`unbound-method`)

## Rule Details

This rule extends the base [`@typescript-eslint/unbound-method`][original-rule]
rule, meaning you must depend on `@typescript-eslint/eslint-plugin` for it to
work. It adds support for understanding when it's ok to pass an unbound method
to `expect` calls.

See the [`@typescript-eslint` documentation][original-rule] for more details on
the `unbound-method` rule.

Note that while this rule requires type information to work, it will fail
silently when not available allowing you to safely enable it on projects that
are not using TypeScript.

## How to use

```json5
{
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
ecmaVersion: 2020,
sourceType: 'module',
},
overrides: [
{
files: ['test/**'],
extends: ['jest'],
rules: {
// you should turn the original rule off *only* for test files
'@typescript-eslint/unbound-method': 'off',
'jest/unbound-method': 'error',
},
},
],
rules: {
'@typescript-eslint/unbound-method': 'error',
},
}
```

This rule should be applied to your test files in place of the original rule,
which should be applied to the rest of your codebase.

## Options

See [`@typescript-eslint/unbound-method`][original-rule] options.

<sup>Taken with ❤️ [from `@typescript-eslint` core][original-rule]</sup>

[original-rule]:
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-jest",
"version": "24.2.1",
"version": "24.3.0",
"description": "Eslint rules for Jest",
"keywords": [
"eslint",
@@ -62,7 +62,8 @@
"displayName": "test",
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/lib/.*"
"<rootDir>/lib/.*",
"<rootDir>/src/rules/__tests__/fixtures/*"
]
},
{
@@ -121,8 +122,14 @@
"typescript": "^4.0.0"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">= 4",
"eslint": ">=5"
},
"peerDependenciesMeta": {
"@typescript-eslint/eslint-plugin": {
"optional": true
}
},
"engines": {
"node": ">=10"
},
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/rules.test.ts.snap
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ Object {
"jest/prefer-todo": "error",
"jest/require-to-throw-message": "error",
"jest/require-top-level-describe": "error",
"jest/unbound-method": "error",
"jest/valid-describe": "error",
"jest/valid-expect": "error",
"jest/valid-expect-in-promise": "error",
2 changes: 1 addition & 1 deletion src/__tests__/rules.test.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
import { resolve } from 'path';
import plugin from '../';

const numberOfRules = 44;
const numberOfRules = 45;
const ruleNames = Object.keys(plugin.rules);
const deprecatedRules = Object.entries(plugin.rules)
.filter(([, rule]) => rule.meta.deprecated)
13 changes: 13 additions & 0 deletions src/rules/__tests__/fixtures/class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// used by no-throw-literal test case to validate custom error
export class Error {}

// used by unbound-method test case to test imports
export const console = { log() {} };

// used by prefer-reduce-type-parameter to test native vs userland check
export class Reducable {
reduce() {}
}

// used by no-implied-eval test function imports
export class Function {}
Empty file.
1 change: 1 addition & 0 deletions src/rules/__tests__/fixtures/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type T = number;
Loading