Skip to content

Commit 135e8fb

Browse files
committed
Refactor code-style
1 parent c094e37 commit 135e8fb

File tree

5 files changed

+115
-126
lines changed

5 files changed

+115
-126
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
unist-util-find-after.js
3+
unist-util-find-after.min.js

index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
'use strict';
1+
'use strict'
22

3-
var is = require('unist-util-is');
3+
var is = require('unist-util-is')
44

5-
module.exports = findAfter;
5+
module.exports = findAfter
66

77
/* Find a node after `index` in `parent` which passes
88
* `test`. */
99
function findAfter(parent, index, test) {
10-
var children;
11-
var child;
12-
var length;
10+
var children
11+
var child
12+
var length
1313

1414
if (!parent || !parent.type || !parent.children) {
15-
throw new Error('Expected parent node');
15+
throw new Error('Expected parent node')
1616
}
1717

18-
children = parent.children;
19-
length = children.length;
18+
children = parent.children
19+
length = children.length
2020

2121
if (index && index.type) {
22-
index = children.indexOf(index);
22+
index = children.indexOf(index)
2323
}
2424

2525
if (isNaN(index) || index < 0 || index === Infinity) {
26-
throw new Error('Expected positive finite index or child node');
26+
throw new Error('Expected positive finite index or child node')
2727
}
2828

2929
while (++index < length) {
30-
child = children[index];
30+
child = children[index]
3131

3232
if (is(test, child, index, parent)) {
33-
return child;
33+
return child
3434
}
3535
}
3636

37-
return null;
37+
return null
3838
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,39 @@
2626
"devDependencies": {
2727
"browserify": "^16.0.0",
2828
"esmangle": "^1.0.0",
29+
"nyc": "^11.0.0",
30+
"prettier": "^1.12.1",
2931
"remark": "^9.0.0",
3032
"remark-cli": "^5.0.0",
3133
"remark-preset-wooorm": "^4.0.0",
32-
"nyc": "^11.0.0",
3334
"tape": "^4.6.2",
3435
"xo": "^0.20.0"
3536
},
3637
"scripts": {
37-
"build-md": "remark . -foq",
38+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3839
"build-bundle": "browserify index.js --no-builtins -s unistUtilFindAfter > unist-util-find-after.js",
3940
"build-mangle": "esmangle unist-util-find-after.js > unist-util-find-after.min.js",
40-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
41-
"lint": "xo",
41+
"build": "npm run build-bundle && npm run build-mangle",
4242
"test-api": "node test",
4343
"test-coverage": "nyc --reporter lcov tape test.js",
44-
"test": "npm run build && npm run lint && npm run test-coverage"
44+
"test": "npm run format && npm run build && npm run test-coverage"
4545
},
4646
"nyc": {
4747
"check-coverage": true,
4848
"lines": 100,
4949
"functions": 100,
5050
"branches": 100
5151
},
52+
"prettier": {
53+
"tabWidth": 2,
54+
"useTabs": false,
55+
"singleQuote": true,
56+
"bracketSpacing": false,
57+
"semi": false,
58+
"trailingComma": "none"
59+
},
5260
"xo": {
53-
"space": true,
61+
"prettier": true,
5462
"esnext": false,
5563
"rules": {
5664
"guard-for-in": "off",

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ npm install unist-util-find-after
1313
## Usage
1414

1515
```js
16-
var remark = require('remark');
17-
var findAfter = require('unist-util-find-after');
16+
var remark = require('remark')
17+
var findAfter = require('unist-util-find-after')
1818

19-
var tree = remark().parse('Some _emphasis_, **importance**, and `code`.');
20-
var paragraph = tree.children[0];
19+
var tree = remark().parse('Some _emphasis_, **importance**, and `code`.')
20+
var paragraph = tree.children[0]
2121

22-
console.log(findAfter(paragraph, 1, 'strong'));
22+
console.log(findAfter(paragraph, 1, 'strong'))
2323
```
2424

2525
Yields:

test.js

Lines changed: 79 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,104 @@
1-
'use strict';
1+
'use strict'
22

3-
var assert = require('assert');
4-
var test = require('tape');
5-
var remark = require('remark');
6-
var findAfter = require('.');
3+
var assert = require('assert')
4+
var test = require('tape')
5+
var remark = require('remark')
6+
var findAfter = require('.')
77

8-
var tree = remark().parse('Some _emphasis_, **importance**, and `code`.');
9-
var paragraph = tree.children[0];
10-
var children = paragraph.children;
8+
var tree = remark().parse('Some _emphasis_, **importance**, and `code`.')
9+
var paragraph = tree.children[0]
10+
var children = paragraph.children
1111

12-
test('unist-util-find-after', function (t) {
12+
test('unist-util-find-after', function(t) {
1313
t.throws(
14-
function () {
15-
findAfter();
14+
function() {
15+
findAfter()
1616
},
1717
/Expected parent node/,
1818
'should fail without parent'
19-
);
19+
)
2020

2121
t.throws(
22-
function () {
23-
findAfter({type: 'foo'});
22+
function() {
23+
findAfter({type: 'foo'})
2424
},
2525
/Expected parent node/,
2626
'should fail without parent node'
27-
);
27+
)
2828

29-
t.doesNotThrow(
30-
function () {
31-
assert.throws(
32-
function () {
33-
findAfter({type: 'foo', children: []});
34-
},
35-
/Expected positive finite index or child node/
36-
);
29+
t.doesNotThrow(function() {
30+
assert.throws(function() {
31+
findAfter({type: 'foo', children: []})
32+
}, /Expected positive finite index or child node/)
3733

38-
assert.throws(
39-
function () {
40-
findAfter({type: 'foo', children: []}, -1);
41-
},
42-
/Expected positive finite index or child node/
43-
);
34+
assert.throws(function() {
35+
findAfter({type: 'foo', children: []}, -1)
36+
}, /Expected positive finite index or child node/)
4437

45-
assert.throws(
46-
function () {
47-
findAfter({type: 'foo', children: []}, {type: 'bar'});
48-
},
49-
/Expected positive finite index or child node/
50-
);
51-
},
52-
'should fail without index'
53-
);
38+
assert.throws(function() {
39+
findAfter({type: 'foo', children: []}, {type: 'bar'})
40+
}, /Expected positive finite index or child node/)
41+
}, 'should fail without index')
5442

55-
t.doesNotThrow(
56-
function () {
57-
assert.throws(
58-
function () {
59-
findAfter({
60-
type: 'foo',
61-
children: [{type: 'bar'}, {type: 'baz'}]
62-
}, 0, false);
43+
t.doesNotThrow(function() {
44+
assert.throws(function() {
45+
findAfter(
46+
{
47+
type: 'foo',
48+
children: [{type: 'bar'}, {type: 'baz'}]
6349
},
64-
/Expected function, string, or object as test/
65-
);
50+
0,
51+
false
52+
)
53+
}, /Expected function, string, or object as test/)
6654

67-
assert.throws(
68-
function () {
69-
findAfter({
70-
type: 'foo',
71-
children: [{type: 'bar'}, {type: 'baz'}]
72-
}, 0, true);
55+
assert.throws(function() {
56+
findAfter(
57+
{
58+
type: 'foo',
59+
children: [{type: 'bar'}, {type: 'baz'}]
7360
},
74-
/Expected function, string, or object as test/
75-
);
76-
},
77-
'should fail for invalid `test`'
78-
);
61+
0,
62+
true
63+
)
64+
}, /Expected function, string, or object as test/)
65+
}, 'should fail for invalid `test`')
7966

80-
t.doesNotThrow(
81-
function () {
82-
assert.strictEqual(findAfter(paragraph, children[1]), children[2]);
83-
assert.strictEqual(findAfter(paragraph, 1), children[2]);
84-
assert.strictEqual(findAfter(paragraph, 7), null);
85-
},
86-
'should return the following node when without `test`'
87-
);
67+
t.doesNotThrow(function() {
68+
assert.strictEqual(findAfter(paragraph, children[1]), children[2])
69+
assert.strictEqual(findAfter(paragraph, 1), children[2])
70+
assert.strictEqual(findAfter(paragraph, 7), null)
71+
}, 'should return the following node when without `test`')
8872

89-
t.doesNotThrow(
90-
function () {
91-
assert.strictEqual(findAfter(paragraph, 0, children[6]), children[6]);
92-
assert.strictEqual(findAfter(paragraph, children[0], children[1]), children[1]);
93-
assert.strictEqual(findAfter(paragraph, 0, children[1]), children[1]);
94-
assert.strictEqual(findAfter(paragraph, children[0], children[0]), null);
95-
assert.strictEqual(findAfter(paragraph, 0, children[0]), null);
96-
assert.strictEqual(findAfter(paragraph, 1, children[1]), null);
97-
},
98-
'should return `node` when given a `node` and existing'
99-
);
73+
t.doesNotThrow(function() {
74+
assert.strictEqual(findAfter(paragraph, 0, children[6]), children[6])
75+
assert.strictEqual(
76+
findAfter(paragraph, children[0], children[1]),
77+
children[1]
78+
)
79+
assert.strictEqual(findAfter(paragraph, 0, children[1]), children[1])
80+
assert.strictEqual(findAfter(paragraph, children[0], children[0]), null)
81+
assert.strictEqual(findAfter(paragraph, 0, children[0]), null)
82+
assert.strictEqual(findAfter(paragraph, 1, children[1]), null)
83+
}, 'should return `node` when given a `node` and existing')
10084

101-
t.doesNotThrow(
102-
function () {
103-
assert.strictEqual(findAfter(paragraph, 0, 'strong'), children[3]);
104-
assert.strictEqual(findAfter(paragraph, 3, 'strong'), null);
105-
assert.strictEqual(findAfter(paragraph, children[0], 'strong'), children[3]);
106-
assert.strictEqual(findAfter(paragraph, children[3], 'strong'), null);
107-
},
108-
'should return a child when given a `type` and existing'
109-
);
85+
t.doesNotThrow(function() {
86+
assert.strictEqual(findAfter(paragraph, 0, 'strong'), children[3])
87+
assert.strictEqual(findAfter(paragraph, 3, 'strong'), null)
88+
assert.strictEqual(findAfter(paragraph, children[0], 'strong'), children[3])
89+
assert.strictEqual(findAfter(paragraph, children[3], 'strong'), null)
90+
}, 'should return a child when given a `type` and existing')
11091

111-
t.doesNotThrow(
112-
function () {
113-
assert.strictEqual(findAfter(paragraph, 0, test), children[5]);
114-
assert.strictEqual(findAfter(paragraph, 5, test), null);
115-
assert.strictEqual(findAfter(paragraph, children[4], test), children[5]);
116-
assert.strictEqual(findAfter(paragraph, children[6], test), null);
92+
t.doesNotThrow(function() {
93+
assert.strictEqual(findAfter(paragraph, 0, test), children[5])
94+
assert.strictEqual(findAfter(paragraph, 5, test), null)
95+
assert.strictEqual(findAfter(paragraph, children[4], test), children[5])
96+
assert.strictEqual(findAfter(paragraph, children[6], test), null)
11797

118-
function test(node, n) {
119-
return n === 5;
120-
}
121-
},
122-
'should return a child when given a `test` and existing'
123-
);
98+
function test(node, n) {
99+
return n === 5
100+
}
101+
}, 'should return a child when given a `test` and existing')
124102

125-
t.end();
126-
});
103+
t.end()
104+
})

0 commit comments

Comments
 (0)