-
Notifications
You must be signed in to change notification settings - Fork 79
feat: add support for getLocFromIndex
and getIndexFromLoc
#376
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
Merged
+137
−6
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f161cf9
feat: add support for `getLocFromIndex`
lumirlumir 963b68e
wip: migration
lumirlumir 6858970
Merge branch 'main' into feat-add-support-for-getlocfromindex
lumirlumir 3fc5bae
wip: bump dependencies
lumirlumir c10733d
wip
lumirlumir aaf82d7
wip: add type test
lumirlumir c361835
wip: tests
lumirlumir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,132 @@ describe("MarkdownSourceCode", () => { | |
}); | ||
}); | ||
|
||
describe("getLocFromIndex()", () => { | ||
it("should convert index to location correctly", () => { | ||
const text = "foo\nbar\r\nbaz"; | ||
const markdownSourceCode = new MarkdownSourceCode({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've used the 110:10 error 'sourceCode' is already declared in the upper scope on line 63 column 6 no-shadow
173:10 error 'sourceCode' is already declared in the upper scope on line 63 column 6 no-shadow |
||
text, | ||
ast: fromMarkdown(text), | ||
}); | ||
|
||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(0), { | ||
line: 1, | ||
column: 1, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(1), { | ||
line: 1, | ||
column: 2, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(2), { | ||
line: 1, | ||
column: 3, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(3), { | ||
line: 1, | ||
column: 4, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(4), { | ||
line: 2, | ||
column: 1, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(5), { | ||
line: 2, | ||
column: 2, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(6), { | ||
line: 2, | ||
column: 3, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(7), { | ||
line: 2, | ||
column: 4, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(8), { | ||
line: 2, | ||
column: 5, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(9), { | ||
line: 3, | ||
column: 1, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(10), { | ||
line: 3, | ||
column: 2, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(11), { | ||
line: 3, | ||
column: 3, | ||
}); | ||
assert.deepStrictEqual(markdownSourceCode.getLocFromIndex(12), { | ||
line: 3, | ||
column: 4, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("getIndexFromLoc()", () => { | ||
it("should convert location to index correctly", () => { | ||
const text = "foo\nbar\r\nbaz"; | ||
const markdownSourceCode = new MarkdownSourceCode({ | ||
text, | ||
ast: fromMarkdown(text), | ||
}); | ||
|
||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 1, column: 1 }), | ||
0, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 1, column: 2 }), | ||
1, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 1, column: 3 }), | ||
2, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 1, column: 4 }), | ||
3, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 2, column: 1 }), | ||
4, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 2, column: 2 }), | ||
5, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 2, column: 3 }), | ||
6, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 2, column: 4 }), | ||
7, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 2, column: 5 }), | ||
8, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 3, column: 1 }), | ||
9, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 3, column: 2 }), | ||
10, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 3, column: 3 }), | ||
11, | ||
); | ||
assert.strictEqual( | ||
markdownSourceCode.getIndexFromLoc({ line: 3, column: 4 }), | ||
12, | ||
); | ||
}); | ||
}); | ||
|
||
describe("getInlineConfigNodes()", () => { | ||
it("should return the inline config nodes", () => { | ||
const nodes = sourceCode.getInlineConfigNodes(); | ||
|
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
Oops, something went wrong.
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.
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.
As
@eslint/plugin-kit
v0.4.0 has been released, we could now continue work here?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.
There was some delay on my end with the
markdown
plugin. I'll work on it soon! 👍