question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`require-hook` rule checks non-test files

See original GitHub issue

Hello, first of all: thanks for your work!

I’m currently facing an issue upgrading to v25.0.1 due to the require-hook rule. This rule is applied outside of test files.

Here’s an example with .tsx and ts files: image

Versions:

  • eslint: 7.32.0
  • eslint-plugin-jest: 25.0.1
  • node: 14.17.0

Thank’s for your help!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
SimenBcommented, Oct 15, 2021

@thibaultdelor unfortunately not as config Jest’s config loading is async while ESLint’s config loading is sync. See https://github.com/jest-community/eslint-plugin-jest/pull/754#issuecomment-780396777 for details


@G-Rath we should probably add an example to the docs as this rule is quite aggressive and seemingly the only one we have that causes issues in this way (at least in recommended config) - this is the third issue about it in as many days.

1reaction
G-Rathcommented, Oct 16, 2021

fwiw, this rule isn’t in the recommended config, but 💯 agree on having this in our docs.

tbh I actually thought we did mention it in the readme but we don’t so I think that should definitely change - I think our general configuration example should be using overrides with Jest’s default file matcher as the glob (or as close to as possible).

Then for require-hook I think we should be good to just have an extra warning saying this rule is very noisy, make sure you're using overrides to only apply it to your test files as shown [in the readme](link)

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint doesn't recognize rule violations in test files and built-in ...
Now a warning should not appear. Next, is to set up a smoke test. All I saw in your example was a file...
Read more >
eslint-plugin-jest - npm
Running rules only on test-related files. The rules provided by this plugin assume that the files they are checking are test-related. This means ......
Read more >
The compiler for next generation JavaScript - Babel
Babel built-ins. CLIRequire hook. Build systems ... Test frameworks. AVAJasmineJestKarmaLabMocha. Utilities. ConnectNodemon. Language APIs. C# / .
Read more >
Testing in ES6 with Mocha and Babel 6 - James K Nelson
Naturally, your tests import the lib code which you're actually publishing, not the original src files. And while this may go without saying, ......
Read more >
eslint-plugin-jest | Yarn - Package Manager
Rules ; prefer-to-have-length, Suggest using toHaveLength(), ; prefer-todo, Suggest using test.todo ; require-hook, Require setup and teardown code to be within ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found