eslint-mdx: [v2] incorrect comment loc info

Initial checklist

Affected packages and versions

2.0.0.next.1

Link to runnable example

No response

Steps to reproduce

{/* First */}

<Story>
  {{
    template: /* HTML */ ``,
  }}
</Story>

print with console.log(JSON.stringify(node.data?.estree.comments || [], null, 2))

Expected behavior

The second comment should start with line: 5, column: 14 and end with line: 5, column: 24

Actual behavior

[
  {
    "type": "Block",
    "value": " First ",
    "start": 1,
    "end": 12,
    "loc": {
      "start": {
        "line": 1,
        "column": 1
      },
      "end": {
        "line": 1,
        "column": 12
      }
    },
    "range": [
      1,
      12
    ]
  }
]
[
  {
    "type": "Block",
    "value": " HTML ",
    "start": 42,
    "end": 52,
    "loc": {
      "start": {
        "line": 4,
        "column": 19
      },
      "end": {
        "line": 4,
        "column": 29
      }
    },
    "range": [
      42,
      52
    ]
  }
]

Runtime

Node v16

Package manager

yarn v1

OS

macOS

Build and bundle tools

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (15 by maintainers)

Commits related to this issue

Most upvoted comments

done

I’m not sure how I came up with the previous logic. I made a little algorithm locally that works and is much simpler. I’ll have to make the code pretty and add test it all, but should have it ready soon!

The first comment is correct, right?

<del> Should the `column` of `unified` node be `1`-indexed? (`acorn`'s is `0`-indexed). </del>

I forgot it’s in estree.

Btw, I don’t think the code makes sense? Why is there an object as the child of Story

This is how storybook for Angular works.

OK, I will give it a try today.

any reason you’re not on a stable v2?

2.0.0.next.1 is eslint-mdx

parsing of each “chunk” of JS-in-markdown happens from 1:1, and then a starting position as added onto it, I guess this is happening for nodes, but not for comments

So this is a known issue? Are you going to fix it?