From 6984e6654de42404cfa5d7043735ce3c93e6f6f0 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 11 Jun 2022 20:47:14 +0200 Subject: [PATCH] Refactor code-style --- index.js | 16 ++++++++-------- package.json | 6 +----- test.js | 8 ++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index c8a5feb..950532d 100644 --- a/index.js +++ b/index.js @@ -13,10 +13,10 @@ * @param {string|Uint8Array|VFile} file */ export function location(file) { - var value = String(file) - /** @type {Array.} */ - var indices = [] - var search = /\r?\n|\r/g + const value = String(file) + /** @type {Array} */ + const indices = [] + const search = /\r?\n|\r/g while (search.test(value)) { indices.push(search.lastIndex) @@ -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) { @@ -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' && diff --git a/package.json b/package.json index 45b6a93..76ac693 100644 --- a/package.json +++ b/package.json @@ -67,11 +67,7 @@ "trailingComma": "none" }, "xo": { - "prettier": true, - "rules": { - "no-var": "off", - "prefer-arrow-callback": "off" - } + "prettier": true }, "remarkConfig": { "plugins": [ diff --git a/test.js b/test.js index 9dcb896..b4dab22 100644 --- a/test.js +++ b/test.js @@ -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, @@ -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}), @@ -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), @@ -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)],