-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat: allow specifying filename in block meta #318
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good start. I left a couple notes on some edge cases to address.
Also, can you please add some docs covering this feature?
assert.strictEqual(blocks[0].filename, "abc/def.js"); | ||
}); | ||
|
||
it("should parse a single-quoted filename in a directory from meta", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an integration test that uses ESLint to process a file with slashes in the code block filename?
I think it should work okay but I'm not 100% sure if there's some assumption that the filename doesn't have a slash somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a PR to add tests in the core to confirm this works: eslint/eslint#19425
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 235afbc what you're looking for on this end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. 👍
src/processor.js
Outdated
* @returns {string | null | undefined} The filename, if parsed from block meta. | ||
*/ | ||
function fileNameFromMeta(block) { | ||
return block.meta?.match(codeBlockFileNameRegex)?.groups.filename; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some kind of validation on the filename characters to ensure it's a valid filename. Spaces, in particular may cause problems.
I'm not sure if it would make sense to throw an error or just replace any unexpected characters with a _
(or another character).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if someone wants to have a space in the file name? Is there a source for what ESLint considers a valid filename?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not what ESLint considers a valid filename, it's what the system considers a valid filename. Because most systems require special syntax to support spaces (surround the filename in quotes), I think it's safe to assume we should not have spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Added a \s+
replacer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bit of cleanup in the docs and I think we'll be good to go pending @mdjermanovic's review.
assert.strictEqual(blocks[0].filename, "abc/def.js"); | ||
}); | ||
|
||
it("should parse a single-quoted filename in a directory from meta", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. 👍
Co-authored-by: Nicholas C. Zakas <[email protected]>
Fixes #226.
Per the RFC, does not include any name deduplication. That should already be done by ESLint itself.