Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules fail with ESLint 9.0.0 - context.getScope is not a function #352

Closed
tillig opened this issue Apr 8, 2024 · 10 comments
Closed

Rules fail with ESLint 9.0.0 - context.getScope is not a function #352

tillig opened this issue Apr 8, 2024 · 10 comments
Labels

Comments

@tillig
Copy link

tillig commented Apr 8, 2024

It appears there have been quite a few breaking changes with ESLint 9.0.0, and with that it looks like context.getScope() is no longer an available shortcut.

It looks like a PR got merged that has the fix for this back on Feb 16, but it appears that hasn't been released yet - it's not in v10.4.1, which is the current latest.

Is there a plan to release that in the near future?

@MikeMcC399
Copy link

MikeMcC399 commented Apr 9, 2024

This issue relates to the blog Preparing your custom rules for ESLint v9.0.0 published on Sep 26, 2023

Good to see that there is already a merged PR for this as Eslint v9 was announced released on Apr 5, 2024.

@lo1tuma
Copy link
Owner

lo1tuma commented Apr 10, 2024

Thanks for reporting. I will take a look into it and try to make a patch release ASAP.

@lo1tuma
Copy link
Owner

lo1tuma commented Apr 10, 2024

I’ve cherry-picked the changes from #347 and made a patch release v10.4.2. Unfortunately I forgot to make a release after merging #347 to main and now main contains a few breaking changes which are planned for v11.

Please let me know if v10.4.2 fixes the issues with ESLint v9.

@MikeMcC399
Copy link

@lo1tuma

Please let me know if v10.4.2 fixes the issues with ESLint v9.

I tested with eslint@9.0.0 and my errors were gone. I also checked for backwards compatibility with eslint@8.57.0 and I saw no issue.

Many thanks!

@lo1tuma
Copy link
Owner

lo1tuma commented Apr 10, 2024

@MikeMcC399 thanks for confirming... in this case I will close this issue.

@lo1tuma lo1tuma closed this as completed Apr 10, 2024
@lo1tuma lo1tuma added the bug label Apr 10, 2024
@tillig
Copy link
Author

tillig commented Apr 10, 2024

Yup, also verified. Thanks!

@mcat95
Copy link

mcat95 commented Apr 16, 2024

Hello,

I believe the 10.4.2 patch broke compatibility with eslint versions prior to 8 (We get the error on 7.32.0):
TypeError: Cannot read properties of undefined (reading 'getScope')

@MikeMcC399
Copy link

@mcat95

I believe the 10.4.2 patch broke compatibility with eslint versions prior to 8 (We get the error on 7.32.0): TypeError: Cannot read properties of undefined (reading 'getScope')

Ouch!

It sounds like this needs to be a new issue leading to a new fix release.

The example in https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope() shows supporting both the deprecated API and the new API. If only the new API has been implemented, then it would break compatibility with anything below ESLint v8.37.0 🤭

module.exports = {
    create(context) {

        const { sourceCode } = context;

        return {
            Program(node) {
                const scope = sourceCode.getScope
                    ? sourceCode.getScope(node)
                    : context.getScope();

                // do something with scope
            }
        }
    }
};

@MikeMcC399
Copy link

@mcat95

@MikeMcC399
Copy link

@mcat95

This was fixed in 10.4.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants