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
Expose true filename to rules #11989
Comments
@mysticatea @not-an-aardvark @nzakas Any thoughts on this use case? |
Could you elaborate on how the virtual filenames cause problems? I read import-js/eslint-plugin-import#1415 but it's not clear to me why relative paths would be broken, since it seems like resolving paths relative to the virtual filename would have the same result as resolving relative to the real filename (since the virtual filename has the same directory). |
The virtual filename is down one level from the real filename - Line 1207 in 1fb3620
|
@not-an-aardvark Is that the case? My understanding was that for a physical file (say, |
Oh I see, thanks for clarifying. |
An alternative fix might be to not alter the implied cwd for named block filenames, but instead use a query string or an extension or something? |
Sounds reasonable request. |
What's next here? I don't know how much of the way the virtual preprocessed block's filename is constructed is part of the API contract. Using a query string or appending some other string that doesn't contain a forward slash would be tidier (and would probably remove the need for an option to control which filename we wanted), but it does seem to contradict what's in the docs: https://eslint.org/docs/user-guide/configuring#specifying-processor Something to consider. I don't feel qualified to have an opinion about this. But I do think that whatever is decided to be done here, the docs should be made to be more explicit about how the filename is constructed. The current |
I'm sorry for my late response. As a fact, const { CLIEngine } = require("eslint");
const engine = new CLIEngine();
engine.executeOnText("console.log('hello')", "a-dummy-filename.js") In that case, ESLint doesn't check if the file path is valid or not. Also, Additionally, processors may make dummy filenames for each code block. It must be a path that people can distinguish between code blocks and files by glob patterns because people often use different settings for code blocks. By design, it's like the child file of the original file. (for example, yes, https://eslint.org/docs/user-guide/configuring#specifying-processor.) I feel that this is related to #12133. If we added |
You say “by design”, but to me that seems like a broken design, because making it be in a subdir changes relative paths. It should be a sibling, so that relative paths are still correct. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
This should be reopened; it affects the plugin ecosystem. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Ping again; this should remain open because it affects the plugin ecosystem. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
If we're unable to change the filename string, our remaining options are, in descending order of personal preference:
That's everything that I saw suggested already plus a couple variations. Are there any other ideas? Unless we go with the fourth option, this is no longer a breaking change and can be removed from the v8.0.0 project to be solved in any minor release. |
We can’t do option 4 because some rules rely on the return value to be unique (this is why we changed it to return filename plus code block in the first place). Options 1 or 2 seem the most viable. Option 1 feels cleaner and would seem to better match expectations but I do worry that people would forget to check codeBlock when using the filename as a cache key. So, I think I’ve talked myself into option 2. Also, removing from v8.0.0 since none of these options are breaking. |
Option 2, |
Summary: we will add a new |
Can I work on this issue? |
Let’s wait a week to see if any first-time contributors would like to take this on. If no one else steps up, then it’s all yours. |
Hi @nzakas, I would like to volunteer to work on this issue. |
@harsha0609 awesome! We'd love to have you work on this issue. Please let us know if you need any help. |
Until the issue is fixed, here's a work-around to disable affected rules for these bogus filenames. {
overrides: [
{ // Can remove after this issue is fixed: https://github.com/eslint/eslint/issues/11989
files: ['**/*.md/*_*.js'],
rules: {
'import/no-unresolved': 'off',
},
},
} Note that I'm specifically concerned about the |
@harsha0609 just checking in to see if you're still planning on working on this? No worries if not, we just want to give you the time to dig in if you want. |
Sorry for the delay @nzakas, was caught up with some work stuff, so yeah I still would love to work on this, could you please help me out with the rule context object definition for this?
|
Hi @harsha0609, looks like the object is defined here: Line 861 in 41b3570
You'll want to add a |
Thanks @pmcelhaney! @harsha0609 you’ll also likely need to pass another argument to this function: Line 833 in 41b3570
|
@nzakas went through the code, guess won't be able to work on this. Sorry for the inconvenience. |
I'll wait to see if anyone else wants to claim it, but I have a pretty good idea how to move forward, so I'll go ahead and share my thoughts. There's an options object where the filename is replaced by "blockName". Lines 1303 to 1326 in 41b3570
We would need to put a copy of the original filename in the options object in a key called Then pass |
That looks like a good approach 👍 |
Hi @pmcelhaney, are you still working on it? If not I would like to work on this one. |
@snitin315 No, I'm not working on it. Thank you for picking it up! |
#14616) * New: add `getPhysicalFilename()` method to the rule context object * Docs: update * Chore: add test * Chore: update more instances * Chore: apply suggestions * Chore: apply suggestions * Chore: fix typo Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
The version of ESLint you are using.
6.0.1
The problem you want to solve.
This. Some rules, like eslint-plugin-import's no-unresolved, need to know the true path of the current file, not a path that's been potentially assembled using a processor's named code block.
Your take on the correct solution to problem.
I'm not entirely sure, but perhaps a new option to
context.getFilename()
to return the true path rather than the one potentially created from a processor's named code blocks.Are you willing to submit a pull request to implement this change?
Yes.
The text was updated successfully, but these errors were encountered: