Skip to content

Commit

Permalink
fix: update config of jest/no-restricted-matchers to continue banni…
Browse files Browse the repository at this point in the history
…ng all variations of matchers
  • Loading branch information
G-Rath committed Oct 14, 2022
1 parent 9d2307c commit 8c6c64a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions jest.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8c6c64a

Please sign in to comment.