Skip to content

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

Merged
mdjermanovic merged 7 commits into
eslint:masterfrom
snitin315:physical-file-name
Jun 4, 2021
Merged

mdjermanovic merged 7 commits into
eslint:masterfrom
snitin315:physical-file-name

Conversation

@snitin315

@snitin315 snitin315 commented May 23, 2021 •

Copy link
Copy Markdown
Contributor

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

@nzakas nzakas left a comment

Copy link
Copy Markdown
Member

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.

Comment thread lib/linter/linter.js
Comment thread docs/developer-guide/working-with-rules.md Outdated
Comment thread tests/lib/linter/linter.js Outdated
Comment thread tests/lib/linter/linter.js
Comment thread tests/lib/linter/linter.js Outdated
Comment thread lib/linter/linter.js Outdated
Comment thread lib/linter/linter.js Outdated
Comment thread tests/lib/linter/linter.js
Comment thread tests/lib/linter/linter.js Outdated
@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
Comment thread tests/lib/linter/linter.js Outdated
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

@mdjermanovic mdjermanovic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@nzakas nzakas left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

Thanks for contributing!

@JounQin

JounQin commented Jul 13, 2021

Copy link
Copy Markdown
Contributor

@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

btmills commented Jul 14, 2021

Copy link
Copy Markdown
Member

@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

JounQin commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

@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