Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v27.9.0
Choose a base ref
...
head repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v28.0.0
Choose a head ref

Commits on Feb 16, 2024

  1. test: don't use hardcoded version (#1507)

    G-Rath authored Feb 16, 2024
    Copy the full SHA
    4c7683c View commit details

Commits on Feb 19, 2024

  1. chore(deps): lock file maintenance

    renovate[bot] committed Feb 19, 2024
    Copy the full SHA
    3ef8b3b View commit details
  2. Copy the full SHA
    a5ca480 View commit details

Commits on Feb 26, 2024

  1. chore(deps): lock file maintenance

    renovate[bot] committed Feb 26, 2024
    Copy the full SHA
    c8e6c69 View commit details
  2. chore(deps): lock file maintenance

    renovate[bot] committed Feb 26, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    517760a View commit details

Commits on Feb 29, 2024

  1. chore(deps): update dependency semantic-release to v23 (#1488)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Feb 29, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    80b18d3 View commit details

Commits on Mar 4, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2290c12 View commit details

Commits on Mar 6, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5dc84c1 View commit details
  2. chore(deps): update yarn to v3.8.1 (#1521)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 6, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    34b9696 View commit details

Commits on Mar 11, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fa92425 View commit details

Commits on Mar 14, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    deb5ece View commit details

Commits on Mar 18, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f887b4c View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    cf29a1f View commit details

Commits on Mar 19, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    156bcdc View commit details
  2. chore: update husky (#1526)

    SimenB authored Mar 19, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e212f5e View commit details

Commits on Mar 21, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ff16ef2 View commit details
  2. feat: remove no-if rule (#1528)

    BREAKING CHANGE: removed `no-if` in favor of `no-conditional-in-test`
    G-Rath authored Mar 21, 2024
    Copy the full SHA
    f976fc8 View commit details
  3. chore(release): 28.0.0-next.1 [skip ci]

    # [28.0.0-next.1](v27.9.0...v28.0.0-next.1) (2024-03-21)
    
    ### Features
    
    * remove `no-if` rule ([#1528](#1528)) ([f976fc8](f976fc8))
    
    ### BREAKING CHANGES
    
    * removed `no-if` in favor of `no-conditional-in-test`
    semantic-release-bot committed Mar 21, 2024
    Copy the full SHA
    732c71b View commit details
  4. feat: drop support for Node v14 (#1527)

    BREAKING CHANGE: dropped support for Node v14
    G-Rath authored Mar 21, 2024
    Copy the full SHA
    df5e580 View commit details
  5. chore(release): 28.0.0-next.2 [skip ci]

    # [28.0.0-next.2](v28.0.0-next.1...v28.0.0-next.2) (2024-03-21)
    
    ### Features
    
    * drop support for Node v14 ([#1527](#1527)) ([df5e580](df5e580))
    
    ### BREAKING CHANGES
    
    * dropped support for Node v14
    semantic-release-bot committed Mar 21, 2024
    Copy the full SHA
    c439b48 View commit details

Commits on Mar 22, 2024

  1. Copy the full SHA
    8408db9 View commit details
  2. feat: upgrade @typescript-eslint/utils to v6 (#1508)

    * feat: upgrade to `@typescript-eslint/utils` v6
    
    * chore: remove invalid module declarations
    
    * fix: update `docs` meta property on rules
    
    * chore: cast `context.settings` for now
    
    * refactor: update deprecated method calls
    
    * fix: update types for `JSONSchema4`
    
    * test(unbound-method): update cases and structure
    
    * test(unbound-method): use `TSESLint.RuleTester`
    
    * test(unbound-method): include filename for invalid cases
    
    * test(unbound-method): don't run broken test when using `@typescript-eslint` v5
    
    * fix: address deprecation warning
    G-Rath authored Mar 22, 2024
    Copy the full SHA
    dc6e8cd View commit details
  3. chore(release): 28.0.0-next.3 [skip ci]

    # [28.0.0-next.3](v28.0.0-next.2...v28.0.0-next.3) (2024-03-22)
    
    ### Features
    
    * upgrade `@typescript-eslint/utils` to v6 ([#1508](#1508)) ([dc6e8cd](dc6e8cd))
    semantic-release-bot committed Mar 22, 2024
    Copy the full SHA
    9899ddf View commit details

Commits on Mar 23, 2024

  1. feat: drop support for @typescript-eslint/eslint-plugin v5 (#1530)

    BREAKING CHANGE: dropped support for `@typescript-eslint/eslint-plugin` v5
    G-Rath authored Mar 23, 2024
    Copy the full SHA
    150e355 View commit details
  2. chore(release): 28.0.0-next.4 [skip ci]

    # [28.0.0-next.4](v28.0.0-next.3...v28.0.0-next.4) (2024-03-23)
    
    ### Features
    
    * drop support for `@typescript-eslint/eslint-plugin` v5 ([#1530](#1530)) ([150e355](150e355))
    
    ### BREAKING CHANGES
    
    * dropped support for `@typescript-eslint/eslint-plugin` v5
    semantic-release-bot committed Mar 23, 2024
    Copy the full SHA
    4d6f79a View commit details

Commits on Mar 24, 2024

  1. Copy the full SHA
    d362581 View commit details
  2. Copy the full SHA
    0297a7a View commit details
  3. Copy the full SHA
    a61b12d View commit details

Commits on Mar 25, 2024

  1. Copy the full SHA
    0138106 View commit details

Commits on Mar 27, 2024

  1. feat: remove snapshot processor and flat/snapshot config (#1532)

    BREAKING CHANGE: removed unneeded `snapshot` processor and `flat/snapshot` config
    G-Rath authored Mar 27, 2024
    Copy the full SHA
    98087f9 View commit details
  2. chore(release): 28.0.0-next.5 [skip ci]

    # [28.0.0-next.5](v28.0.0-next.4...v28.0.0-next.5) (2024-03-27)
    
    ### Features
    
    * remove `snapshot` processor and `flat/snapshot` config ([#1532](#1532)) ([98087f9](98087f9))
    
    ### BREAKING CHANGES
    
    * removed unneeded `snapshot` processor and `flat/snapshot` config
    semantic-release-bot committed Mar 27, 2024
    Copy the full SHA
    201b6e9 View commit details
  3. Copy the full SHA
    fb800db View commit details

Commits on Mar 29, 2024

  1. test(prefer-comparison-matcher): update names and remove duplicates (#…

    …1540)
    
    * test(prefer-comparison-matcher): update test names
    
    * test(prefer-comparison-matcher): deduplicate examples
    G-Rath authored Mar 29, 2024
    Copy the full SHA
    8bba541 View commit details
  2. Copy the full SHA
    295120e View commit details
  3. Copy the full SHA
    af4a9c9 View commit details
  4. chore(release): 28.0.0-next.6 [skip ci]

    # [28.0.0-next.6](v28.0.0-next.5...v28.0.0-next.6) (2024-03-29)
    
    ### Bug Fixes
    
    * **no-large-snapshots:** avoid `instanceof RegExp` check for ESLint v9 compatibility ([#1542](#1542)) ([af4a9c9](af4a9c9))
    semantic-release-bot committed Mar 29, 2024
    Copy the full SHA
    7bc48aa View commit details

Commits on Mar 31, 2024

  1. ci: run against upcoming next major ESLint version (#1534)

    * ci: run against next ESLint
    
    * test: make util
    
    * test: use a class
    
    * test: use a class (2)
    
    * test: improve compat class
    
    * refactor: make `flatCompat` util private
    
    * test: get `linter#verify` cases passing
    
    * ci: skip lint project on eslint v9
    
    * test: ignore coverage in util class
    
    * chore: move Jest config into dedicated file
    
    * ci: handle skipping linting in Jest config
    
    * test: skip `unbound-method` when using `@typescript-eslint` v6
    
    * ci: skip ESLint v9 on Node v16
    
    * refactor: import `Config` from `jest` directly
    
    * refactor: address `@ts-expect-error`s
    
    * refactor: use a constant instead of a function
    G-Rath authored Mar 31, 2024
    Copy the full SHA
    59d642c View commit details

Commits on Apr 1, 2024

  1. Copy the full SHA
    a193e1b View commit details

Commits on Apr 6, 2024

  1. Merge branch 'main' into next

    SimenB committed Apr 6, 2024
    Copy the full SHA
    cff726c View commit details
  2. Copy the full SHA
    3c5e167 View commit details
  3. fix: drop support for Node 19 (#1548)

    BREAKING CHANGE: Node v19 is no longer supported
    SimenB authored Apr 6, 2024
    Copy the full SHA
    c87e388 View commit details
  4. chore(release): 28.0.0-next.7 [skip ci]

    # [28.0.0-next.7](v28.0.0-next.6...v28.0.0-next.7) (2024-04-06)
    
    ### Bug Fixes
    
    * allow ESLint 9 as peer dependency ([#1547](#1547)) ([3c5e167](3c5e167))
    * drop support for Node 19 ([#1548](#1548)) ([c87e388](c87e388))
    
    ### BREAKING CHANGES
    
    * Node v19 is no longer supported
    semantic-release-bot committed Apr 6, 2024
    Copy the full SHA
    37f1d69 View commit details
  5. chore(deps): update wagoid/commitlint-github-action action to v6 (#1539)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Apr 6, 2024
    Copy the full SHA
    9854767 View commit details
  6. Merge pull request #1531 from jest-community/next

    Next major
    SimenB authored Apr 6, 2024
    Copy the full SHA
    7ecbae2 View commit details
  7. chore(release): 28.0.0 [skip ci]

    # [28.0.0](v27.9.0...v28.0.0) (2024-04-06)
    
    ### Bug Fixes
    
    * allow ESLint 9 as peer dependency ([#1547](#1547)) ([3c5e167](3c5e167))
    * drop support for Node 19 ([#1548](#1548)) ([c87e388](c87e388))
    * **no-large-snapshots:** avoid `instanceof RegExp` check for ESLint v9 compatibility ([#1542](#1542)) ([af4a9c9](af4a9c9))
    
    ### Features
    
    * drop support for `@typescript-eslint/eslint-plugin` v5 ([#1530](#1530)) ([150e355](150e355))
    * drop support for Node v14 ([#1527](#1527)) ([df5e580](df5e580))
    * remove `no-if` rule ([#1528](#1528)) ([f976fc8](f976fc8))
    * remove `snapshot` processor and `flat/snapshot` config ([#1532](#1532)) ([98087f9](98087f9))
    * upgrade `@typescript-eslint/utils` to v6 ([#1508](#1508)) ([dc6e8cd](dc6e8cd))
    
    ### BREAKING CHANGES
    
    * Node v19 is no longer supported
    * removed unneeded `snapshot` processor and `flat/snapshot` config
    * dropped support for `@typescript-eslint/eslint-plugin` v5
    * dropped support for Node v14
    * removed `no-if` in favor of `no-conditional-in-test`
    semantic-release-bot committed Apr 6, 2024
    Copy the full SHA
    5bc0b88 View commit details
Showing with 4,050 additions and 3,299 deletions.
  1. +1 −1 .eslintrc.js
  2. +1 −1 .github/workflows/lint.yml
  3. +7 −13 .github/workflows/nodejs.yml
  4. +0 −1 .husky/commit-msg
  5. +0 −1 .husky/pre-commit
  6. +30 −0 .yarn/patches/@typescript-eslint-typescript-estree-npm-5.62.0-5d1ea132a9.patch
  7. +172 −172 .yarn/releases/{yarn-3.8.0.cjs → yarn-3.8.1.cjs}
  8. +1 −1 .yarnrc.yml
  9. +102 −0 CHANGELOG.md
  10. +59 −90 README.md
  11. +1 −1 docs/rules/no-done-callback.md
  12. +1 −1 docs/rules/no-focused-tests.md
  13. +0 −58 docs/rules/no-if.md
  14. +1 −1 docs/rules/prefer-equality-matcher.md
  15. +1 −1 docs/rules/prefer-expect-assertions.md
  16. +1 −1 docs/rules/prefer-strict-equal.md
  17. +3 −3 docs/rules/unbound-method.md
  18. +58 −0 jest.config.ts
  19. +14 −44 package.json
  20. +3 −17 src/__tests__/__snapshots__/rules.test.ts.snap
  21. +5 −10 src/__tests__/rules.test.ts
  22. +32 −67 src/index.ts
  23. +0 −55 src/processors/__tests__/snapshot-processor.test.ts
  24. +0 −15 src/processors/snapshot-processor.ts
  25. +2 −3 src/rules/__tests__/consistent-test-it.test.ts
  26. +3 −3 src/rules/__tests__/expect-expect.test.ts
  27. +2 −3 src/rules/__tests__/max-expects.test.ts
  28. +2 −3 src/rules/__tests__/max-nested-describe.test.ts
  29. +2 −2 src/rules/__tests__/no-alias-methods.test.ts
  30. +2 −3 src/rules/__tests__/no-commented-out-tests.test.ts
  31. +2 −3 src/rules/__tests__/no-conditional-expect.test.ts
  32. +2 −3 src/rules/__tests__/no-conditional-in-test.test.ts
  33. +2 −3 src/rules/__tests__/no-confusing-set-timeout.test.ts
  34. +28 −17 src/rules/__tests__/no-deprecated-functions.test.ts
  35. +2 −3 src/rules/__tests__/no-disabled-tests.test.ts
  36. +18 −3 src/rules/__tests__/no-done-callback.test.ts
  37. +2 −3 src/rules/__tests__/no-duplicate-hooks.test.ts
  38. +2 −3 src/rules/__tests__/no-export.test.ts
  39. +2 −3 src/rules/__tests__/no-focused-tests.test.ts
  40. +2 −3 src/rules/__tests__/no-hooks.test.ts
  41. +2 −3 src/rules/__tests__/no-identical-title.test.ts
  42. +0 −866 src/rules/__tests__/no-if.test.ts
  43. +2 −3 src/rules/__tests__/no-interpolation-in-snapshots.test.ts
  44. +2 −2 src/rules/__tests__/no-jasmine-globals.test.ts
  45. +34 −2 src/rules/__tests__/no-large-snapshots.test.ts
  46. +2 −3 src/rules/__tests__/no-mocks-import.test.ts
  47. +2 −3 src/rules/__tests__/no-restricted-jest-methods.test.ts
  48. +2 −3 src/rules/__tests__/no-restricted-matchers.test.ts
  49. +2 −3 src/rules/__tests__/no-standalone-expect.test.ts
  50. +2 −2 src/rules/__tests__/no-test-prefixes.test.ts
  51. +2 −3 src/rules/__tests__/no-test-return-statement.test.ts
  52. +2 −2 src/rules/__tests__/no-untyped-mock-factory.test.ts
  53. +2 −2 src/rules/__tests__/prefer-called-with.test.ts
  54. +31 −47 src/rules/__tests__/prefer-comparison-matcher.test.ts
  55. +2 −3 src/rules/__tests__/prefer-each.test.ts
  56. +3 −3 src/rules/__tests__/prefer-equality-matcher.test.ts
  57. +1,370 −21 src/rules/__tests__/prefer-expect-assertions.test.ts
  58. +2 −3 src/rules/__tests__/prefer-expect-resolves.test.ts
  59. +2 −3 src/rules/__tests__/prefer-hooks-in-order.test.ts
  60. +2 −3 src/rules/__tests__/prefer-hooks-on-top.test.ts
  61. +2 −3 src/rules/__tests__/prefer-lowercase-title.test.ts
  62. +2 −3 src/rules/__tests__/prefer-mock-promise-shorthand.test.ts
  63. +2 −3 src/rules/__tests__/prefer-snapshot-hint.test.ts
  64. +3 −3 src/rules/__tests__/prefer-spy-on.test.ts
  65. +2 −2 src/rules/__tests__/prefer-strict-equal.test.ts
  66. +3 −4 src/rules/__tests__/prefer-to-be.test.ts
  67. +3 −4 src/rules/__tests__/prefer-to-contain.test.ts
  68. +2 −3 src/rules/__tests__/prefer-to-have-length.test.ts
  69. +2 −3 src/rules/__tests__/prefer-todo.test.ts
  70. +3 −4 src/rules/__tests__/require-hook.test.ts
  71. +2 −3 src/rules/__tests__/require-to-throw-message.test.ts
  72. +2 −3 src/rules/__tests__/require-top-level-describe.test.ts
  73. +77 −0 src/rules/__tests__/test-utils.ts
  74. +90 −12 src/rules/__tests__/unbound-method.test.ts
  75. +2 −3 src/rules/__tests__/valid-describe-callback.test.ts
  76. +2 −3 src/rules/__tests__/valid-expect-in-promise.test.ts
  77. +2 −3 src/rules/__tests__/valid-expect.test.ts
  78. +2 −3 src/rules/__tests__/valid-title.test.ts
  79. +2 −2 src/rules/consistent-test-it.ts
  80. +0 −2 src/rules/expect-expect.ts
  81. +0 −2 src/rules/max-expects.ts
  82. +0 −2 src/rules/max-nested-describe.ts
  83. +0 −2 src/rules/no-alias-methods.ts
  84. +0 −2 src/rules/no-commented-out-tests.ts
  85. +0 −2 src/rules/no-conditional-expect.ts
  86. +0 −2 src/rules/no-conditional-in-test.ts
  87. +0 −2 src/rules/no-confusing-set-timeout.ts
  88. +0 −2 src/rules/no-deprecated-functions.ts
  89. +0 −2 src/rules/no-disabled-tests.ts
  90. +2 −3 src/rules/no-done-callback.ts
  91. +0 −2 src/rules/no-duplicate-hooks.ts
  92. +0 −2 src/rules/no-export.ts
  93. +0 −2 src/rules/no-focused-tests.ts
  94. +1 −2 src/rules/no-hooks.ts
  95. +0 −2 src/rules/no-identical-title.ts
  96. +0 −121 src/rules/no-if.ts
  97. +0 −2 src/rules/no-interpolation-in-snapshots.ts
  98. +0 −2 src/rules/no-jasmine-globals.ts
  99. +4 −6 src/rules/no-large-snapshots.ts
  100. +0 −2 src/rules/no-mocks-import.ts
  101. +0 −2 src/rules/no-restricted-jest-methods.ts
  102. +0 −2 src/rules/no-restricted-matchers.ts
  103. +1 −2 src/rules/no-standalone-expect.ts
  104. +0 −2 src/rules/no-test-prefixes.ts
  105. +0 −2 src/rules/no-test-return-statement.ts
  106. +2 −4 src/rules/no-untyped-mock-factory.ts
  107. +0 −2 src/rules/prefer-called-with.ts
  108. +0 −2 src/rules/prefer-comparison-matcher.ts
  109. +0 −2 src/rules/prefer-each.ts
  110. +0 −2 src/rules/prefer-equality-matcher.ts
  111. +0 −2 src/rules/prefer-expect-assertions.ts
  112. +0 −2 src/rules/prefer-expect-resolves.ts
  113. +0 −2 src/rules/prefer-hooks-in-order.ts
  114. +0 −2 src/rules/prefer-hooks-on-top.ts
  115. +4 −3 src/rules/prefer-lowercase-title.ts
  116. +0 −2 src/rules/prefer-mock-promise-shorthand.ts
  117. +0 −2 src/rules/prefer-snapshot-hint.ts
  118. +0 −2 src/rules/prefer-spy-on.ts
  119. +0 −2 src/rules/prefer-strict-equal.ts
  120. +0 −2 src/rules/prefer-to-be.ts
  121. +0 −2 src/rules/prefer-to-contain.ts
  122. +0 −2 src/rules/prefer-to-have-length.ts
  123. +0 −2 src/rules/prefer-todo.ts
  124. +0 −2 src/rules/require-hook.ts
  125. +0 −2 src/rules/require-to-throw-message.ts
  126. +0 −2 src/rules/require-top-level-describe.ts
  127. +2 −2 src/rules/unbound-method.ts
  128. +3 −5 src/rules/utils/__tests__/parseJestFnCall.test.ts
  129. +15 −38 src/rules/utils/misc.ts
  130. +9 −8 src/rules/utils/parseJestFnCall.ts
  131. +0 −2 src/rules/valid-describe-callback.ts
  132. +0 −2 src/rules/valid-expect-in-promise.ts
  133. +0 −2 src/rules/valid-expect.ts
  134. +2 −3 src/rules/valid-title.ts
  135. +2 −4 tsconfig.json
  136. +1,762 −1,353 yarn.lock
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ module.exports = {
globals,
},
{
files: ['src/**/*', 'dangerfile.ts', 'tools/*'],
files: ['src/**/*', 'dangerfile.ts', 'tools/*', './jest.config.ts'],
parserOptions: {
sourceType: 'module',
},
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- uses: wagoid/commitlint-github-action@v5
- uses: wagoid/commitlint-github-action@v6
with:
configFile: './package.json'
env:
20 changes: 7 additions & 13 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -71,22 +71,16 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x, 18.x, 19.x, 20.x, 21.x]
eslint-version: [7, 8]
ts-eslint-plugin-version: [5, 6, 7]
node-version: [16.x, 18.x, 20.x, 21.x]
eslint-version: [7, 8, 9]
ts-eslint-plugin-version: [6, 7]
exclude:
# ts-eslint/plugin@6 doesn't support node@14
- node-version: 14.x
ts-eslint-plugin-version: 6
# ts-eslint/plugin@7 doesn't support node@14
- node-version: 14.x
ts-eslint-plugin-version: 7
# ts-eslint/plugin@7 doesn't support node@16
- node-version: 16.x
ts-eslint-plugin-version: 7
# ts-eslint/plugin@7 doesn't support node@19
- node-version: 19.x
ts-eslint-plugin-version: 7
# eslint@9 doesn't support node@16
- node-version: 16.x
eslint-version: 9
# ts-eslint/plugin@7 doesn't support eslint@7
- eslint-version: 7
ts-eslint-plugin-version: 7
@@ -109,7 +103,7 @@ jobs:
yarn add --dev eslint@${{ matrix.eslint-version }} @typescript-eslint/eslint-plugin@${{ matrix.ts-eslint-plugin-version }} @typescript-eslint/parser@${{ matrix.ts-eslint-plugin-version }}
- name: run tests
# only collect coverage on eslint versions that support dynamic import
run: yarn test --coverage ${{ matrix.eslint-version >= 8 }}
run: yarn test --coverage ${{ matrix.eslint-version == 8 }}
env:
CI: true
- uses: codecov/codecov-action@v3
1 change: 0 additions & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --edit $1
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/_ts3.4/dist/ts-estree/ts-nodes.d.ts b/_ts3.4/dist/ts-estree/ts-nodes.d.ts
index 2021725e0371bc028330cee33e90021f08e12275..5d19dfc6fc8272fa065edba11e1d6fb5f4ca3cf7 100644
--- a/_ts3.4/dist/ts-estree/ts-nodes.d.ts
+++ b/_ts3.4/dist/ts-estree/ts-nodes.d.ts
@@ -8,10 +8,6 @@ declare module 'typescript' {
}
interface ClassStaticBlockDeclaration extends ts.Node {
}
- interface AssertClause extends ts.Node {
- }
- interface AssertEntry extends ts.Node {
- }
interface SatisfiesExpression extends ts.Node {
}
}
diff --git a/dist/ts-estree/ts-nodes.d.ts b/dist/ts-estree/ts-nodes.d.ts
index 1a90a38bf617eedfb7d9c0dbd431429480dd83ca..1ef85da052c3715a492ead81e4ada50697a15d78 100644
--- a/dist/ts-estree/ts-nodes.d.ts
+++ b/dist/ts-estree/ts-nodes.d.ts
@@ -8,10 +8,6 @@ declare module 'typescript' {
}
interface ClassStaticBlockDeclaration extends ts.Node {
}
- interface AssertClause extends ts.Node {
- }
- interface AssertEntry extends ts.Node {
- }
interface SatisfiesExpression extends ts.Node {
}
}
344 changes: 172 additions & 172 deletions .yarn/releases/yarn-3.8.0.cjs → .yarn/releases/yarn-3.8.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -6,4 +6,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'

yarnPath: .yarn/releases/yarn-3.8.0.cjs
yarnPath: .yarn/releases/yarn-3.8.1.cjs
102 changes: 102 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,105 @@
# [28.0.0](https://github.com/jest-community/eslint-plugin-jest/compare/v27.9.0...v28.0.0) (2024-04-06)


### Bug Fixes

* allow ESLint 9 as peer dependency ([#1547](https://github.com/jest-community/eslint-plugin-jest/issues/1547)) ([3c5e167](https://github.com/jest-community/eslint-plugin-jest/commit/3c5e1673afd02dc2c9b90d259c0452326715ae6c))
* drop support for Node 19 ([#1548](https://github.com/jest-community/eslint-plugin-jest/issues/1548)) ([c87e388](https://github.com/jest-community/eslint-plugin-jest/commit/c87e3887e736c40d1460af9cdbdffe30f79fdaea))
* **no-large-snapshots:** avoid `instanceof RegExp` check for ESLint v9 compatibility ([#1542](https://github.com/jest-community/eslint-plugin-jest/issues/1542)) ([af4a9c9](https://github.com/jest-community/eslint-plugin-jest/commit/af4a9c94d624b5db4643c994f5bec96b0cb889b8))


### Features

* drop support for `@typescript-eslint/eslint-plugin` v5 ([#1530](https://github.com/jest-community/eslint-plugin-jest/issues/1530)) ([150e355](https://github.com/jest-community/eslint-plugin-jest/commit/150e3558a637b49ddd76d362f88332b30f78dc5c))
* drop support for Node v14 ([#1527](https://github.com/jest-community/eslint-plugin-jest/issues/1527)) ([df5e580](https://github.com/jest-community/eslint-plugin-jest/commit/df5e58081d1bd15fbed8bd22f6c03d5f350d73b6))
* remove `no-if` rule ([#1528](https://github.com/jest-community/eslint-plugin-jest/issues/1528)) ([f976fc8](https://github.com/jest-community/eslint-plugin-jest/commit/f976fc8c71fc5e9f55cd5ae09092f15ee277fd2c))
* remove `snapshot` processor and `flat/snapshot` config ([#1532](https://github.com/jest-community/eslint-plugin-jest/issues/1532)) ([98087f9](https://github.com/jest-community/eslint-plugin-jest/commit/98087f9bb27082f9fbda59a56c65536fb9d8a0dc))
* upgrade `@typescript-eslint/utils` to v6 ([#1508](https://github.com/jest-community/eslint-plugin-jest/issues/1508)) ([dc6e8cd](https://github.com/jest-community/eslint-plugin-jest/commit/dc6e8cd249817de585b50e473c2146e1542dd146))


### BREAKING CHANGES

* Node v19 is no longer supported
* removed unneeded `snapshot` processor and `flat/snapshot` config
* dropped support for `@typescript-eslint/eslint-plugin` v5
* dropped support for Node v14
* removed `no-if` in favor of `no-conditional-in-test`

# [28.0.0-next.7](https://github.com/jest-community/eslint-plugin-jest/compare/v28.0.0-next.6...v28.0.0-next.7) (2024-04-06)


### Bug Fixes

* allow ESLint 9 as peer dependency ([#1547](https://github.com/jest-community/eslint-plugin-jest/issues/1547)) ([3c5e167](https://github.com/jest-community/eslint-plugin-jest/commit/3c5e1673afd02dc2c9b90d259c0452326715ae6c))
* drop support for Node 19 ([#1548](https://github.com/jest-community/eslint-plugin-jest/issues/1548)) ([c87e388](https://github.com/jest-community/eslint-plugin-jest/commit/c87e3887e736c40d1460af9cdbdffe30f79fdaea))


### BREAKING CHANGES

* Node v19 is no longer supported

# [28.0.0-next.6](https://github.com/jest-community/eslint-plugin-jest/compare/v28.0.0-next.5...v28.0.0-next.6) (2024-03-29)


### Bug Fixes

* **no-large-snapshots:** avoid `instanceof RegExp` check for ESLint v9 compatibility ([#1542](https://github.com/jest-community/eslint-plugin-jest/issues/1542)) ([af4a9c9](https://github.com/jest-community/eslint-plugin-jest/commit/af4a9c94d624b5db4643c994f5bec96b0cb889b8))

# [28.0.0-next.5](https://github.com/jest-community/eslint-plugin-jest/compare/v28.0.0-next.4...v28.0.0-next.5) (2024-03-27)


### Features

* remove `snapshot` processor and `flat/snapshot` config ([#1532](https://github.com/jest-community/eslint-plugin-jest/issues/1532)) ([98087f9](https://github.com/jest-community/eslint-plugin-jest/commit/98087f9bb27082f9fbda59a56c65536fb9d8a0dc))


### BREAKING CHANGES

* removed unneeded `snapshot` processor and `flat/snapshot` config

# [28.0.0-next.4](https://github.com/jest-community/eslint-plugin-jest/compare/v28.0.0-next.3...v28.0.0-next.4) (2024-03-23)


### Features

* drop support for `@typescript-eslint/eslint-plugin` v5 ([#1530](https://github.com/jest-community/eslint-plugin-jest/issues/1530)) ([150e355](https://github.com/jest-community/eslint-plugin-jest/commit/150e3558a637b49ddd76d362f88332b30f78dc5c))


### BREAKING CHANGES

* dropped support for `@typescript-eslint/eslint-plugin` v5

# [28.0.0-next.3](https://github.com/jest-community/eslint-plugin-jest/compare/v28.0.0-next.2...v28.0.0-next.3) (2024-03-22)


### Features

* upgrade `@typescript-eslint/utils` to v6 ([#1508](https://github.com/jest-community/eslint-plugin-jest/issues/1508)) ([dc6e8cd](https://github.com/jest-community/eslint-plugin-jest/commit/dc6e8cd249817de585b50e473c2146e1542dd146))

# [28.0.0-next.2](https://github.com/jest-community/eslint-plugin-jest/compare/v28.0.0-next.1...v28.0.0-next.2) (2024-03-21)


### Features

* drop support for Node v14 ([#1527](https://github.com/jest-community/eslint-plugin-jest/issues/1527)) ([df5e580](https://github.com/jest-community/eslint-plugin-jest/commit/df5e58081d1bd15fbed8bd22f6c03d5f350d73b6))


### BREAKING CHANGES

* dropped support for Node v14

# [28.0.0-next.1](https://github.com/jest-community/eslint-plugin-jest/compare/v27.9.0...v28.0.0-next.1) (2024-03-21)


### Features

* remove `no-if` rule ([#1528](https://github.com/jest-community/eslint-plugin-jest/issues/1528)) ([f976fc8](https://github.com/jest-community/eslint-plugin-jest/commit/f976fc8c71fc5e9f55cd5ae09092f15ee277fd2c))


### BREAKING CHANGES

* removed `no-if` in favor of `no-conditional-in-test`

# [27.9.0](https://github.com/jest-community/eslint-plugin-jest/compare/v27.8.0...v27.9.0) (2024-02-16)


149 changes: 59 additions & 90 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/rules/no-done-callback.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).

💡 This rule is manually fixable by
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
[editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->

2 changes: 1 addition & 1 deletion docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
[config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).

💡 This rule is manually fixable by
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
[editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->

58 changes: 0 additions & 58 deletions docs/rules/no-if.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/rules/prefer-equality-matcher.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Suggest using the built-in equality matchers (`prefer-equality-matcher`)

💡 This rule is manually fixable by
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
[editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->

2 changes: 1 addition & 1 deletion docs/rules/prefer-expect-assertions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Suggest using `expect.assertions()` OR `expect.hasAssertions()` (`prefer-expect-assertions`)

💡 This rule is manually fixable by
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
[editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->

2 changes: 1 addition & 1 deletion docs/rules/prefer-strict-equal.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Suggest using `toStrictEqual()` (`prefer-strict-equal`)

💡 This rule is manually fixable by
[editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
[editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

<!-- end auto-generated rule header -->

6 changes: 3 additions & 3 deletions docs/rules/unbound-method.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Enforce unbound methods are called with their expected scope (`unbound-method`)

💭 This rule requires type information.
💭 This rule requires
[type information](https://typescript-eslint.io/linting/typed-linting).

<!-- end auto-generated rule header -->

@@ -55,5 +56,4 @@ See [`@typescript-eslint/unbound-method`][original-rule] options (e.g.

<sup>Taken with ❤️ [from `@typescript-eslint` core][original-rule]</sup>

[original-rule]:
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md
[original-rule]: https://typescript-eslint.io/rules/unbound-method
58 changes: 58 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { version as typescriptESLintPluginVersion } from '@typescript-eslint/eslint-plugin/package.json';
import { version as eslintVersion } from 'eslint/package.json';
import type { Config } from 'jest';
import * as semver from 'semver';

const config = {
clearMocks: true,
restoreMocks: true,
resetMocks: true,

coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},

projects: [
{
displayName: 'test',
testPathIgnorePatterns: [
'<rootDir>/lib/.*',
'<rootDir>/src/rules/__tests__/fixtures/*',
'<rootDir>/src/rules/__tests__/test-utils.ts',
],
coveragePathIgnorePatterns: ['/node_modules/'],
},
{
displayName: 'lint',
runner: 'jest-runner-eslint',
testMatch: ['<rootDir>/**/*.{js,ts}'],
testPathIgnorePatterns: ['<rootDir>/lib/.*'],
coveragePathIgnorePatterns: ['/node_modules/'],
},
],
} satisfies Config;

if (semver.major(eslintVersion) >= 9) {
config.projects = config.projects.filter(
({ displayName }) => displayName !== 'lint',
);

// jest/unbound-method doesn't work when using @typescript-eslint v6
if (semver.major(typescriptESLintPluginVersion) === 6) {
for (const project of config.projects) {
project.testPathIgnorePatterns.push(
'<rootDir>/src/rules/__tests__/unbound-method.test.ts',
);
project.coveragePathIgnorePatterns.push(
'<rootDir>/src/rules/unbound-method.ts',
);
}
}
}

export default config;
58 changes: 14 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-jest",
"version": "27.9.0",
"version": "28.0.0",
"description": "ESLint rules for Jest",
"keywords": [
"eslint",
@@ -21,7 +21,7 @@
],
"scripts": {
"build": "babel --extensions .js,.ts src --out-dir lib --copy-files && rimraf --glob lib/__tests__ 'lib/**/__tests__'",
"postinstall": "is-ci || husky install",
"postinstall": "is-ci || husky",
"lint": "eslint . --ignore-pattern '!.eslintrc.js' --ext js,ts",
"prepack": "rimraf lib && yarn build",
"prepublishOnly": "pinst --disable",
@@ -64,38 +64,8 @@
"@semantic-release/github"
]
},
"jest": {
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"projects": [
{
"displayName": "test",
"testPathIgnorePatterns": [
"<rootDir>/lib/.*",
"<rootDir>/src/rules/__tests__/fixtures/*",
"<rootDir>/src/rules/__tests__/test-utils.ts"
]
},
{
"displayName": "lint",
"runner": "jest-runner-eslint",
"testMatch": [
"<rootDir>/**/*.{js,ts}"
],
"testPathIgnorePatterns": [
"<rootDir>/lib/.*"
]
}
]
},
"dependencies": {
"@typescript-eslint/utils": "^5.10.0"
"@typescript-eslint/utils": "^6.0.0"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
@@ -107,16 +77,16 @@
"@schemastore/package": "^0.0.10",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/git": "^10.0.0",
"@tsconfig/node14": "^14.1.0",
"@tsconfig/node16": "^16.0.0",
"@types/eslint": "^8.4.6",
"@types/jest": "^29.0.0",
"@types/node": "^14.18.26",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"babel-jest": "^29.0.0",
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
"dedent": "^1.5.0",
"eslint": "^7.0.0 || ^8.0.0",
"eslint": "^7.0.0 || ^8.0.0 || ^9.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-doc-generator": "^1.0.0",
"eslint-plugin-eslint-comments": "^3.1.2",
@@ -126,7 +96,7 @@
"eslint-plugin-prettier": "^5.0.0",
"eslint-remote-tester": "^3.0.0",
"eslint-remote-tester-repositories": "~1.0.0",
"husky": "^8.0.1",
"husky": "^9.0.1",
"is-ci": "^3.0.0",
"jest": "^29.0.0",
"jest-runner-eslint": "^2.0.0",
@@ -135,15 +105,15 @@
"pinst": "^3.0.0",
"prettier": "^3.0.0",
"rimraf": "^5.0.0",
"semantic-release": "^22.0.0",
"semantic-release": "^23.0.0",
"semver": "^7.3.5",
"strip-ansi": "^6.0.0",
"ts-node": "^10.2.1",
"typescript": "^5.0.4"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0 || ^6.0.0 || ^7.0.0",
"eslint": "^7.0.0 || ^8.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0",
"eslint": "^7.0.0 || ^8.0.0 || ^9.0.0",
"jest": "*"
},
"peerDependenciesMeta": {
@@ -154,14 +124,14 @@
"optional": true
}
},
"packageManager": "yarn@3.8.0",
"packageManager": "yarn@3.8.1",
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
},
"publishConfig": {
"provenance": true
},
"resolutions": {
"typescript": "~5.2.2"
"@typescript-eslint/typescript-estree@5.62.0": "patch:@typescript-eslint/typescript-estree@npm:^5.62.0#./.yarn/patches/@typescript-eslint-typescript-estree-npm-5.62.0-5d1ea132a9.patch"
}
}
20 changes: 3 additions & 17 deletions src/__tests__/__snapshots__/rules.test.ts.snap
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest": ObjectContaining {
"meta": {
"name": "eslint-plugin-jest",
"version": "27.8.0",
"version": Any<String>,
},
},
},
@@ -167,7 +167,7 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest": ObjectContaining {
"meta": {
"name": "eslint-plugin-jest",
"version": "27.8.0",
"version": Any<String>,
},
},
},
@@ -193,20 +193,6 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest/valid-title": "error",
},
},
"flat/snapshots": {
"files": [
"**/*.snap",
],
"plugins": {
"jest": ObjectContaining {
"meta": {
"name": "eslint-plugin-jest",
"version": "27.8.0",
},
},
},
"processor": "jest/snapshots",
},
"flat/style": {
"languageOptions": {
"globals": {
@@ -229,7 +215,7 @@ exports[`rules should export configs that refer to actual rules 1`] = `
"jest": ObjectContaining {
"meta": {
"name": "eslint-plugin-jest",
"version": "27.8.0",
"version": Any<String>,
},
},
},
15 changes: 5 additions & 10 deletions src/__tests__/rules.test.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
import { resolve } from 'path';
import plugin from '../';

const numberOfRules = 53;
const numberOfRules = 52;
const ruleNames = Object.keys(plugin.rules);
const deprecatedRules = Object.entries(plugin.rules)
.filter(([, rule]) => rule.meta.deprecated)
@@ -51,7 +51,7 @@ describe('rules', () => {
const expectJestPlugin = expect.objectContaining({
meta: {
name: 'eslint-plugin-jest',
version: '27.8.0',
version: expect.any(String),
},
});

@@ -61,7 +61,6 @@ describe('rules', () => {
'flat/recommended': { plugins: { jest: expectJestPlugin } },
'flat/style': { plugins: { jest: expectJestPlugin } },
'flat/all': { plugins: { jest: expectJestPlugin } },
'flat/snapshots': { plugins: { jest: expectJestPlugin } },
});
expect(Object.keys(recommendedConfigs)).toEqual([
'all',
@@ -70,20 +69,16 @@ describe('rules', () => {
'flat/all',
'flat/recommended',
'flat/style',
'flat/snapshots',
]);
expect(Object.keys(recommendedConfigs.all.rules)).toHaveLength(
ruleNames.length - deprecatedRules.length,
);
expect(Object.keys(recommendedConfigs['flat/all'].rules)).toHaveLength(
ruleNames.length - deprecatedRules.length,
);
const allConfigRules = Object.values(recommendedConfigs)
.map(config => Object.keys(config.rules ?? {}))
.reduce((previousValue, currentValue) => [
...previousValue,
...currentValue,
]);
const allConfigRules = Object.values(recommendedConfigs).flatMap(config =>
Object.keys(config.rules ?? {}),
);

allConfigRules.forEach(rule => {
const ruleNamePrefix = 'jest/';
99 changes: 32 additions & 67 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
import { readdirSync } from 'fs';
import { join, parse } from 'path';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
import type { TSESLint } from '@typescript-eslint/utils';
import {
name as packageName,
version as packageVersion,
} from '../package.json';
import globals from './globals.json';
import * as snapshotProcessor from './processors/snapshot-processor';

type RuleModule = TSESLint.RuleModule<string, unknown[]> & {
meta: Required<Pick<TSESLint.RuleMetaData<string>, 'docs'>>;
};

// v5 of `@typescript-eslint/experimental-utils` removed this
declare module '@typescript-eslint/utils/dist/ts-eslint/Rule' {
export interface RuleMetaDataDocs {
category: 'Best Practices' | 'Possible Errors';
}
}

declare module '@typescript-eslint/utils/dist/ts-eslint/SourceCode' {
export interface SourceCode {
/**
* Returns the scope of the given node.
* This information can be used track references to variables.
* @since 8.37.0
*/
getScope(node: TSESTree.Node): TSESLint.Scope.Scope;
/**
* Returns an array of the ancestors of the given node, starting at
* the root of the AST and continuing through the direct parent of the current node.
* This array does not include the currently-traversed node itself.
* @since 8.38.0
*/
getAncestors(node: TSESTree.Node): TSESTree.Node[];
/**
* Returns a list of variables declared by the given node.
* This information can be used to track references to variables.
* @since 8.38.0
*/
getDeclaredVariables(
node: TSESTree.Node,
): readonly TSESLint.Scope.Variable[];
}
}

// copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
/* istanbul ignore next */
const interopRequireDefault = (obj: any): { default: any } =>
@@ -64,14 +30,34 @@ const rules = Object.fromEntries(
.map(rule => [rule, importDefault(join(rulesDir, rule)) as RuleModule]),
);

const recommendedRules = Object.fromEntries(
Object.entries(rules)
.filter(([, rule]) => rule.meta.docs.recommended)
.map(([name, rule]) => [
`jest/${name}`,
rule.meta.docs.recommended as TSESLint.Linter.RuleLevel,
]),
);
const recommendedRules = {
'jest/expect-expect': 'warn',
'jest/no-alias-methods': 'error',
'jest/no-commented-out-tests': 'warn',
'jest/no-conditional-expect': 'error',
'jest/no-deprecated-functions': 'error',
'jest/no-disabled-tests': 'warn',
'jest/no-done-callback': 'error',
'jest/no-export': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/no-interpolation-in-snapshots': 'error',
'jest/no-jasmine-globals': 'error',
'jest/no-mocks-import': 'error',
'jest/no-standalone-expect': 'error',
'jest/no-test-prefixes': 'error',
'jest/valid-describe-callback': 'error',
'jest/valid-expect': 'error',
'jest/valid-expect-in-promise': 'error',
'jest/valid-title': 'error',
} satisfies Record<string, TSESLint.Linter.RuleLevel>;

const styleRules = {
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
} satisfies Record<string, TSESLint.Linter.RuleLevel>;

const allRules = Object.fromEntries<TSESLint.Linter.RuleLevel>(
Object.entries(rules)
@@ -89,19 +75,14 @@ const plugin = {
| 'style'
| 'flat/all'
| 'flat/recommended'
| 'flat/style'
| 'flat/snapshots',
| 'flat/style',
Pick<Required<TSESLint.Linter.Config>, 'rules'>
>,
environments: {
globals: {
globals,
},
},
processors: {
snapshots: snapshotProcessor,
'.snap': snapshotProcessor,
},
rules,
};

@@ -122,26 +103,10 @@ const createFlatConfig = (
plugin.configs = {
all: createRCConfig(allRules),
recommended: createRCConfig(recommendedRules),
style: createRCConfig({
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
}),
style: createRCConfig(styleRules),
'flat/all': createFlatConfig(allRules),
'flat/recommended': createFlatConfig(recommendedRules),
'flat/style': createFlatConfig({
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be': 'error',
'jest/prefer-to-contain': 'error',
'jest/prefer-to-have-length': 'error',
}),
'flat/snapshots': {
// @ts-expect-error this is introduced in flat config
files: ['**/*.snap'],
plugins: { jest: plugin },
processor: 'jest/snapshots',
},
'flat/style': createFlatConfig(styleRules),
};

export = plugin;
55 changes: 0 additions & 55 deletions src/processors/__tests__/snapshot-processor.test.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/processors/snapshot-processor.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/rules/__tests__/consistent-test-it.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../consistent-test-it';
import { TestCaseName } from '../utils';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
6 changes: 3 additions & 3 deletions src/rules/__tests__/expect-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AST_NODE_TYPES, TSESLint } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../expect-expect';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/max-expects.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../max-expects';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/max-nested-describe.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../max-nested-describe';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
4 changes: 2 additions & 2 deletions src/rules/__tests__/no-alias-methods.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-alias-methods';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

ruleTester.run('no-alias-methods', rule, {
valid: [
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-commented-out-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-commented-out-tests';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-conditional-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-conditional-expect';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2019,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-conditional-in-test.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-conditional-in-test';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-confusing-set-timeout.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-confusing-set-timeout';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2020,
45 changes: 28 additions & 17 deletions src/rules/__tests__/no-deprecated-functions.test.ts
Original file line number Diff line number Diff line change
@@ -4,14 +4,15 @@ import {
type JestVersion,
detectJestVersion,
} from '../utils/detectJestVersion';
import { FlatCompatRuleTester, usingFlatConfig } from './test-utils';

jest.mock('../utils/detectJestVersion');

const detectJestVersionMock = detectJestVersion as jest.MockedFunction<
typeof detectJestVersion
>;

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

const generateValidCases = (
jestVersion: JestVersion | string | undefined,
@@ -120,30 +121,26 @@ describe('the rule', () => {
valid: [
'jest',
'require("fs")',
...allowedFunctions
.map(func => generateValidCases(jestVersion, func))
.reduce((acc, arr) => acc.concat(arr), []),
...allowedFunctions.flatMap(func =>
generateValidCases(jestVersion, func),
),
],
invalid: deprecations
.map(([, deprecation, replacement]) =>
generateInvalidCases(jestVersion, deprecation, replacement),
)
.reduce((acc, arr) => acc.concat(arr), []),
invalid: deprecations.flatMap(([, deprecation, replacement]) =>
generateInvalidCases(jestVersion, deprecation, replacement),
),
});

ruleTester.run('detected jest version', rule, {
valid: [
'jest',
'require("fs")',
...allowedFunctions
.map(func => generateValidCases(undefined, func))
.reduce((acc, arr) => acc.concat(arr), []),
...allowedFunctions.flatMap(func =>
generateValidCases(undefined, func),
),
],
invalid: deprecations
.map(([, deprecation, replacement]) =>
generateInvalidCases(undefined, deprecation, replacement),
)
.reduce((acc, arr) => acc.concat(arr), []),
invalid: deprecations.flatMap(([, deprecation, replacement]) =>
generateInvalidCases(undefined, deprecation, replacement),
),
});
});

@@ -158,6 +155,20 @@ describe('the rule', () => {
expect(() => {
const linter = new TSESLint.Linter();

/* istanbul ignore if */
if (usingFlatConfig) {
linter.verify('jest.resetModuleRegistry()', [
{
plugins: {
jest: { rules: { 'no-deprecated-functions': rule } },
},
rules: { 'jest/no-deprecated-functions': 'error' },
},
]);

return;
}

linter.defineRule('no-deprecated-functions', rule);

linter.verify('jest.resetModuleRegistry()', {
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-disabled-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-disabled-tests';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
21 changes: 18 additions & 3 deletions src/rules/__tests__/no-done-callback.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-done-callback';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
@@ -477,6 +476,14 @@ ruleTester.run('no-done-callback', rule, {
messageId: 'noDoneCallback',
line: 1,
column: 37,
suggestions: [
{
messageId: 'suggestWrappingInPromise',
data: { callback: 'done' },
output:
'test.each``("something", () => {return new Promise(done => { done(); })})',
},
],
},
],
},
@@ -487,6 +494,14 @@ ruleTester.run('no-done-callback', rule, {
messageId: 'noDoneCallback',
line: 1,
column: 35,
suggestions: [
{
messageId: 'suggestWrappingInPromise',
data: { callback: 'done' },
output:
'it.each``("something", () => {return new Promise(done => { done(); })})',
},
],
},
],
},
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-duplicate-hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-duplicate-hooks';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-export.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-export';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-focused-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-focused-tests';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 6,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-hooks';
import { HookName } from '../utils';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-identical-title.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-identical-title';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
866 changes: 0 additions & 866 deletions src/rules/__tests__/no-if.test.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/rules/__tests__/no-interpolation-in-snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-interpolation-in-snapshots';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
4 changes: 2 additions & 2 deletions src/rules/__tests__/no-jasmine-globals.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-jasmine-globals';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

ruleTester.run('no-jasmine-globals', rule, {
valid: [
36 changes: 34 additions & 2 deletions src/rules/__tests__/no-large-snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-large-snapshots';
import { espreeParser } from './test-utils';
import {
FlatCompatRuleTester,
espreeParser,
usingFlatConfig,
} from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
@@ -267,6 +271,34 @@ describe('no-large-snapshots', () => {
expect(() => {
const linter = new TSESLint.Linter();

/* istanbul ignore if */
if (usingFlatConfig) {
linter.verify(
'console.log()',
[
{
files: ['*.snap'],
plugins: {
jest: { rules: { 'no-large-snapshots': rule } },
},
rules: {
'jest/no-large-snapshots': [
'error',
{
allowedSnapshots: {
'mock-component.jsx.snap': [/a big component \d+/u],
},
},
],
},
},
],
'mock-component.jsx.snap',
);

return;
}

linter.defineRule('no-large-snapshots', rule);

linter.verify(
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-mocks-import.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-mocks-import';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-restricted-jest-methods.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-restricted-jest-methods';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-restricted-matchers.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-restricted-matchers';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-standalone-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-standalone-expect';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
4 changes: 2 additions & 2 deletions src/rules/__tests__/no-test-prefixes.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-test-prefixes';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

ruleTester.run('no-test-prefixes', rule, {
valid: [
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-test-return-statement.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-test-return-statement';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: { ecmaVersion: 2015 },
});
4 changes: 2 additions & 2 deletions src/rules/__tests__/no-untyped-mock-factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-untyped-mock-factory';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
});

4 changes: 2 additions & 2 deletions src/rules/__tests__/prefer-called-with.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../prefer-called-with';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

ruleTester.run('prefer-called-with', rule, {
valid: [
78 changes: 31 additions & 47 deletions src/rules/__tests__/prefer-comparison-matcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import type { TSESLint } from '@typescript-eslint/utils';
import rule from '../prefer-comparison-matcher';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
@@ -205,29 +205,23 @@ const generateValidStringLiteralCases = (operator: string, matcher: string) => {
['x', "'y'"],
['x', '`y`'],
['x', '`y${z}`'],
].reduce((cases, [a, b]) => [
...cases,
...[
`expect(${a} ${operator} ${b}).${matcher}(true)`,
`expect(${a} ${operator} ${b}).${matcher}(false)`,
`expect(${a} ${operator} ${b}).not.${matcher}(true)`,
`expect(${a} ${operator} ${b}).not.${matcher}(false)`,
`expect(${b} ${operator} ${a}).${matcher}(true)`,
`expect(${b} ${operator} ${a}).${matcher}(false)`,
`expect(${b} ${operator} ${a}).not.${matcher}(true)`,
`expect(${b} ${operator} ${a}).not.${matcher}(false)`,
`expect(${a} ${operator} ${b}).${matcher}(true)`,
`expect(${a} ${operator} ${b}).${matcher}(false)`,
`expect(${a} ${operator} ${b}).not.${matcher}(true)`,
`expect(${a} ${operator} ${b}).not.${matcher}(false)`,
`expect(${b} ${operator} ${a}).${matcher}(true)`,
`expect(${b} ${operator} ${a}).${matcher}(false)`,
`expect(${b} ${operator} ${a}).not.${matcher}(true)`,
`expect(${b} ${operator} ${a}).not.${matcher}(false)`,
`expect(${b} ${operator} ${b}).not.${matcher}(false)`,
`expect(${b} ${operator} ${b}).resolves.not.${matcher}(false)`,
`expect(${b} ${operator} ${b}).resolves.${matcher}(false)`,
],
].flatMap(([a, b]) => [
`expect(${a} ${operator} ${b}).${matcher}(true)`,
`expect(${a} ${operator} ${b}).${matcher}(false)`,
`expect(${a} ${operator} ${b}).not.${matcher}(true)`,
`expect(${a} ${operator} ${b}).not.${matcher}(false)`,
`expect(${a} ${operator} ${b}).resolves.${matcher}(true)`,
`expect(${a} ${operator} ${b}).resolves.${matcher}(false)`,
`expect(${a} ${operator} ${b}).resolves.not.${matcher}(true)`,
`expect(${a} ${operator} ${b}).resolves.not.${matcher}(false)`,
`expect(${b} ${operator} ${a}).resolves.not.${matcher}(false)`,
`expect(${b} ${operator} ${a}).resolves.not.${matcher}(true)`,
`expect(${b} ${operator} ${a}).resolves.${matcher}(false)`,
`expect(${b} ${operator} ${a}).resolves.${matcher}(true)`,
`expect(${b} ${operator} ${a}).not.${matcher}(false)`,
`expect(${b} ${operator} ${a}).not.${matcher}(true)`,
`expect(${b} ${operator} ${a}).${matcher}(false)`,
`expect(${b} ${operator} ${a}).${matcher}(true)`,
]);
};

@@ -236,35 +230,25 @@ const testComparisonOperator = (
preferredMatcher: string,
preferredMatcherWhenNegated: string,
) => {
ruleTester.run(`prefer-to-be-comparison: ${operator}`, rule, {
ruleTester.run(`prefer-comparison-matcher: ${operator}`, rule, {
valid: [
'expect()',
'expect({}).toStrictEqual({})',
`expect(value).${preferredMatcher}(1);`,
`expect(value).${preferredMatcherWhenNegated}(1);`,
`expect(value).not.${preferredMatcher}(1);`,
`expect(value).not.${preferredMatcherWhenNegated}(1);`,
...['toBe', 'toEqual', 'toStrictEqual'].reduce<string[]>(
(cases, equalityMatcher) => [
...cases,
...generateValidStringLiteralCases(operator, equalityMatcher),
],
[],
...['toBe', 'toEqual', 'toStrictEqual'].flatMap(equalityMatcher =>
generateValidStringLiteralCases(operator, equalityMatcher),
),
],
invalid: ['toBe', 'toEqual', 'toStrictEqual'].reduce<
Array<TSESLint.InvalidTestCase<'useToBeComparison', never>>
>(
(cases, equalityMatcher) => [
...cases,
...generateInvalidCases(
operator,
equalityMatcher,
preferredMatcher,
preferredMatcherWhenNegated,
),
],
[],
invalid: ['toBe', 'toEqual', 'toStrictEqual'].flatMap(equalityMatcher =>
generateInvalidCases(
operator,
equalityMatcher,
preferredMatcher,
preferredMatcherWhenNegated,
),
),
});
};
@@ -274,7 +258,7 @@ testComparisonOperator('<', 'toBeLessThan', 'toBeGreaterThanOrEqual');
testComparisonOperator('>=', 'toBeGreaterThanOrEqual', 'toBeLessThan');
testComparisonOperator('<=', 'toBeLessThanOrEqual', 'toBeGreaterThan');

ruleTester.run(`prefer-to-be-comparison`, rule, {
ruleTester.run(`prefer-comparison-matcher`, rule, {
valid: [
'expect.hasAssertions',
'expect.hasAssertions()',
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-each.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-each';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
6 changes: 3 additions & 3 deletions src/rules/__tests__/prefer-equality-matcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import type { TSESLint } from '@typescript-eslint/utils';
import rule from '../prefer-equality-matcher';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
1,391 changes: 1,370 additions & 21 deletions src/rules/__tests__/prefer-expect-assertions.test.ts

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-expect-resolves.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-expect-resolves';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-hooks-in-order.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-hooks-in-order';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-hooks-on-top.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-hooks-on-top';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-lowercase-title.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-lowercase-title';
import { DescribeAlias, TestCaseName } from '../utils';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-mock-promise-shorthand.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-mock-promise-shorthand';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 6,
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-snapshot-hint.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-snapshot-hint';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
6 changes: 3 additions & 3 deletions src/rules/__tests__/prefer-spy-on.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AST_NODE_TYPES, TSESLint } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import rule from '../prefer-spy-on';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
4 changes: 2 additions & 2 deletions src/rules/__tests__/prefer-strict-equal.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../prefer-strict-equal';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

ruleTester.run('prefer-strict-equal', rule, {
valid: [
7 changes: 3 additions & 4 deletions src/rules/__tests__/prefer-to-be.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../prefer-to-be';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
@@ -317,7 +316,7 @@ ruleTester.run('prefer-to-be: undefined vs defined', rule, {
],
});

new TSESLint.RuleTester({
new FlatCompatRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
}).run('prefer-to-be: typescript edition', rule, {
valid: [
7 changes: 3 additions & 4 deletions src/rules/__tests__/prefer-to-contain.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-to-contain';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
@@ -212,7 +211,7 @@ ruleTester.run('prefer-to-contain', rule, {
],
});

new TSESLint.RuleTester({
new FlatCompatRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
}).run('prefer-to-be-null: typescript edition', rule, {
valid: [
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-to-have-length.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../prefer-to-have-length';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2020,
5 changes: 2 additions & 3 deletions src/rules/__tests__/prefer-todo.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../prefer-todo';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: { ecmaVersion: 2015 },
});
7 changes: 3 additions & 4 deletions src/rules/__tests__/require-hook.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../require-hook';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
@@ -408,7 +407,7 @@ ruleTester.run('require-hook', rule, {
],
});

new TSESLint.RuleTester({
new FlatCompatRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
}).run('require-hook: typescript edition', rule, {
valid: [
5 changes: 2 additions & 3 deletions src/rules/__tests__/require-to-throw-message.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../require-to-throw-message';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/require-top-level-describe.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../require-top-level-describe';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
77 changes: 77 additions & 0 deletions src/rules/__tests__/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,83 @@
import { createRequire } from 'module';
import { TSESLint } from '@typescript-eslint/utils';
import { version as eslintVersion } from 'eslint/package.json';
import * as semver from 'semver';

const require = createRequire(__filename);
const eslintRequire = createRequire(require.resolve('eslint'));

export const espreeParser = eslintRequire.resolve('espree');

export const usingFlatConfig = semver.major(eslintVersion) >= 9;

export class FlatCompatRuleTester extends TSESLint.RuleTester {
public constructor(testerConfig?: TSESLint.RuleTesterConfig) {
super(FlatCompatRuleTester._flatCompat(testerConfig));
}

public override run<
TMessageIds extends string,
TOptions extends Readonly<unknown[]>,
>(
ruleName: string,
rule: TSESLint.RuleModule<TMessageIds, TOptions>,
tests: TSESLint.RunTests<TMessageIds, TOptions>,
) {
super.run(ruleName, rule, {
valid: tests.valid.map(t => FlatCompatRuleTester._flatCompat(t)),
invalid: tests.invalid.map(t => FlatCompatRuleTester._flatCompat(t)),
});
}

/* istanbul ignore next */
private static _flatCompat<
T extends
| undefined
| TSESLint.RuleTesterConfig
| string
| TSESLint.ValidTestCase<unknown[]>
| TSESLint.InvalidTestCase<string, unknown[]>,
>(config: T): T {
if (!config || !usingFlatConfig || typeof config === 'string') {
return config;
}

const obj: TSESLint.FlatConfig.Config & {
languageOptions: TSESLint.FlatConfig.LanguageOptions & {
parserOptions: TSESLint.FlatConfig.ParserOptions;
};
} = {
languageOptions: { parserOptions: {} },
};

for (const [key, value] of Object.entries(config)) {
if (key === 'parser') {
obj.languageOptions.parser = require(value);

continue;
}

if (key === 'parserOptions') {
for (const [option, val] of Object.entries(value)) {
if (option === 'ecmaVersion' || option === 'sourceType') {
// @ts-expect-error: TS thinks the value could the opposite type of whatever option is
obj.languageOptions[option] =
val as TSESLint.FlatConfig.LanguageOptions[
| 'ecmaVersion'
| 'sourceType'];

continue;
}

obj.languageOptions.parserOptions[option] = val;
}

continue;
}

obj[key as keyof typeof obj] = value;
}

return obj as unknown as T;
}
}
102 changes: 90 additions & 12 deletions src/rules/__tests__/unbound-method.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
import path from 'path';
import { ESLintUtils, type TSESLint } from '@typescript-eslint/utils';
import type { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import type { MessageIds, Options } from '../unbound-method';
import { FlatCompatRuleTester } from './test-utils';

function getFixturesRootDir(): string {
return path.join(__dirname, 'fixtures');
}

const rootPath = getFixturesRootDir();

const ruleTester = new ESLintUtils.RuleTester({
parser: '@typescript-eslint/parser',
const ruleTester = new FlatCompatRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
tsconfigRootDir: rootPath,
project: './tsconfig.json',
},
});

const fixtureFilename = path.join(rootPath, 'file.ts');

const withFixtureFilename = <
T extends Array<
| (TSESLint.ValidTestCase<Options> | string)
| TSESLint.InvalidTestCase<MessageIds, Options>
>,
>(
cases: T,
): T extends Array<TSESLint.InvalidTestCase<MessageIds, Options>>
? Array<TSESLint.InvalidTestCase<MessageIds, Options>>
: Array<TSESLint.ValidTestCase<Options>> => {
// @ts-expect-error this is fine, and will go away later once we upgrade
return cases.map(code => {
const test = typeof code === 'string' ? { code } : code;

return { filename: fixtureFilename, ...test };
});
};

const ConsoleClassAndVariableCode = dedent`
class Console {
log(str) {
@@ -164,8 +185,8 @@ describe('error handling', () => {
});

describe('when @typescript-eslint/eslint-plugin is not available', () => {
const ruleTester = new ESLintUtils.RuleTester({
parser: '@typescript-eslint/parser',
const ruleTester = new FlatCompatRuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
tsconfigRootDir: rootPath,
@@ -177,16 +198,18 @@ describe('error handling', () => {
'unbound-method jest edition without type service',
requireRule(true),
{
valid: validTestCases.concat(invalidTestCases.map(({ code }) => code)),
valid: withFixtureFilename(
validTestCases.concat(invalidTestCases.map(({ code }) => code)),
),
invalid: [],
},
);
});
});

ruleTester.run('unbound-method jest edition', requireRule(false), {
valid: validTestCases,
invalid: invalidTestCases,
valid: withFixtureFilename(validTestCases),
invalid: withFixtureFilename(invalidTestCases),
});

function addContainsMethodsClass(code: string): string {
@@ -225,11 +248,12 @@ function addContainsMethodsClassInvalid(
}

ruleTester.run('unbound-method', requireRule(false), {
valid: [
valid: withFixtureFilename([
'Promise.resolve().then(console.log);',
"['1', '2', '3'].map(Number.parseInt);",
'[5.2, 7.1, 3.6].map(Math.floor);',
'const x = console.log;',
'const x = Object.defineProperty;',
...[
'instance.bound();',
'instance.unbound();',
@@ -455,8 +479,8 @@ class OtherClass extends BaseClass {
const oc = new OtherClass();
oc.superLogThis();
`,
],
invalid: [
]),
invalid: withFixtureFilename([
{
code: `
class Console {
@@ -762,5 +786,59 @@ class OtherClass extends BaseClass {
},
],
},
],
{
code: `
const values = {
a() {},
b: () => {},
};
const { a, b } = values;
`,
errors: [
{
line: 7,
column: 9,
endColumn: 10,
messageId: 'unboundWithoutThisAnnotation',
},
],
},
{
code: `
const values = {
a() {},
b: () => {},
};
const { a: c } = values;
`,
errors: [
{
line: 7,
column: 9,
endColumn: 10,
messageId: 'unboundWithoutThisAnnotation',
},
],
},
{
code: `
const values = {
a() {},
b: () => {},
};
const { b, a } = values;
`,
errors: [
{
line: 7,
column: 12,
endColumn: 13,
messageId: 'unboundWithoutThisAnnotation',
},
],
},
]),
});
5 changes: 2 additions & 3 deletions src/rules/__tests__/valid-describe-callback.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../valid-describe-callback';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/valid-expect-in-promise.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../valid-expect-in-promise';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/valid-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../valid-expect';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
5 changes: 2 additions & 3 deletions src/rules/__tests__/valid-title.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../valid-title';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
4 changes: 2 additions & 2 deletions src/rules/consistent-test-it.ts
Original file line number Diff line number Diff line change
@@ -35,9 +35,7 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Enforce `test` and `it` usage conventions',
recommended: false,
},
fixable: 'code',
messages: {
@@ -51,9 +49,11 @@ export default createRule<
type: 'object',
properties: {
fn: {
type: 'string',
enum: [TestCaseName.it, TestCaseName.test],
},
withinDescribe: {
type: 'string',
enum: [TestCaseName.it, TestCaseName.test],
},
},
2 changes: 0 additions & 2 deletions src/rules/expect-expect.ts
Original file line number Diff line number Diff line change
@@ -54,9 +54,7 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Enforce assertion to be made in a test body',
recommended: 'warn',
},
messages: {
noAssertions: 'Test has no assertions',
2 changes: 0 additions & 2 deletions src/rules/max-expects.ts
Original file line number Diff line number Diff line change
@@ -10,9 +10,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Enforces a maximum number assertion calls in a test body',
recommended: false,
},
messages: {
exceededMaxAssertion:
2 changes: 0 additions & 2 deletions src/rules/max-nested-describe.ts
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Enforces a maximum depth to nested describe calls',
recommended: false,
},
messages: {
exceededMaxDepth:
2 changes: 0 additions & 2 deletions src/rules/no-alias-methods.ts
Original file line number Diff line number Diff line change
@@ -9,9 +9,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow alias methods',
recommended: 'error',
},
messages: {
replaceAlias: `Replace {{ alias }}() with its canonical name of {{ canonical }}()`,
2 changes: 0 additions & 2 deletions src/rules/no-commented-out-tests.ts
Original file line number Diff line number Diff line change
@@ -11,9 +11,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow commented out tests',
recommended: 'warn',
},
messages: {
commentedTests: 'Some tests seem to be commented',
2 changes: 0 additions & 2 deletions src/rules/no-conditional-expect.ts
Original file line number Diff line number Diff line change
@@ -20,8 +20,6 @@ export default createRule({
meta: {
docs: {
description: 'Disallow calling `expect` conditionally',
category: 'Best Practices',
recommended: 'error',
},
messages: {
conditionalExpect: 'Avoid calling `expect` conditionally`',
2 changes: 0 additions & 2 deletions src/rules/no-conditional-in-test.ts
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@ export default createRule({
meta: {
docs: {
description: 'Disallow conditional logic in tests',
category: 'Best Practices',
recommended: false,
},
messages: {
conditionalInTest: 'Avoid having conditionals in tests',
2 changes: 0 additions & 2 deletions src/rules/no-confusing-set-timeout.ts
Original file line number Diff line number Diff line change
@@ -18,9 +18,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow confusing usages of jest.setTimeout',
recommended: false,
},
messages: {
globalSetTimeout: '`jest.setTimeout` should be call in `global` scope',
2 changes: 0 additions & 2 deletions src/rules/no-deprecated-functions.ts
Original file line number Diff line number Diff line change
@@ -28,9 +28,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow use of deprecated functions',
recommended: 'error',
},
messages: {
deprecatedFunction:
2 changes: 0 additions & 2 deletions src/rules/no-disabled-tests.ts
Original file line number Diff line number Diff line change
@@ -10,9 +10,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow disabled tests',
recommended: 'warn',
},
messages: {
missingFunction: 'Test is missing function argument',
5 changes: 2 additions & 3 deletions src/rules/no-done-callback.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import {
} from '@typescript-eslint/utils';
import {
createRule,
getFilename,
getNodeName,
getSourceCode,
isFunction,
@@ -37,9 +38,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow using a callback in asynchronous tests and hooks',
recommended: 'error',
},
messages: {
noDoneCallback:
@@ -134,7 +133,7 @@ export default createRule({
!tokenAfterLastParam
) {
throw new Error(
`Unexpected null when attempting to fix ${context.getFilename()} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`,
`Unexpected null when attempting to fix ${getFilename(context)} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`,
);
}

2 changes: 0 additions & 2 deletions src/rules/no-duplicate-hooks.ts
Original file line number Diff line number Diff line change
@@ -4,9 +4,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow duplicate setup and teardown hooks',
recommended: false,
},
messages: {
noDuplicateHook: 'Duplicate {{hook}} in describe block',
2 changes: 0 additions & 2 deletions src/rules/no-export.ts
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow using `exports` in files containing tests',
recommended: 'error',
},
messages: {
unexpectedExport: `Do not export from a test file`,
2 changes: 0 additions & 2 deletions src/rules/no-focused-tests.ts
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow focused tests',
recommended: 'error',
},
messages: {
focusedTest: 'Unexpected focused test',
3 changes: 1 addition & 2 deletions src/rules/no-hooks.ts
Original file line number Diff line number Diff line change
@@ -7,9 +7,7 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow setup and teardown hooks',
recommended: false,
},
messages: {
unexpectedHook: "Unexpected '{{ hookName }}' hook",
@@ -20,6 +18,7 @@ export default createRule<
properties: {
allow: {
type: 'array',
// @ts-expect-error https://github.com/eslint/eslint/discussions/17573
contains: ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'],
},
},
2 changes: 0 additions & 2 deletions src/rules/no-identical-title.ts
Original file line number Diff line number Diff line change
@@ -21,9 +21,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow identical titles',
recommended: 'error',
},
messages: {
multipleTestTitle:
121 changes: 0 additions & 121 deletions src/rules/no-if.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/rules/no-interpolation-in-snapshots.ts
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow string interpolation inside snapshots',
recommended: 'error',
},
messages: {
noInterpolation: 'Do not use string interpolation inside of snapshots',
2 changes: 0 additions & 2 deletions src/rules/no-jasmine-globals.ts
Original file line number Diff line number Diff line change
@@ -11,9 +11,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow Jasmine globals',
recommended: 'error',
},
messages: {
illegalGlobal:
10 changes: 4 additions & 6 deletions src/rules/no-large-snapshots.ts
Original file line number Diff line number Diff line change
@@ -54,11 +54,11 @@ const reportOnViolation = (
const snapshotName = getAccessorValue(node.expression.left.property);

isAllowed = allowedSnapshotsInFile.some(name => {
if (name instanceof RegExp) {
return name.test(snapshotName);
if (typeof name === 'string') {
return snapshotName === name;
}

return snapshotName === name;
return name.test(snapshotName);
});
}
}
@@ -76,9 +76,7 @@ export default createRule<[RuleOptions], MessageId>({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow large snapshots',
recommended: false,
},
messages: {
noSnapshot: '`{{ lineCount }}`s should begin with lowercase',
@@ -107,7 +105,7 @@ export default createRule<[RuleOptions], MessageId>({
},
defaultOptions: [{}],
create(context, [options]) {
if (context.getFilename().endsWith('.snap')) {
if (getFilename(context).endsWith('.snap')) {
return {
ExpressionStatement(node) {
reportOnViolation(context, node, options);
2 changes: 0 additions & 2 deletions src/rules/no-mocks-import.ts
Original file line number Diff line number Diff line change
@@ -17,9 +17,7 @@ export default createRule({
meta: {
type: 'problem',
docs: {
category: 'Best Practices',
description: 'Disallow manually importing from `__mocks__`',
recommended: 'error',
},
messages: {
noManualImport: `Mocks should not be manually imported from a ${mocksDirName} directory. Instead use \`jest.mock\` and import from the original module path`,
2 changes: 0 additions & 2 deletions src/rules/no-restricted-jest-methods.ts
Original file line number Diff line number Diff line change
@@ -12,9 +12,7 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow specific `jest.` methods',
recommended: false,
},
type: 'suggestion',
schema: [
2 changes: 0 additions & 2 deletions src/rules/no-restricted-matchers.ts
Original file line number Diff line number Diff line change
@@ -23,9 +23,7 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow specific matchers & modifiers',
recommended: false,
},
type: 'suggestion',
schema: [
3 changes: 1 addition & 2 deletions src/rules/no-standalone-expect.ts
Original file line number Diff line number Diff line change
@@ -60,16 +60,15 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow using `expect` outside of `it` or `test` blocks',
recommended: 'error',
},
messages: {
unexpectedExpect: 'Expect must be inside of a test block',
},
type: 'suggestion',
schema: [
{
type: 'object',
properties: {
additionalTestBlockFunctions: {
type: 'array',
2 changes: 0 additions & 2 deletions src/rules/no-test-prefixes.ts
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Require using `.only` and `.skip` over `f` and `x`',
recommended: 'error',
},
messages: {
usePreferredName: 'Use "{{ preferredNodeName }}" instead',
2 changes: 0 additions & 2 deletions src/rules/no-test-return-statement.ts
Original file line number Diff line number Diff line change
@@ -25,9 +25,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow explicitly returning from tests',
recommended: false,
},
messages: {
noReturnValue: 'Jest tests should not return a value',
6 changes: 2 additions & 4 deletions src/rules/no-untyped-mock-factory.ts
Original file line number Diff line number Diff line change
@@ -21,10 +21,8 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
'Disallow using `jest.mock()` factories without an explicit type parameter',
recommended: false,
},
messages: {
addTypeParameterToModuleMock:
@@ -38,7 +36,7 @@ export default createRule({
create(context) {
return {
CallExpression(node: TSESTree.CallExpression): void {
const { callee, typeParameters } = node;
const { callee, typeArguments } = node;

if (callee.type !== AST_NODE_TYPES.MemberExpression) {
return;
@@ -55,7 +53,7 @@ export default createRule({
const [nameNode, factoryNode] = node.arguments;

const hasTypeParameter =
typeParameters !== undefined && typeParameters.params.length > 0;
typeArguments !== undefined && typeArguments.params.length > 0;
const hasReturnType =
isFunction(factoryNode) && factoryNode.returnType !== undefined;

2 changes: 0 additions & 2 deletions src/rules/prefer-called-with.ts
Original file line number Diff line number Diff line change
@@ -4,10 +4,8 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
'Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()`',
recommended: false,
},
messages: {
preferCalledWith: 'Prefer {{ matcherName }}With(/* expected args */)',
2 changes: 0 additions & 2 deletions src/rules/prefer-comparison-matcher.ts
Original file line number Diff line number Diff line change
@@ -57,9 +57,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using the built-in comparison matchers',
recommended: false,
},
messages: {
useToBeComparison: 'Prefer using `{{ preferredMatcher }}` instead',
2 changes: 0 additions & 2 deletions src/rules/prefer-each.ts
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Prefer using `.each` rather than manual loops',
recommended: false,
},
messages: {
preferEach: 'prefer using `{{ fn }}.each` rather than a manual loop',
2 changes: 0 additions & 2 deletions src/rules/prefer-equality-matcher.ts
Original file line number Diff line number Diff line change
@@ -14,9 +14,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using the built-in equality matchers',
recommended: false,
},
messages: {
useEqualityMatcher: 'Prefer using one of the equality matchers instead',
2 changes: 0 additions & 2 deletions src/rules/prefer-expect-assertions.ts
Original file line number Diff line number Diff line change
@@ -64,10 +64,8 @@ export default createRule<[RuleOptions], MessageIds>({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
'Suggest using `expect.assertions()` OR `expect.hasAssertions()`',
recommended: false,
},
messages: {
hasAssertionsTakesNoArguments:
2 changes: 0 additions & 2 deletions src/rules/prefer-expect-resolves.ts
Original file line number Diff line number Diff line change
@@ -5,10 +5,8 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
'Prefer `await expect(...).resolves` over `expect(await ...)` syntax',
recommended: false,
},
fixable: 'code',
messages: {
2 changes: 0 additions & 2 deletions src/rules/prefer-hooks-in-order.ts
Original file line number Diff line number Diff line change
@@ -6,9 +6,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Prefer having hooks in a consistent order',
recommended: false,
},
messages: {
reorderHooks: `\`{{ currentHook }}\` hooks should be before any \`{{ previousHook }}\` hooks`,
2 changes: 0 additions & 2 deletions src/rules/prefer-hooks-on-top.ts
Original file line number Diff line number Diff line change
@@ -4,9 +4,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest having hooks before any test cases',
recommended: false,
},
messages: {
noHookOnTop: 'Hooks should come before test cases',
7 changes: 4 additions & 3 deletions src/rules/prefer-lowercase-title.ts
Original file line number Diff line number Diff line change
@@ -56,8 +56,6 @@ export default createRule<
type: 'suggestion',
docs: {
description: 'Enforce lowercase test names',
category: 'Best Practices',
recommended: false,
},
fixable: 'code',
messages: {
@@ -70,11 +68,14 @@ export default createRule<
ignore: {
type: 'array',
items: {
type: 'string',
// for some reason TypeScript thinks this _must_ be a read-only
// array, so we have to explicitly cast it as a mutable array
enum: [
DescribeAlias.describe,
TestCaseName.test,
TestCaseName.it,
],
] as string[],
},
additionalItems: false,
},
2 changes: 0 additions & 2 deletions src/rules/prefer-mock-promise-shorthand.ts
Original file line number Diff line number Diff line change
@@ -32,9 +32,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Prefer mock resolved/rejected shorthands for promises',
recommended: false,
},
messages: {
useMockShorthand: 'Prefer {{ replacement }}',
2 changes: 0 additions & 2 deletions src/rules/prefer-snapshot-hint.ts
Original file line number Diff line number Diff line change
@@ -43,9 +43,7 @@ export default createRule<[('always' | 'multi')?], keyof typeof messages>({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Prefer including a hint with external snapshots',
recommended: false,
},
messages,
type: 'suggestion',
2 changes: 0 additions & 2 deletions src/rules/prefer-spy-on.ts
Original file line number Diff line number Diff line change
@@ -68,9 +68,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using `jest.spyOn()`',
recommended: false,
},
messages: {
useJestSpyOn: 'Use jest.spyOn() instead',
2 changes: 0 additions & 2 deletions src/rules/prefer-strict-equal.ts
Original file line number Diff line number Diff line change
@@ -10,9 +10,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using `toStrictEqual()`',
recommended: false,
},
messages: {
useToStrictEqual: 'Use `toStrictEqual()` instead',
2 changes: 0 additions & 2 deletions src/rules/prefer-to-be.ts
Original file line number Diff line number Diff line change
@@ -93,9 +93,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using `toBe()` for primitive literals',
recommended: false,
},
messages: {
useToBe: 'Use `toBe` when expecting primitive literals',
2 changes: 0 additions & 2 deletions src/rules/prefer-to-contain.ts
Original file line number Diff line number Diff line change
@@ -39,9 +39,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using `toContain()`',
recommended: false,
},
messages: {
useToContain: 'Use toContain() instead',
2 changes: 0 additions & 2 deletions src/rules/prefer-to-have-length.ts
Original file line number Diff line number Diff line change
@@ -11,9 +11,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using `toHaveLength()`',
recommended: false,
},
messages: {
useToHaveLength: 'Use toHaveLength() instead',
2 changes: 0 additions & 2 deletions src/rules/prefer-todo.ts
Original file line number Diff line number Diff line change
@@ -55,9 +55,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Suggest using `test.todo`',
recommended: false,
},
messages: {
emptyTest: 'Prefer todo test case over empty test case',
2 changes: 0 additions & 2 deletions src/rules/require-hook.ts
Original file line number Diff line number Diff line change
@@ -65,9 +65,7 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Require setup and teardown code to be within a hook',
recommended: false,
},
messages: {
useHook: 'This should be done within a hook',
2 changes: 0 additions & 2 deletions src/rules/require-to-throw-message.ts
Original file line number Diff line number Diff line change
@@ -4,9 +4,7 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Require a message for `toThrow()`',
recommended: false,
},
messages: {
addErrorMessage: 'Add an error message to {{ matcherName }}()',
2 changes: 0 additions & 2 deletions src/rules/require-top-level-describe.ts
Original file line number Diff line number Diff line change
@@ -15,10 +15,8 @@ export default createRule<
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
'Require test cases and hooks to be inside a `describe` block',
recommended: false,
},
messages,
type: 'suggestion',
4 changes: 2 additions & 2 deletions src/rules/unbound-method.ts
Original file line number Diff line number Diff line change
@@ -60,12 +60,12 @@ export default createRule<Options, MessageIds>({
type: 'problem',
...baseRule?.meta,
docs: {
category: 'Best Practices',
description:
'Enforce unbound methods are called with their expected scope',
requiresTypeChecking: true,
...baseRule?.meta.docs,
recommended: false,
// mark this as not recommended
recommended: undefined,
},
},
create(context) {
8 changes: 3 additions & 5 deletions src/rules/utils/__tests__/parseJestFnCall.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package';
import { TSESLint, type TSESTree } from '@typescript-eslint/utils';
import type { TSESTree } from '@typescript-eslint/utils';
import dedent from 'dedent';
import { espreeParser } from '../../__tests__/test-utils';
import { FlatCompatRuleTester, espreeParser } from '../../__tests__/test-utils';
import {
type ParsedJestFnCall,
type ResolvedJestFnWithNode,
@@ -29,7 +29,7 @@ const findESLintVersion = (): number => {

const eslintVersion = findESLintVersion();

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
@@ -48,9 +48,7 @@ const rule = createRule({
name: __filename,
meta: {
docs: {
category: 'Possible Errors',
description: 'Fake rule for testing parseJestFnCall',
recommended: false,
},
messages: {
details: '{{ data }}',
53 changes: 15 additions & 38 deletions src/rules/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -137,18 +137,14 @@ export const getTestCallExpressionsFromDeclaredVariables = (
declaredVariables: readonly TSESLint.Scope.Variable[],
context: TSESLint.RuleContext<string, unknown[]>,
): TSESTree.CallExpression[] => {
return declaredVariables.reduce<TSESTree.CallExpression[]>(
(acc, { references }) =>
acc.concat(
references
.map(({ identifier }) => identifier.parent)
.filter(
(node): node is TSESTree.CallExpression =>
node?.type === AST_NODE_TYPES.CallExpression &&
isTypeOfJestFnCall(node, context, ['test']),
),
return declaredVariables.flatMap(({ references }) =>
references
.map(({ identifier }) => identifier.parent)
.filter(
(node): node is TSESTree.CallExpression =>
node?.type === AST_NODE_TYPES.CallExpression &&
isTypeOfJestFnCall(node, context, ['test']),
),
[],
);
};

@@ -234,58 +230,39 @@ export const getFirstMatcherArg = (
export const getFilename = (
context: TSESLint.RuleContext<string, unknown[]>,
) => {
return 'filename' in context
? (context.filename as string)
: context.getFilename();
return context.filename ?? context.getFilename();
};

/* istanbul ignore next */
export const getSourceCode = (
context: TSESLint.RuleContext<string, unknown[]>,
) => {
return 'sourceCode' in context
? (context.sourceCode as TSESLint.SourceCode)
: context.getSourceCode();
return context.sourceCode ?? context.getSourceCode();
};

/* istanbul ignore next */
export const getScope = (
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node,
) => {
const sourceCode = getSourceCode(context);

if ('getScope' in sourceCode) {
return sourceCode.getScope(node);
}

return context.getScope();
return getSourceCode(context).getScope?.(node) ?? context.getScope();
};

/* istanbul ignore next */
export const getAncestors = (
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node,
) => {
const sourceCode = getSourceCode(context);

if ('getAncestors' in sourceCode) {
return sourceCode.getAncestors(node);
}

return context.getAncestors();
return getSourceCode(context).getAncestors?.(node) ?? context.getAncestors();
};

/* istanbul ignore next */
export const getDeclaredVariables = (
context: TSESLint.RuleContext<string, unknown[]>,
node: TSESTree.Node,
) => {
const sourceCode = getSourceCode(context);

if ('getDeclaredVariables' in sourceCode) {
return sourceCode.getDeclaredVariables(node);
}

return context.getDeclaredVariables(node);
return (
getSourceCode(context).getDeclaredVariables?.(node) ??
context.getDeclaredVariables(node)
);
};
17 changes: 9 additions & 8 deletions src/rules/utils/parseJestFnCall.ts
Original file line number Diff line number Diff line change
@@ -183,20 +183,21 @@ const ValidJestFnCallChains = [
'xtest.failing.each',
];

declare module '@typescript-eslint/utils/dist/ts-eslint' {
export interface SharedConfigurationSettings {
jest?: {
globalAliases?: Record<string, string[]>;
version?: number | string;
};
}
// todo: switch back to using declaration merging once https://github.com/typescript-eslint/typescript-eslint/pull/8485
// is landed
interface SharedConfigurationSettings {
jest?: {
globalAliases?: Record<string, string[]>;
version?: number | string;
};
}

const resolvePossibleAliasedGlobal = (
global: string,
context: TSESLint.RuleContext<string, unknown[]>,
) => {
const globalAliases = context.settings.jest?.globalAliases ?? {};
const globalAliases =
(context.settings as SharedConfigurationSettings).jest?.globalAliases ?? {};

const alias = Object.entries(globalAliases).find(([, aliases]) =>
aliases.includes(global),
2 changes: 0 additions & 2 deletions src/rules/valid-describe-callback.ts
Original file line number Diff line number Diff line change
@@ -23,9 +23,7 @@ export default createRule({
meta: {
type: 'problem',
docs: {
category: 'Possible Errors',
description: 'Enforce valid `describe()` callback',
recommended: 'error',
},
messages: {
nameAndCallback: 'Describe requires name and callback arguments',
2 changes: 0 additions & 2 deletions src/rules/valid-expect-in-promise.ts
Original file line number Diff line number Diff line change
@@ -344,10 +344,8 @@ export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
'Require promises that have expectations in their chain to be valid',
recommended: 'error',
},
messages: {
expectInFloatingPromise:
2 changes: 0 additions & 2 deletions src/rules/valid-expect.ts
Original file line number Diff line number Diff line change
@@ -115,9 +115,7 @@ export default createRule<[Options], MessageIds>({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Enforce valid `expect()` usage',
recommended: 'error',
},
messages: {
tooManyArgs: 'Expect takes at most {{ amount }} argument{{ s }}',
5 changes: 2 additions & 3 deletions src/rules/valid-title.ts
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ const compileMatcherPatterns = (
type CompiledMatcherAndMessage = [matcher: RegExp, message?: string];
type MatcherAndMessage = [matcher: string, message?: string];

const MatcherAndMessageSchema: JSONSchema.JSONSchema7 = {
const MatcherAndMessageSchema: JSONSchema.JSONSchema4 = {
type: 'array',
items: { type: 'string' },
minItems: 1,
@@ -114,9 +114,7 @@ export default createRule<[Options], MessageIds>({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Enforce valid titles',
recommended: 'error',
},
messages: {
titleMustBeString: 'Title must be a string',
@@ -158,6 +156,7 @@ export default createRule<[Options], MessageIds>({
MatcherAndMessageSchema,
{
type: 'object',
// @ts-expect-error https://github.com/eslint/eslint/discussions/17573
propertyNames: { enum: ['describe', 'test', 'it'] },
additionalProperties: {
oneOf: [{ type: 'string' }, MatcherAndMessageSchema],
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"extends": "@tsconfig/node16/tsconfig.json",
"compilerOptions": {
"noEmit": true,
"stripInternal": true,
@@ -12,11 +12,9 @@
"noFallthroughCasesInSwitch": true,

"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"skipLibCheck": false,
"forceConsistentCasingInFileNames": true
"skipLibCheck": false
},
"files": ["eslint-remote-tester.config.ts"],
"include": ["src/**/*", "tools/**/*"],
3,115 changes: 1,762 additions & 1,353 deletions yarn.lock

Large diffs are not rendered by default.