fix(core/link-to-dfn): use parentElement.closest() for scoping hint#5261
Open
marcoscaceres wants to merge 3 commits intospeced:mainfrom
Open
fix(core/link-to-dfn): use parentElement.closest() for scoping hint#5261marcoscaceres wants to merge 3 commits intospeced:mainfrom
marcoscaceres wants to merge 3 commits intospeced:mainfrom
Conversation
`elem.closest("[data-link-for]")` matches the element itself, so when
an `<a>` has `data-link-for` (e.g., from `[=bar/foo=]` syntax), the
hint incorrectly says the link is "inside" a scoped section when the
attribute is on the link itself.
Use `parentElement.closest()` to restrict to ancestor elements. Also
guard against the empty-string case (`data-link-for=""` means
intentionally unscoped).
Closes speced#5257
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an incorrect scoping hint emitted by core/link-to-dfn when reporting unresolved links, ensuring the hint only considers ancestor [data-link-for] scopes (not the <a> itself) and suppresses the hint for intentionally-unscoped data-link-for="".
Changes:
- Scope detection now uses
elem.parentElement?.closest("[data-link-for]")to avoidclosest()matching the anchor itself. - Scoping note now only appears when the found scoped ancestor has a non-empty
data-link-forvalue.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot feedback: - Add `?? null` to normalize `undefined` from optional chaining to `null`, matching the JSDoc type `HTMLElement | null` - Add test covering all 3 scoping hint cases: non-empty ancestor data-link-for (hint fires), empty data-link-for (hint omitted), and no data-link-for (hint omitted)
Contributor
Author
|
@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed? |
1 similar comment
Contributor
Author
|
@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5257
`elem.closest("[data-link-for]")` matches the element itself, so when an `` has `data-link-for` (e.g., from `[=bar/foo=]` syntax), the hint incorrectly says the link is "inside" a scoped section when the attribute is on the link itself.
Uses `parentElement.closest()` to restrict to ancestor elements. Also guards against the empty-string case (`data-link-for=""` means intentionally unscoped).