Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 21, 2021
1 parent b1f9134 commit 72cbf43
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -26,10 +26,10 @@ export const findAllBefore =
* @returns {Array.<Node>}
*/
function (parent, index, test) {
var is = convert(test)
const is = convert(test)
/** @type {Array.<Node>} */
var results = []
var offset = -1
const results = []
let offset = -1

if (!parent || !parent.type || !parent.children) {
throw new Error('Expected parent node')
Expand Down
6 changes: 1 addition & 5 deletions package.json
Expand Up @@ -64,11 +64,7 @@
"trailingComma": "none"
},
"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},
"remarkConfig": {
"plugins": [
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Expand Up @@ -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'),
Expand All @@ -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'))
```
Expand Down
24 changes: 12 additions & 12 deletions test.js
Expand Up @@ -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()
},
Expand All @@ -18,7 +18,7 @@ test('unist-util-find-all-before', function (t) {
)

t.throws(
function () {
() => {
// @ts-expect-error runtime.
findAllBefore({type: 'foo'})
},
Expand All @@ -27,7 +27,7 @@ test('unist-util-find-all-before', function (t) {
)

t.throws(
function () {
() => {
// @ts-expect-error runtime.
findAllBefore({type: 'foo', children: []})
},
Expand All @@ -36,23 +36,23 @@ test('unist-util-find-all-before', function (t) {
)

t.throws(
function () {
() => {
findAllBefore({type: 'foo', children: []}, -1)
},
/Expected positive finite number as index/,
'should fail without index (#2)'
)

t.throws(
function () {
() => {
findAllBefore({type: 'foo', children: []}, {type: 'bar'})
},
/Expected child node or index/,
'should fail without index (#3)'
)

t.throws(
function () {
() => {
// @ts-expect-error runtime.
findAllBefore({type: 'foo', children: [{type: 'bar'}]}, 1, false)
},
Expand All @@ -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)
},
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 72cbf43

Please sign in to comment.