Skip to content

Conversation

@david-vaclavek
Copy link

@david-vaclavek david-vaclavek commented Dec 12, 2024

Fixes #162


const filename = context.filename;
let filename = context.filename;
if (typeof filename === 'undefined') {
Copy link
Owner

Choose a reason for hiding this comment

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

Currently this code just hides a problem for exists test cases.

Let's add tests that reproduce original problem from issue, and make sure all other tests will be run for that case too.

Copy link
Author

@david-vaclavek david-vaclavek Dec 16, 2024

Choose a reason for hiding this comment

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

@vitonsky
I'm not sure it is possible to properly cover it with the tests.

See the screenshot:

image

  1. Sample updated test.
  2. Test console.log statement.
  3. console.log output, which proves that both context.filename and context.getFilename() return the same value. If filename in test definition would be undefined, then both values are also undefined. It's not possible to pass getFilename: () => {...} function into test definition, as it's not part of the interface.

My conclusion:
Testing the behavior of context.getFilename() in ESLint can be done using the RuleTester class by passing a filename property in the test cases. It's a part of ESLint 7 usage that context.getFilename() must be used.

Reading the statement above, how exactly would you like me to cover it with tests? Could you provide an example?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants