Skip to content

Commit 9660dc7

Browse files
authored
Merge pull request #6 from syntax-tree/xo
Refactor code-style to use `xo`
2 parents c6d9454 + 7b0bde9 commit 9660dc7

File tree

13 files changed

+157
-141
lines changed

13 files changed

+157
-141
lines changed

all.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
module.exports = all
1+
'use strict';
22

3-
var trim = require('trim')
4-
var one = require('./one')
3+
module.exports = all;
54

6-
function all (h, parent) {
7-
var nodes = parent.children || []
8-
var length = nodes.length
9-
var values = []
10-
var index = -1
11-
var result
12-
var head
5+
var one = require('./one');
6+
7+
function all(h, parent) {
8+
var nodes = parent.children || [];
9+
var length = nodes.length;
10+
var values = [];
11+
var index = -1;
12+
var result;
1313

1414
while (++index < length) {
15-
result = one(h, nodes[index], parent)
15+
result = one(h, nodes[index], parent);
16+
1617
if (result) {
17-
values = values.concat(result)
18+
values = values.concat(result);
1819
}
1920
}
2021

21-
return values
22+
return values;
2223
}

handlers/emphasis.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
module.exports = emphasis
1+
'use strict';
22

3-
var u = require('unist-builder')
4-
var all = require('../all')
3+
module.exports = emphasis;
54

6-
function emphasis (h, node) {
7-
return h(node, 'emphasis', all(h, node))
5+
var all = require('../all');
6+
7+
function emphasis(h, node) {
8+
return h(node, 'emphasis', all(h, node));
89
}

handlers/heading.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
module.exports = heading
1+
'use strict';
22

3-
var u = require('unist-builder')
4-
var all = require('../all')
3+
module.exports = heading;
54

6-
function heading (h, node) {
5+
var all = require('../all');
6+
7+
function heading(h, node) {
78
var depth = Number(node.tagName.charAt(1)) || 1;
8-
return h(node, 'heading', {depth: depth}, all(h, node))
9+
return h(node, 'heading', {depth: depth}, all(h, node));
910
}

handlers/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
exports.root = require('./root')
1+
'use strict';
22

3-
exports.text = require('./text')
3+
exports.root = require('./root');
44

5-
exports.strong = exports.b = require('./strong')
6-
exports.em = exports.i = require('./emphasis')
7-
exports.code = exports.kbd = exports.samp = exports.var = require('./inline-code')
5+
exports.text = require('./text');
6+
7+
exports.strong = exports.b = require('./strong');
8+
exports.em = exports.i = require('./emphasis');
9+
exports.code = exports.kbd = exports.samp = exports.var = require('./inline-code');
10+
11+
exports.p = require('./paragraph');
812

9-
exports.p = require('./paragraph')
1013
exports.h1 = exports.h2 = exports.h3 =
11-
exports.h4 = exports.h5 = exports.h6 = require('./heading')
14+
exports.h4 = exports.h5 = exports.h6 = require('./heading');

handlers/inline-code.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
module.exports = inlineCode
1+
'use strict';
2+
3+
module.exports = inlineCode;
24

35
var toString = require('hast-util-to-string');
4-
var u = require('unist-builder')
5-
var all = require('../all')
66

7-
function inlineCode (h, node) {
8-
return h(node, 'inlineCode', toString(node))
7+
function inlineCode(h, node) {
8+
return h(node, 'inlineCode', toString(node));
99
}

handlers/paragraph.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
module.exports = p
1+
'use strict';
22

3-
var u = require('unist-builder')
4-
var all = require('../all')
3+
module.exports = paragraph;
54

5+
var all = require('../all');
66

7-
function p (h, node) {
8-
return h(node, 'paragraph', all(h, node))
7+
function paragraph(h, node) {
8+
return h(node, 'paragraph', all(h, node));
99
}

handlers/root.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
module.exports = root
1+
'use strict';
22

3-
var u = require('unist-builder')
4-
var all = require('../all')
3+
module.exports = root;
54

6-
function root (h, node) {
7-
return h(node, 'root', all(h, node))
5+
var all = require('../all');
6+
7+
function root(h, node) {
8+
return h(node, 'root', all(h, node));
89
}

handlers/strong.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
module.exports = strong
1+
'use strict';
22

3-
var u = require('unist-builder')
4-
var all = require('../all')
3+
module.exports = strong;
54

6-
function strong (h, node) {
7-
return h(node, 'strong', all(h, node))
5+
var all = require('../all');
6+
7+
function strong(h, node) {
8+
return h(node, 'strong', all(h, node));
89
}

handlers/text.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
var u = require('unist-builder')
2-
var trimLines = require('trim-lines')
1+
'use strict';
32

4-
module.exports = function text (h, node) {
3+
module.exports = text;
4+
5+
var u = require('unist-builder');
6+
var trimLines = require('trim-lines');
7+
8+
function text(h, node) {
59
if (node.value.match(/(\n+)/g)) {
6-
return null
10+
return null;
711
}
812

9-
return h.augment(node, u('text', trimLines(node.value)))
13+
return h.augment(node, u('text', trimLines(node.value)));
1014
}

index.js

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
1-
var u = require('unist-builder')
2-
var xtend = require('xtend')
1+
'use strict';
32

4-
var one = require('./one')
3+
module.exports = toMDAST;
54

6-
module.exports = function toMDAST (tree, options) {
7-
var h = factory(tree, options)
8-
var node = one(h, tree)
5+
var xtend = require('xtend');
6+
var one = require('./one');
97

10-
return node
11-
}
12-
13-
function factory (tree, options) {
14-
var settings = options || {}
15-
h.augment = augment
8+
h.augment = augment;
169

17-
return h
18-
19-
function h (node, type, props, children) {
20-
if (!children && ((typeof props === 'object' && 'length' in props) || typeof props === 'string')) {
21-
children = props
22-
props = {}
23-
}
10+
function toMDAST(tree) {
11+
return one(h, tree);
12+
}
2413

25-
var result = augment(node, {type: type})
14+
function h(node, type, props, children) {
15+
if (!children && ((typeof props === 'object' && 'length' in props) || typeof props === 'string')) {
16+
children = props;
17+
props = {};
18+
}
2619

27-
if (typeof children === 'string') {
28-
result.value = children;
29-
} else if (children) {
30-
result.children = children;
31-
}
20+
var result = augment(node, {type: type});
3221

33-
return xtend(result, props)
22+
if (typeof children === 'string') {
23+
result.value = children;
24+
} else if (children) {
25+
result.children = children;
3426
}
3527

36-
/* `right` is the finalized MDAST node,
37-
created from `left`, a HAST node */
38-
function augment (left, right) {
39-
var data
40-
var ctx
41-
42-
if (left.value) {
43-
right.value = left.value
44-
}
28+
return xtend(result, props);
29+
}
4530

46-
return right
31+
/* `right` is the finalized MDAST node,
32+
* created from `left`, a HAST node */
33+
function augment(left, right) {
34+
if (left.value) {
35+
right.value = left.value;
4736
}
37+
38+
return right;
4839
}

0 commit comments

Comments
 (0)