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

fix: convert deprecated context calls #182

Merged
merged 2 commits into from Apr 26, 2024

Conversation

MikeMcC399
Copy link
Collaborator

@MikeMcC399 MikeMcC399 commented Apr 22, 2024

Issue

These methods are deprecated in ESLint 8.x (eslint@8.50.0 and later 8.x releases), causing warnings, and removed in ESLint 9.x (eslint@9.0.0), causing failures.

Change

See ESLint Blog Preparing your custom rules for ESLint v9.0.0 Sep 26, 2023.

The above mentioned rules are converted according to:

except that instead of the suggested code line
const { sourceCode } = context;
the following is used
const { sourceCode = {} } = context;
to avoid failure on earlier versions, such as ESLint 8.23.0.

Edit: the recommendations have been revised and the above line of code is now
const sourceCode = context.sourceCode ?? context.getSourceCode();

Verification

On Ubuntu 22.04.4 LTS with Node.js 20.12.2 LTS. For ESLint v7 and v8 execute npx jest.

npm ci
npm uninstall eslint-plugin-eslint-plugin eslint-plugin-n
npm install eslint@7
npx jest
npm install eslint@8
npx jest

@cypress-app-bot
Copy link

@jennifer-shehane
Copy link
Member

@MikeMcC399 Can we have the circle.yml print the version that was installed for ESLint? I was trying to see which version is installed on this step, and you can't actually tell. The warnings are a bit confusing printing a 7.x version.

@MikeMcC399

This comment was marked as resolved.

@MikeMcC399

This comment was marked as resolved.

Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@MikeMcC399

This comment was marked as resolved.

@MikeMcC399

This comment was marked as outdated.

@MikeMcC399 MikeMcC399 marked this pull request as ready for review April 23, 2024 16:59
@MikeMcC399 MikeMcC399 marked this pull request as draft April 26, 2024 06:31
@MikeMcC399

This comment was marked as resolved.

@MikeMcC399
Copy link
Collaborator Author

MikeMcC399 commented Apr 26, 2024

Updated according to new recommendations from Preparing your custom rules for ESLint v9.0.0.

I will leave in draft whilst going through some additional external compatibility tests. Edit: Done

@MikeMcC399
Copy link
Collaborator Author

Verification

Use https://github.com/cypress-io/cypress-example-kitchensink as test platform

Preparation

npm ci
npm install eslint-plugin-mocha@latest https://github.com/MikeMcC399/eslint-plugin-cypress#convert-to-sourcecode

Test the following combinations with npm run lint

Node.js eslint result
18.0.0 7.0.0 pass
18.0.0 7.32.0 pass
18.0.0 8.0.0 pass
18.0.0 8.57.0 pass
18.0.0 8.57.0 pass
20.12.2 7.0.0 pass
20.12.2 8.57.0 pass
20.12.2 9.1.1 (1)(2)
22.0.0 7.0.0 pass
22.0.0 8.57.0 pass
22.0.0 9.0.0 (1)(2)

(1) Failure: (expected)
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@">=7 <9" from eslint-plugin-cypress@0.0.0-development
(2) Failure: (expected)
ESLint: 9.1.1
Error: Could not find config file.

ESLint 9.x

On Node.js 20.12.2 LTS
See also ESLint 9.x > Configuration Files (Deprecated)

npm install eslint@9 --force # to override peer dependencies
export ESLINT_USE_FLAT_CONFIG=false # to use deprecated configuration files with ESLint 9.x
npm run lint
Node.js eslint result
20.12.2 9.1.1 (3)(4)

(3) Warning from npm

$ npm install eslint@9 --force
npm WARN using --force Recommended protections disabled.
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: cypress-example-kitchensink@0.0.0-development
npm WARN Found: eslint@9.1.1
npm WARN node_modules/eslint
npm WARN   peer eslint@"^6.0.0 || ^7.0.0 || >=8.0.0" from @eslint-community/eslint-utils@4.4.0
npm WARN   node_modules/@eslint-community/eslint-utils
npm WARN     @eslint-community/eslint-utils@"^4.2.0" from eslint@9.1.1
npm WARN   4 more (eslint-plugin-json-format, eslint-plugin-mocha, ...)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer eslint@">=7 <9" from eslint-plugin-cypress@0.0.0-development
npm WARN node_modules/eslint-plugin-cypress
npm WARN   dev eslint-plugin-cypress@"github:MikeMcC399/eslint-plugin-cypress#convert-to-sourcecode" from the root project

(4) Warning from ESLint

$ npm run lint

> cypress-example-kitchensink@0.0.0-development lint
> eslint --fix cypress app/assets/js/scripts.js

(node:7547) ESLintRCWarning: You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https://eslint.org/docs/latest/use/configure/migration-guide for details.
(Use `node --trace-warnings ...` to show where the warning was created)

@MikeMcC399
Copy link
Collaborator Author

I successfully re-tested for ESLint 7.0.0 to 8.57.0 on supported Node.js versions 18.0.0 to 22.0.0.

With forced npm installation and use of the environment variable setting ESLINT_USE_FLAT_CONFIG=false it is now possible for the first time to run the plugin under ESLint 9.x. This should be viewed as experimental and unsupported at this time however. Further work is still needed on the migration to ESLint 9.x.

@MikeMcC399 MikeMcC399 marked this pull request as ready for review April 26, 2024 13:53
Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, getting so much closer!

@jennifer-shehane jennifer-shehane merged commit 429ac7f into cypress-io:master Apr 26, 2024
6 checks passed
@jennifer-shehane
Copy link
Member

@MikeMcC399 Let me know if this doesn't release. I might need to configure some keys on our side if it's still not working.

@cypress-app-bot
Copy link

🎉 This PR is included in version 3.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@MikeMcC399
Copy link
Collaborator Author

@jennifer-shehane

Let me know if this doesn't release. I might need to configure some keys on our side if it's still not working.

The release seems to have gone through with no problems. I'm beginning to think that the issue last time was just a GitHub glitch (it wouldn't be the first time)!

I'll go back to the kitchensink repo and make sure it still works there. It should be fine as far as I know.

@MikeMcC399 MikeMcC399 deleted the convert-to-sourcecode branch April 26, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eslint 8 deprecated rules context: planned failure Eslint 9
3 participants