Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update eslint-plugin-jest to v27 #252

Merged
merged 3 commits into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required because of jest-community/eslint-plugin-jest#1218

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