Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 11, 2022
1 parent b3f067a commit 6984e66
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* @param {string|Uint8Array|VFile} file
*/
export function location(file) {
var value = String(file)
/** @type {Array.<number>} */
var indices = []
var search = /\r?\n|\r/g
const value = String(file)
/** @type {Array<number>} */
const indices = []
const search = /\r?\n|\r/g

while (search.test(value)) {
indices.push(search.lastIndex)
Expand All @@ -35,7 +35,7 @@ export function location(file) {
* @returns {FullPoint}
*/
function toPoint(offset) {
var index = -1
let index = -1

if (offset > -1 && offset < indices[indices.length - 1]) {
while (++index < indices.length) {
Expand All @@ -60,10 +60,10 @@ export function location(file) {
* @returns {Offset}
*/
function toOffset(point) {
var line = point && point.line
var column = point && point.column
const line = point && point.line
const column = point && point.column
/** @type {number} */
var offset
let offset

if (
typeof line === 'number' &&
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@
"trailingComma": "none"
},
"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},
"remarkConfig": {
"plugins": [
Expand Down
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {VFile} from 'vfile'
import {location} from './index.js'

test('location()', function (t) {
var place = location('')
let place = location('')

t.equals(
typeof place.toOffset,
Expand Down Expand Up @@ -32,7 +32,7 @@ test('location()', function (t) {
)

t.test('place.toOffset(point)', function (t) {
var place = location('foo\nbar\nbaz')
const place = location('foo\nbar\nbaz')

t.equals(
place.toOffset({line: undefined, column: undefined}),
Expand Down Expand Up @@ -68,7 +68,7 @@ test('location()', function (t) {
})

t.test('place.toPoint(offset)', function (t) {
var place = location('foo\nbar\nbaz')
const place = location('foo\nbar\nbaz')

t.deepEquals(
place.toPoint(-1),
Expand Down Expand Up @@ -98,7 +98,7 @@ test('location()', function (t) {
})

t.test('other tests', function (t) {
var place = location('foo')
let place = location('foo')

t.deepEquals(
[place.toPoint(3), place.toPoint(4), place.toPoint(5)],
Expand Down

0 comments on commit 6984e66

Please sign in to comment.