Skip to content

eslint v9 - context.getScope is not a function - API change #924

@dylang

Description

@dylang

Have you read the Troubleshooting section?

Yes

Plugin version

v6.3.0

ESLint version

v9..9.0

Node.js version

20.16.0

package manager and version

yarn v1

Operating system

macOS

Bug description

Example error:

TypeError: context.getScope is not a function
Occurred while linting ./examples/example-web-frontend/src/hello-world.test.tsx:39
Rule: "testing-library/await-async-utils"

Steps to reproduce

run eslint in terminal or ide using eslint v9.9.0 and latest plugin.

Error output/screenshots

Rule: "testing-library/await-async-utils"
    at getInnermostFunctionScope (/project/node_modules/eslint-plugin-testing-library/dist/node-utils/index.js:205:71)
    at getInnermostReturningFunction (/project/node_modules/eslint-plugin-testing-library/dist/node-utils/index.js:331:27)
    at detectAsyncUtilWrapper (/project/node_modules/eslint-plugin-testing-library/dist/rules/await-async-utils.js:32:82)
    at CallExpression Identifier (/project/node_modules/eslint-plugin-testing-library/dist/rules/await-async-utils.js:86:21)
    at enhancedRuleInstructions.<computed> (/project/node_modules/eslint-plugin-testing-library/dist/create-testing-library-rule/detect-testing-library-utils.js:528:105)
    at ruleErrorHandler (/project/node_modules/eslint/lib/linter/linter.js:1124:48)
    at /Users/dgreene/medallia/magic-fun/node_modules/eslint/lib/linter/safe-emitter.js:45:58

ESLint configuration

Not the whole config, just the part regarding test files.
The project is using typescript-eslint@v8.0.1.

import globals from 'globals';
import testingLibrary from 'eslint-plugin-testing-library';
import { config } from 'typescript-eslint';
import jest from 'eslint-plugin-jest';
import jestDom from 'eslint-plugin-jest-dom';

export const testConfig = config({
  name: 'eslint-config-test-files',

  files: [
    '**/*.test.?(disabled.)?(m)[jt]s?(x)',
    '**/*.spec.?(m)[jt]s?(x)',
    '**/demo/**/*.[jt]s?(x)',
    '**/demo-sandbox/**/*.[jt]s?(x)',
    '**/__mocks__/**/*.[jt]s?(x)',
    '**/test/**/*.[jt]s?(x)',
    '**/fixtures/**/*.[jt]s?(x)'
  ],

  languageOptions: {
    globals: { ...globals.jest, jsdom: true }
  },

  plugins: {
    jest,
    'jest-dom': jestDom,
    'testing-library': testingLibrary
  },

  rules: {
    ...jest.configs['flat/recommended'].rules,
    ...jestDom.configs['flat/recommended'].rules,
    ...testingLibrary.configs['flat/react'].rules
  }
});

Rule(s) affected

Seems like all of them.

Anything else?

It seems that getScope was moved from context to sourceCode

https://eslint.org/docs/latest/use/troubleshooting/v9-rule-api-changes

https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()

Do you want to submit a pull request to fix this bug?

No

Activity

added
bugSomething isn't working
triagePending to be triaged by a maintainer
on Aug 11, 2024
removed
triagePending to be triaged by a maintainer
on Aug 12, 2024
Belco90

Belco90 commented on Aug 12, 2024

@Belco90
Member

Thanks for reporting. In the current version of this plugin, we are only adding compatibility with flat config, but not officially with ESLint v9. I'm afraid you'll have to use the ESLint compatibility util until we release the next major of the plugin, where ESLint v9 will be properly supported.

added
enhancementNew feature or request
and removed
bugSomething isn't working
on Aug 12, 2024
lemueldizon

lemueldizon commented on Aug 12, 2024

@lemueldizon

This below fixed the issue for me, it's a slight change compared to previous version fix pointed out in #899.

{
   ...
    files: ['**/*.test.{ts,tsx}'],
    plugins: {
      'testing-library': fixupPluginRules({
        rules: testingLibrary.rules
      })
    },
    rules: {
      ...testingLibrary.configs['flat/react'].rules,
      'testing-library/no-container': 'off',
      'testing-library/no-node-access': 'off'
    }
   ...
  }
G-Rath

G-Rath commented on Aug 14, 2024

@G-Rath
G-Rath

G-Rath commented on Aug 15, 2024

@G-Rath
Contributor

I have opened #925 which should resolve this without requiring a new major

ixartz

ixartz commented on Oct 13, 2024

@ixartz

Would be great to update the peerDependencies to support ESLint v9. ESLint v8 has been deprecated: "ESLint v8.x reached end-of-life on 2024-10-05 and is no longer maintained." quoted on the official website.

Thanks

Belco90

Belco90 commented on Oct 14, 2024

@Belco90
Member

Sorry for not reacting to this. I'll try to get #925 merged this week.

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @dylang@Belco90@G-Rath@ixartz@lemueldizon

      Issue actions

        eslint v9 - context.getScope is not a function - API change · Issue #924 · testing-library/eslint-plugin-testing-library