Skip to content

Commit 6c09da6

Browse files
enable prettier
1 parent 2bd31ba commit 6c09da6

File tree

8 files changed

+75
-50
lines changed

8 files changed

+75
-50
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function toc(node, options) {
3131

3232
/* No given heading */
3333
if (!heading) {
34-
result.index = result.endIndex = null;
34+
result.index = null;
35+
result.endIndex = null;
3536
}
3637

3738
return result;

lib/insert.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ var LINK = 'link';
2121
var TEXT = 'text';
2222

2323
/**
24-
* Insert a `node` into a `parent`.
25-
*
26-
* @param {Object} node - `node` to insert.
27-
* @param {Object} parent - Parent of `node`.
28-
* @param {boolean?} [tight] - Prefer tight list-items.
29-
* @return {undefined}
30-
*/
24+
* Insert a `node` into a `parent`.
25+
*
26+
* @param {Object} node - `node` to insert.
27+
* @param {Object} parent - Parent of `node`.
28+
* @param {boolean?} [tight] - Prefer tight list-items.
29+
* @return {undefined}
30+
*/
3131
function insert(node, parent, tight) {
3232
var children = parent.children;
3333
var length = children.length;
@@ -41,15 +41,19 @@ function insert(node, parent, tight) {
4141

4242
item.children.push({
4343
type: PARAGRAPH,
44-
children: [{
45-
type: LINK,
46-
title: null,
47-
url: '#' + node.id,
48-
children: [{
49-
type: TEXT,
50-
value: node.value
51-
}]
52-
}]
44+
children: [
45+
{
46+
type: LINK,
47+
title: null,
48+
url: '#' + node.id,
49+
children: [
50+
{
51+
type: TEXT,
52+
value: node.value
53+
}
54+
]
55+
}
56+
]
5357
});
5458

5559
children.push(item);

lib/is-opening-heading.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var HEADING = 'heading';
2424
* @return {boolean} - Whether `node` is a main heading.
2525
*/
2626
function isOpeningHeading(node, depth, expression) {
27-
return depth === null && node && node.type === HEADING &&
28-
expression.test(toString(node));
27+
return (
28+
depth === null &&
29+
node &&
30+
node.type === HEADING &&
31+
expression.test(toString(node))
32+
);
2933
}

lib/list-item.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ module.exports = listItem;
1313
var LIST_ITEM = 'listItem';
1414

1515
/**
16-
* Create a list item.
17-
*
18-
* @return {Object} - List-item node.
19-
*/
16+
* Create a list item.
17+
*
18+
* @return {Object} - List-item node.
19+
*/
2020
function listItem() {
2121
return {
2222
type: LIST_ITEM,

lib/list.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ module.exports = list;
1313
var LIST = 'list';
1414

1515
/**
16-
* Create a list.
17-
*
18-
* @return {Object} - List node.
19-
*/
16+
* Create a list.
17+
*
18+
* @return {Object} - List node.
19+
*/
2020
function list() {
2121
return {
2222
type: LIST,

lib/search.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ function search(root, expression, maxDepth) {
4848
* but only create a TOC from top-level headings.
4949
*/
5050

51-
visit(root, HEADING, function (child, index, parent) {
51+
visit(root, HEADING, function(child, index, parent) {
5252
var value = toString(child);
53-
var id = child.data && child.data.hProperties && child.data.hProperties.id;
53+
var id =
54+
child.data && child.data.hProperties && child.data.hProperties.id;
5455
id = slugs.slug(id || value);
5556

5657
if (parent !== root) {
@@ -83,7 +84,8 @@ function search(root, expression, maxDepth) {
8384
}
8485

8586
if (headingIndex === undefined) {
86-
headingIndex = closingIndex = -1;
87+
headingIndex = -1;
88+
closingIndex = -1;
8789
map = [];
8890
}
8991

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build-bundle": "browserify index.js --no-builtins -s mdastUtilTOC > mdast-util-toc.js",
1313
"build-mangle": "esmangle mdast-util-toc.js > mdast-util-toc.min.js",
1414
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
15-
"lint": "xo index.js test",
15+
"lint": "xo",
1616
"test-api": "node test/index.js",
1717
"test-coverage": "istanbul cover test/index.js",
1818
"test": "npm run build && npm run lint && npm run test-coverage"
@@ -57,6 +57,10 @@
5757
"xo": {
5858
"space": 4,
5959
"esnext": false,
60+
"prettier": true,
61+
"ignore": [
62+
"example.js"
63+
],
6064
"rules": {
6165
"valid-jsdoc": [
6266
"error"

test/index.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,41 @@ var ROOT = join(__dirname, 'fixtures');
1414

1515
var fixtures = fs.readdirSync(ROOT);
1616

17-
test('mdast-util-toc()', function (t) {
17+
test('mdast-util-toc()', function(t) {
1818
t.is(typeof toc, 'function', 'should be a function');
1919

20-
t.throws(function () {
21-
toc();
22-
}, 'Cannot read property \'children\' of undefined', 'should fail without node');
20+
t.throws(
21+
function() {
22+
toc();
23+
},
24+
"Cannot read property 'children' of undefined",
25+
'should fail without node'
26+
);
2327

2428
t.end();
2529
});
2630

27-
test('Fixtures', function (t) {
28-
fixtures.filter(function (filepath) {
29-
return filepath.indexOf('.') !== 0;
30-
}).forEach(function (fixture) {
31-
var filepath = join(ROOT, fixture);
32-
var output = JSON.parse(read(join(filepath, 'output.json'), 'utf8'));
33-
var input = remark().use(remarkAttr).parse(read(join(filepath, 'input.md'), 'utf-8'));
34-
var config = join(filepath, 'config.json');
35-
var result;
36-
37-
config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {};
38-
result = toc(input, config);
39-
40-
t.deepEqual(result, output, 'should work on `' + fixture + '`');
41-
});
31+
test('Fixtures', function(t) {
32+
fixtures
33+
.filter(function(filepath) {
34+
return filepath.indexOf('.') !== 0;
35+
})
36+
.forEach(function(fixture) {
37+
var filepath = join(ROOT, fixture);
38+
var output = JSON.parse(
39+
read(join(filepath, 'output.json'), 'utf8')
40+
);
41+
var input = remark()
42+
.use(remarkAttr)
43+
.parse(read(join(filepath, 'input.md'), 'utf-8'));
44+
var config = join(filepath, 'config.json');
45+
var result;
46+
47+
config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {};
48+
result = toc(input, config);
49+
50+
t.deepEqual(result, output, 'should work on `' + fixture + '`');
51+
});
4252

4353
t.end();
4454
});

0 commit comments

Comments
 (0)