Skip to content

Commit fa93dc8

Browse files
committed
Refactor code-style
1 parent c55e2ec commit fa93dc8

File tree

5 files changed

+78
-60
lines changed

5 files changed

+78
-60
lines changed

.prettierignore

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

index.js

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

3-
var slug = require('remark-slug');
4-
var util = require('mdast-util-toc');
3+
var slug = require('remark-slug')
4+
var util = require('mdast-util-toc')
55

6-
module.exports = toc;
6+
module.exports = toc
77

8-
var DEFAULT_HEADING = 'toc|table[ -]of[ -]contents?';
8+
var DEFAULT_HEADING = 'toc|table[ -]of[ -]contents?'
99

1010
function toc(options) {
11-
var settings = options || {};
12-
var heading = settings.heading || DEFAULT_HEADING;
13-
var depth = settings.maxDepth || 6;
14-
var tight = settings.tight;
11+
var settings = options || {}
12+
var heading = settings.heading || DEFAULT_HEADING
13+
var depth = settings.maxDepth || 6
14+
var tight = settings.tight
1515

16-
this.use(slug);
16+
this.use(slug)
1717

18-
return transformer;
18+
return transformer
1919

2020
/* Adds an example section based on a valid example
2121
* JavaScript document to a `Usage` section. */
@@ -24,17 +24,17 @@ function toc(options) {
2424
heading: heading,
2525
maxDepth: depth,
2626
tight: tight
27-
});
27+
})
2828

2929
if (result.index === null || result.index === -1 || !result.map) {
30-
return;
30+
return
3131
}
3232

3333
/* Replace markdown. */
3434
node.children = [].concat(
3535
node.children.slice(0, result.index),
3636
result.map,
3737
node.children.slice(result.endIndex)
38-
);
38+
)
3939
}
4040
}

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"is-hidden": "^1.1.0",
3535
"negate": "^1.0.0",
3636
"nyc": "^12.0.0",
37+
"prettier": "^1.14.2",
3738
"remark": "^9.0.0",
3839
"remark-cli": "^5.0.0",
3940
"remark-preset-wooorm": "^4.0.0",
@@ -42,17 +43,24 @@
4243
"xo": "^0.22.0"
4344
},
4445
"scripts": {
45-
"build-md": "remark *.md -qfo",
46+
"format": "remark *.md -qfo && prettier --write \"**/*.js\" && xo --fix",
4647
"build-bundle": "browserify . -s remarkToc > remark-toc.js",
4748
"build-mangle": "browserify . -s remarkToc -p tinyify > remark-toc.min.js",
48-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
49-
"lint": "xo",
49+
"build": "npm run build-bundle && npm run build-mangle",
5050
"test-api": "node test",
5151
"test-coverage": "nyc --reporter lcov tape test/index.js",
52-
"test": "npm run build && npm run lint && npm run test-coverage"
52+
"test": "npm run format && npm run build && npm run test-coverage"
53+
},
54+
"prettier": {
55+
"tabWidth": 2,
56+
"useTabs": false,
57+
"singleQuote": true,
58+
"bracketSpacing": false,
59+
"semi": false,
60+
"trailingComma": "none"
5361
},
5462
"xo": {
55-
"space": true,
63+
"prettier": true,
5664
"esnext": false,
5765
"ignores": [
5866
"remark-toc.js"

readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ Say we have the following file, `example.md`:
2929
And our script, `example.js`, looks as follows:
3030

3131
```javascript
32-
var vfile = require('to-vfile');
33-
var remark = require('remark');
34-
var toc = require('remark-toc');
32+
var vfile = require('to-vfile')
33+
var remark = require('remark')
34+
var toc = require('remark-toc')
3535

3636
remark()
3737
.use(toc)
38-
.process(vfile.readSync('example.md'), function (err, file) {
39-
if (err) throw err;
40-
console.log(String(file));
41-
});
38+
.process(vfile.readSync('example.md'), function(err, file) {
39+
if (err) throw err
40+
console.log(String(file))
41+
})
4242
```
4343

4444
Now, running `node example` yields:

test/index.js

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var fs = require('fs');
5-
var path = require('path');
6-
var remark = require('remark');
7-
var negate = require('negate');
8-
var hidden = require('is-hidden');
9-
var toc = require('..');
3+
var test = require('tape')
4+
var fs = require('fs')
5+
var path = require('path')
6+
var remark = require('remark')
7+
var negate = require('negate')
8+
var hidden = require('is-hidden')
9+
var toc = require('..')
1010

11-
var read = fs.readFileSync;
12-
var exists = fs.existsSync;
13-
var join = path.join;
11+
var read = fs.readFileSync
12+
var join = path.join
1413

15-
var ROOT = join(__dirname, 'fixtures');
14+
var ROOT = join(__dirname, 'fixtures')
1615

17-
var fixtures = fs.readdirSync(ROOT);
16+
var fixtures = fs.readdirSync(ROOT)
1817

1918
function process(value, config) {
20-
return remark().use(toc, config).processSync(value).toString();
19+
return remark()
20+
.use(toc, config)
21+
.processSync(value)
22+
.toString()
2123
}
2224

23-
test('remark-toc()', function (t) {
24-
t.equal(typeof toc, 'function', 'should be a function');
25+
test('remark-toc()', function(t) {
26+
t.equal(typeof toc, 'function', 'should be a function')
2527

26-
t.doesNotThrow(function () {
27-
toc.call(remark());
28-
}, 'should not throw if not passed options');
28+
t.doesNotThrow(function() {
29+
toc.call(remark())
30+
}, 'should not throw if not passed options')
2931

30-
t.end();
31-
});
32+
t.end()
33+
})
3234

33-
test('Fixtures', function (t) {
34-
fixtures.filter(negate(hidden)).forEach(function (fixture) {
35-
var filepath = join(ROOT, fixture);
36-
var output = read(join(filepath, 'output.md'), 'utf-8');
37-
var input = read(join(filepath, 'input.md'), 'utf-8');
38-
var config = join(filepath, 'config.json');
39-
var result;
35+
test('Fixtures', function(t) {
36+
fixtures.filter(negate(hidden)).forEach(function(fixture) {
37+
var filepath = join(ROOT, fixture)
38+
var output = read(join(filepath, 'output.md'), 'utf-8')
39+
var input = read(join(filepath, 'input.md'), 'utf-8')
40+
var config
41+
var result
4042

41-
config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {};
42-
result = process(input, config);
43+
try {
44+
config = JSON.parse(read(join(filepath, 'config.json')))
45+
} catch (err) {
46+
config = {}
47+
}
4348

44-
t.equal(result, output, 'should work on `' + fixture + '`');
45-
});
49+
result = process(input, config)
4650

47-
t.end();
48-
});
51+
t.equal(result, output, 'should work on `' + fixture + '`')
52+
})
53+
54+
t.end()
55+
})

0 commit comments

Comments
 (0)