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

oxlint: jest-plugin: no-export: false positives for exports in __mocks__ files #2397

Closed
jokeyrhyme opened this issue Feb 11, 2024 · 4 comments · Fixed by #2408
Closed

oxlint: jest-plugin: no-export: false positives for exports in __mocks__ files #2397

jokeyrhyme opened this issue Feb 11, 2024 · 4 comments · Fixed by #2408
Labels
A-linter Area - Linter good first issue Experience Level - Good for newcomers

Comments

@jokeyrhyme
Copy link

Thanks so much for sharing this exciting project!

I have a project that uses the manual mocks feature for jest: https://jestjs.io/docs/manual-mocks

e.g.

  • other.js (contains export do() => { /* ... */ })
  • __mocks__/other.js (contains export do() -> jest.fn().mockImplementation(() => { /* ... */ }))
  • thing.js (contains import './other.js')
  • thing.test.js (contains jest.mock('./other.js'))

It's expected that these jest manual mock files export just like the production files that they mirror

oxlint --jest-plugin (version 0.2.8) results in "⚠ eslint-plugin-jest(no-export): Do not export from a test file." when scanning __mocks__/other.js , so it seems to consider these manual mock files to be test files, but I think it should not classify them as test files

@mysteryven mysteryven self-assigned this Feb 12, 2024
@mysteryven
Copy link
Member

Thanks for your using! we treated it as a test file if it imports global variables like jest, beforeEach, test, etc… we should distinguish it by file path.

@jokeyrhyme
Copy link
Author

jokeyrhyme commented Feb 12, 2024

By default, jest uses these lists of globs to find test files:

But, by default, it will first search for a jest.config.js|ts|mjs|cjs|json file ( https://jestjs.io/docs/configuration ) that can override these globs

I'm not sure how much complexity is desirable in this area, but perhaps we could start with the equivalent of those hard-coded globs? Would you accept a PR that also checks for a static jest.config.json file?

@mysteryven
Copy link
Member

We can start with a hard-coded glob first, PR is always welcome!

Do we need to check static jest config? @Boshen

@mysteryven mysteryven removed their assignment Feb 12, 2024
@mysteryven mysteryven added good first issue Experience Level - Good for newcomers A-linter Area - Linter labels Feb 12, 2024
@Boshen
Copy link
Member

Boshen commented Feb 12, 2024

Do we need to check static jest config?

Let's try and not to read another config file. Are there any workarounds? For example ignore the rule by using https://eslint.org/docs/latest/use/configure/ignore#ignorepatterns-in-config-files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter good first issue Experience Level - Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants