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

The context.filename is undefined for inline lint in Cursor IDE #162

Open
david-vaclavek opened this issue Dec 12, 2024 · 4 comments · May be fixed by #163
Open

The context.filename is undefined for inline lint in Cursor IDE #162

david-vaclavek opened this issue Dec 12, 2024 · 4 comments · May be fixed by #163
Labels
bug Something isn't working question Further information is requested

Comments

@david-vaclavek
Copy link

Hello.

The context.filename is undefined for inline lint in Cursor IDE. I suppose it's related to the inline file lint in general.

My suggested fix is to replace

const filename = context.filename;

with

const fullFilePath = context.getFilename();
const cwd = context.getCwd();
const filename = path.relative(cwd, fullFilePath);

which works perfectly in my case.

@vitonsky
Copy link
Owner

Hi, thanks for pull request.

Why context.filename is undefined? What is inline lint and is it possible to add test that reproduce a problem, to ensure we will no more have regression for this bug in future after your fix?

@vitonsky vitonsky added bug Something isn't working question Further information is requested labels Dec 13, 2024
@david-vaclavek
Copy link
Author

Hi @vitonsky.

Let me clarify on the following screenshot:
SCR-20241213-mmgr

  1. This is the file I'm linting. By inline lint, I mean linting directly in IDE UI, not via CLI (or another script).
  2. My test console.log command, that prints the contents of context variable (3).
  3. Printed value is missing context.filename, therefore it's undefined.
  4. Replaced old version of the code (old code is demostrated in the text).
  5. If old code is present, such an error appears.

I also updated the PR to not override your default behavior. See the commit 5e4f362fa81134070904b6be95a18857d02fcbdb.

@vitonsky
Copy link
Owner

@david-vaclavek to make changes in code we have to understand the root cause.

Could you explain why context.filename is undefined for your use case?

I can't found information for such ESLint behavior, so it looks the problem related to IDE, not to ESLint plugin. If we can prove otherwise, we should reproduce this problem in tests first and then fix it. This is how we make changes on this project.

@david-vaclavek
Copy link
Author

It's likely related to the ESLint version, as we still use v7 in this project.
And although I can't find the v7 documentation anymore, context.getFilename() is listed deprecated method in v8's Custom Rules.

Therefore, I suspect this was v7's way of getting the filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants