Skip to content

Conversation

@tylermumford
Copy link

Summary

On RuleContext objects, use the filename property instead of the deprecated getFilename() method. That method was marked as deprecated in ESLint v8 and is removed in ESLint v10.

Motivation

I'm preparing a company project for ESLint v10, and I get an error that eslint-plugin-react uses a method that doesn't exist on the RuleContext object.

(Hello, this is my first PR on this repo. I hope to be helpful and respectful.)

@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​types/​eslint@​7.2.10 ⏵ 8.56.121001007880100

View full report

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

It'd be interesting to also add tests that run in eslint 10.


create(context) {
const filename = context.getFilename();
const filename = context.filename;
Copy link
Member

Choose a reason for hiding this comment

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

it's probably safer to do this since we still support much older eslint versions?

Suggested change
const filename = context.filename;
const filename = context.filename || context.getFilename();

function resolveBasedir(contextOrFilename) {
if (contextOrFilename) {
const filename = typeof contextOrFilename === 'string' ? contextOrFilename : contextOrFilename.getFilename();
const filename = typeof contextOrFilename === 'string' ? contextOrFilename : contextOrFilename.filename;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const filename = typeof contextOrFilename === 'string' ? contextOrFilename : contextOrFilename.filename;
const filename = typeof contextOrFilename === 'string' ? contextOrFilename : contextOrFilename.filename || contextOrFileName.getFilename();

"@babel/plugin-syntax-function-bind": "^7.27.1",
"@babel/preset-react": "^7.27.1",
"@types/eslint": "=7.2.10",
"@types/eslint": "=8.56.12",
Copy link
Member

Choose a reason for hiding this comment

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

we still support eslint 7 so i'm not sure we can upgrade the types - and if we do we'd use ^, not =

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants