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

New: add getPhysicalFilename() method to rule context (fixes #11989) #14616

Merged
merged 7 commits into from Jun 4, 2021
Merged

New: add getPhysicalFilename() method to rule context (fixes #11989) #14616

merged 7 commits into from Jun 4, 2021

Conversation

snitin315
Copy link
Contributor

@snitin315 snitin315 commented May 23, 2021

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[X] Other, please explain:

What changes did you make? (Give an overview)

Fix #11989

add a new getPhysicalFilename() method to the rule context object. This method will return the full path of the file on disk without any code block information.

Is there anything you'd like reviewers to focus on?

No

@eslint-github-bot eslint-github-bot bot added the triage An ESLint team member will look at this issue soon label May 23, 2021
@snitin315 snitin315 marked this pull request as ready for review May 24, 2021 04:08
@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint and removed triage An ESLint team member will look at this issue soon labels May 25, 2021
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Overall looks good. Just one question.

lib/linter/linter.js Show resolved Hide resolved
tests/lib/linter/linter.js Outdated Show resolved Hide resolved
tests/lib/linter/linter.js Show resolved Hide resolved
lib/linter/linter.js Outdated Show resolved Hide resolved
lib/linter/linter.js Outdated Show resolved Hide resolved
tests/lib/linter/linter.js Show resolved Hide resolved
@mdjermanovic mdjermanovic changed the title New: add getPhysicalFilename() method to the rule context object New: add getPhysicalFilename() method to rule context (fixes #11989) Jun 3, 2021
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@mdjermanovic mdjermanovic merged commit bb66a3d into eslint:master Jun 4, 2021
@mdjermanovic
Copy link
Member

Thanks for contributing!

@JounQin
Copy link
Contributor

JounQin commented Jul 13, 2021

@snitin315 @nzakas @mdjermanovic

I find physicalFilename is not available in ValidTestCase, so it makes testing cases for virtual filename unavailable, should that be supported?

Before context.getPhysicalFilename, I have a custom util getPhysicalFilename and a test case like:

ruleTester.run('remark', remark, {
  valid: [
    {
      code: '<header>Header2</header>',
      parser,
      parserOptions,
      filename: path.resolve(__filename, '0-fake.mdx'), // virtual filename
    },
  ],
})

But when I migrate to context.getPhysicalFilename, it results context.getPhysicalFilename() === filename, it is not correct, so maybe a new physicalFilename option is required for this case:

ruleTester.run('remark', remark, {
  valid: [
    {
      code: '<header>Header2</header>',
      parser,
      parserOptions,
      physicalFilename: __filename,
      filename: path.resolve(__filename, '0-fake.mdx'), // virtual filename
    },
  ],
})

@btmills
Copy link
Member

btmills commented Jul 14, 2021

@JounQin I'd guess we'll want to do that. Can you open an issue? People aren't as likely to see things that are part of finished discussions.

@JounQin
Copy link
Contributor

JounQin commented Jul 14, 2021

@JounQin I'd guess we'll want to do that. Can you open an issue? People aren't as likely to see things that are part of finished discussions.

See #14800

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Dec 2, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose true filename to rules
6 participants