Skip to content

Commit 9834f02

Browse files
committed
Refactor code-style
1 parent 3463bc1 commit 9834f02

File tree

5 files changed

+56
-33
lines changed

5 files changed

+56
-33
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-size.js
3+
unist-util-size.min.js

index.js

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

3-
module.exports = size;
3+
module.exports = size
44

55
function size(node) {
6-
var children = node && node.children;
7-
var length = (children && children.length) || 0;
8-
var count = length;
9-
var index = -1;
6+
var children = node && node.children
7+
var length = (children && children.length) || 0
8+
var count = length
9+
var index = -1
1010

1111
while (++index < length) {
12-
count += size(children[index]);
12+
count += size(children[index])
1313
}
1414

15-
return count;
15+
return count
1616
}

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,37 @@
2424
"esmangle": "^1.0.1",
2525
"hastscript": "^3.0.1",
2626
"nyc": "^11.0.0",
27+
"prettier": "^1.12.1",
2728
"remark-cli": "^5.0.0",
2829
"remark-preset-wooorm": "^4.0.0",
2930
"tape": "^4.0.0",
3031
"xo": "^0.20.0"
3132
},
3233
"scripts": {
33-
"build-md": "remark . -qfo",
34+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3435
"build-bundle": "browserify index.js --bare -s unistUtilSize > unist-util-size.js",
3536
"build-mangle": "esmangle < unist-util-size.js > unist-util-size.min.js",
36-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
37-
"lint": "xo",
37+
"build": "npm run build-bundle && npm run build-mangle",
3838
"test-api": "node test",
3939
"test-coverage": "nyc --reporter lcov tape test.js",
40-
"test": "npm run build && npm run lint && npm run test-coverage"
40+
"test": "npm run format && npm run build && npm run test-coverage"
4141
},
4242
"nyc": {
4343
"check-coverage": true,
4444
"lines": 100,
4545
"functions": 100,
4646
"branches": 100
4747
},
48+
"prettier": {
49+
"tabWidth": 2,
50+
"useTabs": false,
51+
"singleQuote": true,
52+
"bracketSpacing": false,
53+
"semi": false,
54+
"trailingComma": "none"
55+
},
4856
"xo": {
49-
"space": true,
57+
"prettier": true,
5058
"esnext": false,
5159
"rules": {
5260
"guard-for-in": "off",

readme.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ npm install unist-util-size
1313
## Usage
1414

1515
```js
16-
var h = require('hastscript');
17-
var size = require('unist-util-size');
16+
var h = require('hastscript')
17+
var size = require('unist-util-size')
1818

1919
var tree = h('div', [
20-
h('p', ['Some ', h('strong', 'importance'), ' and ', h('em', 'emphasis'), '.']),
20+
h('p', [
21+
'Some ',
22+
h('strong', 'importance'),
23+
' and ',
24+
h('em', 'emphasis'),
25+
'.'
26+
]),
2127
h('pre', h('code', 'bar()'))
22-
]);
28+
])
2329

24-
console.log(size(tree)); // 11
25-
console.log(size(tree.children[0])); // 7
26-
console.log(size(tree.children[0].children[0])); // 0
30+
console.log(size(tree)) // => 11
31+
console.log(size(tree.children[0])) // => 7
32+
console.log(size(tree.children[0].children[0])) // => 0
2733
```
2834

2935
## API

test.js

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

3-
var test = require('tape');
4-
var h = require('hastscript');
5-
var size = require('.');
3+
var test = require('tape')
4+
var h = require('hastscript')
5+
var size = require('.')
66

7-
test('unist-util-size', function (t) {
7+
test('unist-util-size', function(t) {
88
var tree = h('div', [
9-
h('p', ['Some ', h('strong', 'importance'), ' and ', h('em', 'emphasis'), '.']),
9+
h('p', [
10+
'Some ',
11+
h('strong', 'importance'),
12+
' and ',
13+
h('em', 'emphasis'),
14+
'.'
15+
]),
1016
h('pre', h('code', 'bar()'))
11-
]);
17+
])
1218

13-
t.equal(size(tree), 11, 'complete tree');
14-
t.equal(size(tree.children[0]), 7, 'parent node with mixed children');
15-
t.equal(size(tree.children[0].children[1]), 1, 'parent of text');
16-
t.equal(size(tree.children[0].children[0]), 0, 'text node');
19+
t.equal(size(tree), 11, 'complete tree')
20+
t.equal(size(tree.children[0]), 7, 'parent node with mixed children')
21+
t.equal(size(tree.children[0].children[1]), 1, 'parent of text')
22+
t.equal(size(tree.children[0].children[0]), 0, 'text node')
1723

18-
t.end();
19-
});
24+
t.end()
25+
})

0 commit comments

Comments
 (0)