Skip to content

Commit

Permalink
feat: update eslint-plugin-jest to v27 (#252)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency eslint-plugin-jest to v27

* test: default to using `@typescript-eslint/parser` for rules that optionally support type services

* fix: update config of `jest/no-restricted-matchers` to continue banning all variations of matchers

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Gareth Jones <jones258@gmail.com>
  • Loading branch information
renovate[bot] and G-Rath committed Oct 18, 2022
1 parent 3c1567c commit 944cbfb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 39 deletions.
24 changes: 22 additions & 2 deletions jest.js
@@ -1,3 +1,23 @@
/**
* Generates a config for `jest/no-restricted-matchers` that bans all variations
* of the given base matchers
*
* @param {Record<string, string>} matchers
*
* @return {Record<string, string>}
*/
const banMatchers = matchers => {
return Object.fromEntries(
Object.entries(matchers).flatMap(([matcher, message]) => [
[matcher, message],
[`resolves.${matcher}`, message],
[`resolves.not.${matcher}`, message],
[`rejects.not.${matcher}`, message],
[`not.${matcher}`, message]
])
);
};

/** @type {import('eslint').Linter.Config} */
const config = {
plugins: ['jest', 'jest-formatting'],
Expand All @@ -20,13 +40,13 @@ const config = {
'jest/no-large-snapshots': 'warn',
'jest/no-restricted-matchers': [
'error',
{
banMatchers({
toThrowErrorMatchingSnapshot:
'Use `toThrowErrorMatchingInlineSnapshot()` instead',
toMatchSnapshot: 'Use `toMatchInlineSnapshot()` instead',
toBeTruthy: 'Avoid `toBeTruthy`',
toBeFalsy: 'Avoid `toBeFalsy`'
}
})
],
'jest/no-test-return-statement': 'error',
'jest/prefer-called-with': 'error',
Expand Down
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -71,7 +71,7 @@
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-flowtype": "^8.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-jest": "^27.0.0",
"eslint-plugin-jest-formatting": "^3.0.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -97,7 +97,7 @@
"eslint-plugin-eslint-comments": ">= 3",
"eslint-plugin-flowtype": "^8.0.0",
"eslint-plugin-import": ">= 2.21",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-jest": "^27.0.0",
"eslint-plugin-jest-formatting": "^3.0.0",
"eslint-plugin-jsx-a11y": "^6.0.0",
"eslint-plugin-node": ">= 2.21",
Expand Down
3 changes: 3 additions & 0 deletions test/configs.spec.ts
Expand Up @@ -121,6 +121,9 @@ describe('for each config file', () => {
expect.hasAssertions();

const baseConfig: ESLint.Linter.Config = {
// default to using the @typescript-eslint/parser in case we have any
// rules that can use the type services, like `jest/unbound-method`
parser: '@typescript-eslint/parser',
...config,
parserOptions: {
// @babel/eslint-parser
Expand Down

0 comments on commit 944cbfb

Please sign in to comment.