Skip to content

ESLint 9 compatibility: TypeError: context.getScope is not a function #16

@Dwlad90

Description

@Dwlad90

Problem

The plugin is not compatible with ESLint 9 due to usage of deprecated APIs.

Error Message

TypeError: context.getScope is not a function Occurred while linting .../src/Button.tsx:1 Rule: react-server-components/use-client at Program (...node_modules/eslint-plugin-react-server-components/dist/index.cjs:289:31)

Details

  • ESLint version: 9.25.1
  • eslint-plugin-react-server-components version: 1.2.0
  • @eslint/eslintrc: latest

The plugin is using context.getScope() which has been removed in ESLint 9's new flat config system. Even though I'm using FlatCompat to properly load the legacy config, the internal implementation of the rule is still using deprecated APIs.

Reproduction

import { FlatCompat } from '@eslint/eslintrc';
import reactPlugin from 'eslint-plugin-react';
// Other imports...

// Using FlatCompat to convert legacy configs
const compat = new FlatCompat({
  baseDirectory: import.meta.dirname,
});

// Loading the recommended config using FlatCompat
const rscConfig = compat.extends('plugin:react-server-components/recommended');

export default [
  {
    // ...other config
    plugins: {
      'react': reactPlugin,
      // Using the plugin from the converted config
      'react-server-components': rscConfig[0].plugins['react-server-components'],
    },
    rules: {
      // ...other rules
      // Using rules from the converted config
      ...rscConfig[0].rules,
      
      // Custom rule config
      "react-server-components/use-client": ["error", { allowedServerHooks: ["useMemo"] }],
    },
  }
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions