From 72cbf43853d0d590e49ff30172d67812a6d7d99d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 21 Jul 2021 16:48:38 +0200 Subject: [PATCH] Refactor code-style --- index.js | 6 +++--- package.json | 6 +----- readme.md | 4 ++-- test.js | 24 ++++++++++++------------ 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 6130667..c51856d 100644 --- a/index.js +++ b/index.js @@ -26,10 +26,10 @@ export const findAllBefore = * @returns {Array.} */ function (parent, index, test) { - var is = convert(test) + const is = convert(test) /** @type {Array.} */ - var results = [] - var offset = -1 + const results = [] + let offset = -1 if (!parent || !parent.type || !parent.children) { throw new Error('Expected parent node') diff --git a/package.json b/package.json index 76d6776..4e23490 100644 --- a/package.json +++ b/package.json @@ -64,11 +64,7 @@ "trailingComma": "none" }, "xo": { - "prettier": true, - "rules": { - "no-var": "off", - "prefer-arrow-callback": "off" - } + "prettier": true }, "remarkConfig": { "plugins": [ diff --git a/readme.md b/readme.md index d412de7..763d003 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ npm install unist-util-find-all-before import {u} from 'unist-builder' import {findAllBefore} from 'unist-util-find-all-before' -var tree = u('tree', [ +const tree = u('tree', [ u('leaf', 'leaf 1'), u('node', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]), u('leaf', 'leaf 4'), @@ -37,7 +37,7 @@ var tree = u('tree', [ u('leaf', 'leaf 7') ]) -var leaf6 = tree.children[4] +const leaf6 = tree.children[4] console.log(findAllBefore(tree, leaf6, 'leaf')) ``` diff --git a/test.js b/test.js index 654cc3b..66abd81 100644 --- a/test.js +++ b/test.js @@ -2,14 +2,14 @@ import test from 'tape' import remark from 'remark' import {findAllBefore} from './index.js' -var tree = remark().parse('Some _emphasis_, **importance**, and `code`.') +const tree = remark().parse('Some _emphasis_, **importance**, and `code`.') // @ts-expect-error hush. -var paragraph = tree.children[0] -var children = paragraph.children +const paragraph = tree.children[0] +const children = paragraph.children -test('unist-util-find-all-before', function (t) { +test('unist-util-find-all-before', (t) => { t.throws( - function () { + () => { // @ts-expect-error runtime. findAllBefore() }, @@ -18,7 +18,7 @@ test('unist-util-find-all-before', function (t) { ) t.throws( - function () { + () => { // @ts-expect-error runtime. findAllBefore({type: 'foo'}) }, @@ -27,7 +27,7 @@ test('unist-util-find-all-before', function (t) { ) t.throws( - function () { + () => { // @ts-expect-error runtime. findAllBefore({type: 'foo', children: []}) }, @@ -36,7 +36,7 @@ test('unist-util-find-all-before', function (t) { ) t.throws( - function () { + () => { findAllBefore({type: 'foo', children: []}, -1) }, /Expected positive finite number as index/, @@ -44,7 +44,7 @@ test('unist-util-find-all-before', function (t) { ) t.throws( - function () { + () => { findAllBefore({type: 'foo', children: []}, {type: 'bar'}) }, /Expected child node or index/, @@ -52,7 +52,7 @@ test('unist-util-find-all-before', function (t) { ) t.throws( - function () { + () => { // @ts-expect-error runtime. findAllBefore({type: 'foo', children: [{type: 'bar'}]}, 1, false) }, @@ -61,7 +61,7 @@ test('unist-util-find-all-before', function (t) { ) t.throws( - function () { + () => { // @ts-expect-error runtime. findAllBefore({type: 'foo', children: [{type: 'bar'}]}, 1, true) }, @@ -137,7 +137,7 @@ test('unist-util-find-all-before', function (t) { 'should return children when given a `type` and existing (#4)' ) - var result = children.slice(4) + const result = children.slice(4) t.deepEqual( findAllBefore(paragraph, 100, test),