web-infra-dev / web-infra-dev/rslint

[Feature]: Lint Rstest support

Open
#935 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
459
Forks
33
Avg merge
1d 2h
Merged PRs (30d)
376

Description

## What problem does this feature solve?

Related discussion: https://github.com/web-infra-dev/rstest/issues/85#issuecomment-4435049030

Most of the rules for jest may also be applicable to Rstest. In a typical repo which using Rstest - web-infra-dev/rsbuild - around 2/3 of the `eslint-plugin-jest` rules can pass directly.

So I have a proposal: we could share an abstraction layer under both Jest and Rstest lint rules in our repo. Consider Rslint is now porting rules from `eslint-plugin-jest` actively, we can extract some utils outside first. once the jest rules become stable, we can start building Rstest rules on top of the existing things.

## Tracker

### Rstest-only Recommended (1/1)

| Rule Name | Will implement | Status | Level |
| --- | :---: | :---: | :---: |
| no-async-mock-factory | βœ… | Merged [#2100](https://github.com/web-infra-dev/rslint/pull/2100) | `error` |

### Jest Recommended (13/13)

| Rule Name | Will implement | Status | Level |
| --- | :---: | :---: | :---: |
| expect-expect | βœ… | Merged [#1614](https://github.com/web-infra-dev/rslint/pull/1614) | `warn` |
| no-alias-methods | βœ… | Merged [#1837](https://github.com/web-infra-dev/rslint/pull/1837) | Not recommended[^no-alias-methods] |
| no-conditional-expect | βœ… | Merged [#1548](https://github.com/web-infra-dev/rslint/pull/1548) | `error` |
| no-deprecated-functions | 🚫 | 🚫 | 🚫 |
| no-commented-out-tests | βœ… | Merged [#1339](https://github.com/web-infra-dev/rslint/pull/1339) | `warn` |
| no-disabled-tests | βœ… | Merged [#1475](https://github.com/web-infra-dev/rslint/pull/1475) | `warn` |
| no-done-callback | 🚫 | 🚫 | 🚫 |
| no-export | 🚫 | 🚫 | 🚫 |
| no-focused-tests | βœ… | Merged [#1363](https://github.com/web-infra-dev/rslint/pull/1363) | `error` |
| no-identical-title | βœ… | Merged [#1473](https://github.com/web-infra-dev/rslint/pull/1473) | `error` |
| no-interpolation-in-snapshots | βœ… | Merged [#1604](https://github.com/web-infra-dev/rslint/pull/1604) | `error` |
| no-jasmine-globals | 🚫 | 🚫 | 🚫 |
| no-mocks-import | βœ… | Merged [#1295](https://github.com/web-infra-dev/rslint/pull/1295) | `error` |
| no-standalone-expect | βœ… | Merged #1701 | `error` |
| no-test-prefixes | 🚫 | 🚫 | 🚫 |
| valid-describe-callback | 🚫 | 🚫 | 🚫 |
| valid-expect | βœ… | Merged [#1695](https://github.com/web-infra-dev/rslint/pull/1695) | `error` |
| valid-expect-in-promise | βœ… | Merged [#1696](https://github.com/web-infra-dev/rslint/pull/1696) | `error` |
| valid-title | βœ… | Merged [#1606](https://github.com/web-infra-dev/rslint/pull/1606) | `error` |

### Vitest Recommended not in Jest Recommended (3/3)

| Rule Name | Will implement | Status | Level |
| --- | :---: | :---: | :---: |
| no-import-node-test | βœ… | Merged [#1775](https://github.com/web-infra-dev/rslint/pull/1775) | `error` |
| prefer-called-exactly-once-with | βœ… | Merged [#1776](https://github.com/web-infra-dev/rslint/pull/1776) | `error` |
| require-local-test-context-for-concurrent-snapshots | βœ… | Merged [#1778](https://github.com/web-infra-dev/rslint/pull/1778) | `error` |

### Jest Not Recommended (28/45)

| Rule Name | Ready for Jest | Will implement | Status |
| --- | :---: | :---: | :---: |
| consistent-test-it | β€” | βœ… | Merged [#2110](https://github.com/web-infra-dev/rslint/pull/2110) |
| max-expects | βœ… | βœ… | Merged [#1838](https://github.com/web-infra-dev/rslint/pull/1838) |
| max-nested-describe | βœ… | βœ… | Merged [#2167](https://github.com/web-infra-dev/rslint/pull/2167) |
| no-conditional-in-test | βœ… | βœ… | Merged [#1839](https://github.com/web-infra-dev/rslint/pull/1839) |
| no-confusing-set-timeout | βœ… | 🚫 | 🚫 |
| no-duplicate-hooks | βœ… | βœ… | PR [#2195](https://github.com/web-infra-dev/rslint/pull/2195) |
| no-hooks | βœ… | βœ… | Merged [#1835](https://github.com/web-infra-dev/rslint/pull/1835) |
| no-large-snapshots | 🚫 | 🚫[^no-large-snapshots] | 🚫 |
| no-restricted-jest-methods | βœ… | 🚫 | 🚫 |
| no-restricted-matchers | βœ… | βœ… | Merged [#2086](https://github.com/web-infra-dev/rslint/pull/2086) |
| no-test-return-statement | β€” | βœ… | β€” |
| no-unneeded-async-expect-function | βœ… | βœ… | PR [#2194](https://github.com/web-infra-dev/rslint/pull/2194) |
| no-untyped-mock-factory | β€” | βœ… | β€” |
| padding-around-after-all-blocks | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| padding-around-after-each-blocks | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| padding-around-all | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| padding-around-before-all-blocks | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| padding-around-before-each-blocks | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| padding-around-describe-blocks | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| padding-around-expect-groups | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| padding-around-test-blocks | βœ… | βœ… | Merged [#2075](https://github.com/web-infra-dev/rslint/pull/2075) |
| prefer-to-be | βœ… | βœ… | Merged [#2115](https://github.com/web-infra-dev/rslint/pull/2115) |
| prefer-to-contain | βœ… | βœ… | Merged [#2127](https://github.com/web-infra-dev/rslint/pull/2127) |
| prefer-to-have-length | βœ… | βœ… | PR [#2196](https://github.com/web-infra-dev/rslint/pull/2196) |
| prefer-called-with | βœ… | βœ… | Merged [#2085](https://github.com/web-infra-dev/rslint/pull/2085) |
| prefer-comparison-matcher | βœ… | βœ… | Merged [#2121](https://github.com/web-infra-dev/rslint/pull/2121) |
| prefer-each | βœ… | βœ… | Merged [#1841](https://github.com/web-infra-dev/rslint/pull/1841) |
| prefer-ending-with-an-expect | β€” | βœ… | β€” |
| prefer-equality-matcher | βœ… | βœ… | Merged [#2091](https://github.com/web-infra-dev/rslint/pull/2091) |
| prefer-expect-assertions | β€” | βœ… | β€” |
| prefer-expect-resolves | βœ… | βœ… | β€” |
| prefer-hooks-in-order | βœ… | βœ… | Merged [#1836](https://github.com/web-infra-dev/rslint/pull/1836) |
| prefer-hooks-on-top | βœ… | βœ… | β€” |
| prefer-importing-jest-globals | β€” | 🚫 | 🚫 |
| prefer-jest-mocked | βœ… | 🚫 | 🚫 |
| prefer-lowercase-title | β€” | βœ… | β€” |
| prefer-mock-promise-shorthand | β€” | βœ… | β€” |
| prefer-mock-return-shorthand | β€” | βœ… | β€” |
| prefer-snapshot-hint | β€” | βœ… | β€” |
| prefer-spy-on | βœ… | βœ… | β€” |
| prefer-strict-equal | βœ… | βœ… | Merged [#2093](https://github.com/web-infra-dev/rslint/pull/2093) |
| prefer-to-have-been-called | βœ… | βœ… | Merged [#2160](https://github.com/web-infra-dev/rslint/pull/2160) |
| prefer-to-have-been-called-times | βœ… | βœ… | β€” |
| prefer-todo | βœ… | βœ… | Merged [#1840](https://github.com/web-infra-dev/rslint/pull/1840) |
| require-hook | βœ… | βœ… | β€” |
| require-to-throw-message | βœ… | βœ… | Merged [#2092](https://github.com/web-infra-dev/rslint/pull/2092) |
| require-top-level-describe | βœ… | βœ… | β€” |
| valid-mock-module-path | β€” | 🚫 | 🚫 |
| no-error-equal | β€” | 🚫 | 🚫 |
| no-unnecessary-assertion | β€” | βœ… | Merged [#2149](https://github.com/web-infra-dev/rslint/pull/2149) |
| unbound-method | β€” | βœ… | Merged [#2155](https://github.com/web-infra-dev/rslint/pull/2155) |
| valid-expect-with-promise | β€” | βœ… | Merged [#2151](https://github.com/web-infra-dev/rslint/pull/2151) |

### Vitest Not Recommended not in Jest (15/15)

| Rule Name | Will implement | Status |
| --- | :---: | :---: |
| consistent-each-for | βœ… | Merged [#1979](https://github.com/web-infra-dev/rslint/pull/1979) |
| consistent-test-filename | βœ… | Merged [#1978](https://github.com/web-infra-dev/rslint/pull/1978) |
| consistent-vitest-vi | 🚫[^vi-namespace] | 🚫 |
| hoisted-apis-on-top | βœ… | Merged [#1929](https://github.com/web-infra-dev/rslint/pull/1929) |
| no-conditional-tests | βœ… | Merged [#1919](https://github.com/web-infra-dev/rslint/pull/1919) |
| no-importing-vitest-globals | 🚫[^vi-namespace] | 🚫 |
| no-restricted-vi-methods | 🚫[^vi-namespace] | 🚫 |
| prefer-called-once | βœ… | Merged [#1921](https://github.com/web-infra-dev/rslint/pull/1921) |
| prefer-called-times | βœ… | Merged [#1890](https://github.com/web-infra-dev/rslint/pull/1890) |
| prefer-describe-function-title | 🚫 | 🚫 |
| prefer-expect-type-of | βœ… | Merged [#1885](https://github.com/web-infra-dev/rslint/pull/1885) |
| prefer-import-in-mock | βœ… | Merged [#1930](https://github.com/web-infra-dev/rslint/pull/1930) |
| prefer-importing-vitest-globals | 🚫[^vi-namespace] | 🚫 |
| prefer-strict-boolean-matchers | βœ… | Merged [#1972](https://github.com/web-infra-dev/rslint/pull/1972) |
| prefer-to-be-falsy | βœ… | Merged [#1972](https://github.com/web-infra-dev/rslint/pull/1972) |
| prefer-to-be-object | 🚫 | 🚫 |
| prefer-to-be-truthy | βœ… | Merged [#1972](https://github.com/web-infra-dev/rslint/pull/1972) |
| prefer-vi-mocked | 🚫[^vi-namespace] | 🚫 |
| require-awaited-expect-poll | βœ… | Merged [#1920](https://github.com/web-infra-dev/rslint/pull/1920) |
| require-mock-type-parameters | βœ… | Merged [#1944](https://github.com/web-infra-dev/rslint/pull/1944) |
| require-test-timeout | βœ… | Merged [#1918](https://github.com/web-infra-dev/rslint/pull/1918) |
| warn-todo | βœ… | Merged [#1889](https://github.com/web-infra-dev/rslint/pull/1889) |

### Rstest-only Not Recommended (5/5)

| Rule Name | Will implement | Status |
| --- | :---: | :---: |
| consistent-rstest-namespace | βœ… | Merged [#1942](https://github.com/web-infra-dev/rslint/pull/1942) |
| no-importing-rstest-globals | βœ… | Merged [#2029](https://github.com/web-infra-dev/rslint/pull/2029) |
| no-restricted-rstest-methods | βœ… | Merged [#2027](https://github.com/web-infra-dev/rslint/pull/2027) |
| prefer-importing-rstest-globals | βœ… | Merged [#2029](https://github.com/web-infra-dev/rslint/pull/2029) |
| prefer-rs-mocked | βœ… | Merged [#2030](https://github.com/web-infra-dev/rslint/pull/2030) |

[^no-alias-methods]: Jest deprecated these aliases in Jest 26 and [removed them in Jest 30](https://jestjs.io/docs/upgrading-to-jest30#removal-of-alias-matcher-functions). Vitest still supports them and keeps [`no-alias-methods` outside its `recommended` config](https://github.com/vitest-dev/eslint-plugin-vitest/blob/22d672abafce8c036eb830edf753b0c20e303f7b/src/index.ts), so canonical naming is primarily an opt-in style preference there. Rstest follows Vitest because its `expect` implementation is based on `@vitest/expect`.

[^no-large-snapshots]: Rslint's input pipeline only supports JavaScript and TypeScript file extensions, so it cannot lint external `.snap` files as required by this rule.

[^vi-namespace]: These rules are all defined in terms of the `vi` object or the `vitest` module specifier, neither of which exists in Rstest β€” the equivalent utilities are exported as `rstest` / `rs` and are also reachable through `import.meta.rstest`. So they cannot be ported under the same name. Where the underlying idea still applies, it belongs to a separately named Rstest rule (for example `no-restricted-rstest-methods`, `prefer-rs-mocked`), not to a port of the Vitest rule.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.