mthadley / eslint-plugin-sort-destructure-keys

ESLint plugin to check if keys should be sorted in an object pattern.
https://www.npmjs.com/package/eslint-plugin-sort-destructure-keys
ISC License
95 stars 9 forks source link

Update getScope call for ESLint 9 compatibility #267

Closed ptb closed 6 months ago

ptb commented 7 months ago

This adds compatibility with ESLint 9.

context.getScope() is deprecated and has been removed in ESLint v9.0.0.

We have introduced a new SourceCode#getScope(node) method that requires you to pass in the reference node. This method was added in ESLint v8.37.0 so it has already been in place for the last six months. For best compatibility, you can check for the presence of this new method to determine which one to use:

module.exports = {
    create(context) {

        const { sourceCode } = context;

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

                // do something with scope
            }
        }
    }
};

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

hollanderbart commented 6 months ago

@mthadley Can you please review this PR?