fix: guard for missing position in no-invalid-label-refs#620
fix: guard for missing position in no-invalid-label-refs#620DMartens wants to merge 2 commits intoeslint:mainfrom
Conversation
|
Thanks for investigating. Under what circumstances is a node created without a I don't think we should just ignore nodes without |
|
The problem is not that we cannot get the position but that the one
Currently the node listens for |
lumirlumir
left a comment
There was a problem hiding this comment.
Currently, all Markdown rules assume every node has a position property. I think this change is only a workaround for a quick fix, not a fundamental solution.
I've examined various Markdown AST cases, and in my experience the only time a node lacks position is when the mode is GFM and the node contains autolink literals. I encountered the same issue while working on #597, but at the time I didn't have enough time to investigate further, so I left it as-is.
Therefore, I strongly suspect the missing position is a parser bug rather than something that can be fundamentally fixed here. If we proceed in this direction, the fix would need to be applied across all Markdown rules, since nodes without a position property can occur elsewhere.
Looking at mdast-util-from-markdown and micromark, the tokenizer and parser don't clearly state when a node's position property is included or not, but in almost every case the AST includes position, it only seems to be missing in certain scenarios, so I suspect the bug is more likely caused by a specific extension in GFM mode.
|
As I said this is a quick band aid fix to make sure this rule does not crash. |
|
I agree with @lumirlumir in that every rule expects every node to have a While I don't mind a temporary solution, I think that solution should get to attempt to calculate the actual position inside of |
|
How should the position be calculated as we cannot make any assumptions of the context.
I think we should rather return |
|
Handling in each rule is a footgun that will be easy to forget and a pain to remember to fix later. I don't see that as a valid option. Can we not look for |
|
I thought that you meant we should try to get to position in the general case, not for this specific case. As lumir mentioned he also encountered missing In this specific case all three nodes do not have a position:
Adding characters after
So we would also need to handle that. |
|
After further investigation, I found this pattern only occurs when The cases below all include https://example.com
http://example.com
xxx@google.comHowever, the cases below do not (the number of whitespace characters after [https://example.com
[ https://example.com
[http://example.com
[ http://example.com
[xxx@google.com
[ xxx@google.comIf a quick workaround doesn't make sense, I think waiting for the |
Prerequisites checklist
What is the purpose of this pull request?
The GFM parser can create nodes without a
positionproperty for example as reported in #619.The example code "Hello [World][https://example.com]" is split into 3 subnodes while the commonmark parser keeps it a single text node.
What changes did you make? (Give an overview)
Ignore
textnodes without apositionproperty.This leaves the example code as a false negative but for a proper fix we would need to rethink how the rule works.
Related Issues
Fixes #619
Is there anything you'd like reviewers to focus on?
Should we also check other rules for a potentially missing
positionproperty?