Skip to content

Commit

Permalink
Merge pull request #1932 from romainmenke/fix-warning-end-index--inve…
Browse files Browse the repository at this point in the history
…ntive-numbat-fbada42105

Fix resulting `end` position when `endIndex` is `0` for `rangeBy`
  • Loading branch information
ai committed Mar 20, 2024
2 parents 0fd1d86 + b45e7e9 commit c1ad8fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/node.js
Expand Up @@ -241,7 +241,7 @@ class Node {
column: opts.end.column,
line: opts.end.line
}
} else if (opts.endIndex) {
} else if (typeof opts.endIndex === 'number') {
end = this.positionInside(opts.endIndex)
} else if (opts.index) {
end = this.positionInside(opts.index + 1)
Expand Down
18 changes: 18 additions & 0 deletions test/warning.test.ts
Expand Up @@ -85,6 +85,24 @@ test('gets range from node without end', () => {
is(warning.endColumn, 2)
})

test('gets range from node with endIndex 3', () => {
let root = parse('a{}')
let warning = new Warning('text', { node: root.first, index: 0, endIndex: 3 })
is(warning.line, 1)
is(warning.column, 1)
is(warning.endLine, 1)
is(warning.endColumn, 4)
})

test('gets range from node with endIndex 0', () => {
let root = parse('a{}')
let warning = new Warning('text', { node: root.first, index: 0, endIndex: 0 })
is(warning.line, 1)
is(warning.column, 1)
is(warning.endLine, 1)
is(warning.endColumn, 2)
})

test('gets range from word', () => {
let root = parse('a b{}')
let warning = new Warning('text', { node: root.first, word: 'b' })
Expand Down

0 comments on commit c1ad8fb

Please sign in to comment.