Skip to content

Commit 1be95f1

Browse files
committed
Refactor code-style
1 parent 05dd4ae commit 1be95f1

File tree

111 files changed

+5305
-4553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+5305
-4553
lines changed

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
remark.js
3+
remark.min.js

package.json

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"mdast-util-compact": "^1.0.0",
1919
"mdast-zone": "^3.0.1",
2020
"nyc": "^13.0.0",
21+
"prettier": "^1.14.3",
2122
"remark-preset-wooorm": "^4.0.0",
2223
"tape": "^4.5.1",
2324
"tinyify": "^2.4.3",
@@ -30,25 +31,32 @@
3031
},
3132
"scripts": {
3233
"postinstall": "lerna bootstrap",
33-
"build-md": "packages/remark-cli/cli.js . -qfo",
34+
"format": "packages/remark-cli/cli.js . -qfo && prettier --write '**/*.js' && xo --fix",
3435
"build-bundle": "browserify packages/remark -s remark > remark.js",
3536
"build-mangle": "browserify packages/remark -s remark -p tinyify > remark.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/api",
3939
"test-api-extensive": "TEST_EXTENDED=true node test/api",
4040
"test-cli": "node test/cli.js",
4141
"test-coverage": "nyc --reporter lcov tape test",
42-
"test": "npm run build && npm run lint && npm run test-coverage"
42+
"test": "npm run format && npm run build && npm run test-coverage"
4343
},
4444
"nyc": {
4545
"check-coverage": true,
4646
"lines": 100,
4747
"functions": 100,
4848
"branches": 100
4949
},
50+
"prettier": {
51+
"tabWidth": 2,
52+
"useTabs": false,
53+
"singleQuote": true,
54+
"bracketSpacing": false,
55+
"semi": false,
56+
"trailingComma": "none"
57+
},
5058
"xo": {
51-
"space": true,
59+
"prettier": true,
5260
"esnext": false,
5361
"rules": {
5462
"import/no-unassigned-import": "off",

packages/remark-cli/cli.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
2-
'use strict';
2+
'use strict'
33

4-
var start = require('unified-args');
5-
var extensions = require('markdown-extensions');
6-
var processor = require('remark');
7-
var proc = require('remark/package.json');
8-
var cli = require('./package.json');
4+
var start = require('unified-args')
5+
var extensions = require('markdown-extensions')
6+
var processor = require('remark')
7+
var proc = require('remark/package.json')
8+
var cli = require('./package.json')
99

1010
start({
1111
processor: processor,
@@ -21,4 +21,4 @@ start({
2121
rcName: '.' + proc.name + 'rc',
2222
ignoreName: '.' + proc.name + 'ignore',
2323
extensions: extensions
24-
});
24+
})

packages/remark-parse/index.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
'use strict';
1+
'use strict'
22

3-
var unherit = require('unherit');
4-
var xtend = require('xtend');
5-
var Parser = require('./lib/parser.js');
3+
var unherit = require('unherit')
4+
var xtend = require('xtend')
5+
var Parser = require('./lib/parser.js')
66

7-
module.exports = parse;
8-
parse.Parser = Parser;
7+
module.exports = parse
8+
parse.Parser = Parser
99

1010
function parse(options) {
11-
var Local = unherit(Parser);
12-
Local.prototype.options = xtend(Local.prototype.options, this.data('settings'), options);
13-
this.Parser = Local;
11+
var settings = this.data('settings')
12+
var Local = unherit(Parser)
13+
14+
Local.prototype.options = xtend(Local.prototype.options, settings, options)
15+
16+
this.Parser = Local
1417
}

packages/remark-parse/lib/decode.js

+29-35
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,34 @@
1-
'use strict';
1+
'use strict'
22

3-
var xtend = require('xtend');
4-
var entities = require('parse-entities');
3+
var xtend = require('xtend')
4+
var entities = require('parse-entities')
55

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

8-
/* Factory to create an entity decoder. */
8+
// Factory to create an entity decoder.
99
function factory(ctx) {
10-
decoder.raw = decodeRaw;
10+
decoder.raw = decodeRaw
1111

12-
return decoder;
12+
return decoder
1313

14-
/* Normalize `position` to add an `indent`. */
14+
// Normalize `position` to add an `indent`.
1515
function normalize(position) {
16-
var offsets = ctx.offset;
17-
var line = position.line;
18-
var result = [];
16+
var offsets = ctx.offset
17+
var line = position.line
18+
var result = []
1919

2020
while (++line) {
2121
if (!(line in offsets)) {
22-
break;
22+
break
2323
}
2424

25-
result.push((offsets[line] || 0) + 1);
25+
result.push((offsets[line] || 0) + 1)
2626
}
2727

28-
return {
29-
start: position,
30-
indent: result
31-
};
28+
return {start: position, indent: result}
3229
}
3330

34-
/* Handle a warning.
35-
* See https://github.com/wooorm/parse-entities
36-
* for the warnings. */
37-
function handleWarning(reason, position, code) {
38-
if (code === 3) {
39-
return;
40-
}
41-
42-
ctx.file.message(reason, position);
43-
}
44-
45-
/* Decode `value` (at `position`) into text-nodes. */
31+
// Decode `value` (at `position`) into text-nodes.
4632
function decoder(value, position, handler) {
4733
entities(value, {
4834
position: normalize(position),
@@ -51,14 +37,22 @@ function factory(ctx) {
5137
reference: handler,
5238
textContext: ctx,
5339
referenceContext: ctx
54-
});
40+
})
5541
}
5642

57-
/* Decode `value` (at `position`) into a string. */
43+
// Decode `value` (at `position`) into a string.
5844
function decodeRaw(value, position, options) {
59-
return entities(value, xtend(options, {
60-
position: normalize(position),
61-
warning: handleWarning
62-
}));
45+
return entities(
46+
value,
47+
xtend(options, {position: normalize(position), warning: handleWarning})
48+
)
49+
}
50+
51+
// Handle a warning.
52+
// See <https://github.com/wooorm/parse-entities> for the warnings.
53+
function handleWarning(reason, position, code) {
54+
if (code !== 3) {
55+
ctx.file.message(reason, position)
56+
}
6357
}
6458
}

packages/remark-parse/lib/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
'use strict'
22

33
module.exports = {
44
position: true,
@@ -7,4 +7,4 @@ module.exports = {
77
footnotes: false,
88
pedantic: false,
99
blocks: require('./block-elements.json')
10-
};
10+
}
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
var index = value.indexOf('\n', fromIndex);
6+
var index = value.indexOf('\n', fromIndex)
77

88
while (index > fromIndex) {
99
if (value.charAt(index - 1) !== ' ') {
10-
break;
10+
break
1111
}
1212

13-
index--;
13+
index--
1414
}
1515

16-
return index;
16+
return index
1717
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
return value.indexOf('`', fromIndex);
6+
return value.indexOf('`', fromIndex)
77
}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
return value.indexOf('~~', fromIndex);
6+
return value.indexOf('~~', fromIndex)
77
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
var asterisk = value.indexOf('*', fromIndex);
7-
var underscore = value.indexOf('_', fromIndex);
6+
var asterisk = value.indexOf('*', fromIndex)
7+
var underscore = value.indexOf('_', fromIndex)
88

99
if (underscore === -1) {
10-
return asterisk;
10+
return asterisk
1111
}
1212

1313
if (asterisk === -1) {
14-
return underscore;
14+
return underscore
1515
}
1616

17-
return underscore < asterisk ? underscore : asterisk;
17+
return underscore < asterisk ? underscore : asterisk
1818
}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
return value.indexOf('\\', fromIndex);
6+
return value.indexOf('\\', fromIndex)
77
}
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
var link = value.indexOf('[', fromIndex);
7-
var image = value.indexOf('![', fromIndex);
6+
var link = value.indexOf('[', fromIndex)
7+
var image = value.indexOf('![', fromIndex)
88

99
if (image === -1) {
10-
return link;
10+
return link
1111
}
1212

13-
/* Link can never be `-1` if an image is found, so we don’t need
14-
* to check for that :) */
15-
return link < image ? link : image;
13+
// Link can never be `-1` if an image is found, so we don’t need to check
14+
// for that :)
15+
return link < image ? link : image
1616
}
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
var asterisk = value.indexOf('**', fromIndex);
7-
var underscore = value.indexOf('__', fromIndex);
6+
var asterisk = value.indexOf('**', fromIndex)
7+
var underscore = value.indexOf('__', fromIndex)
88

99
if (underscore === -1) {
10-
return asterisk;
10+
return asterisk
1111
}
1212

1313
if (asterisk === -1) {
14-
return underscore;
14+
return underscore
1515
}
1616

17-
return underscore < asterisk ? underscore : asterisk;
17+
return underscore < asterisk ? underscore : asterisk
1818
}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
1+
'use strict'
22

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

55
function locate(value, fromIndex) {
6-
return value.indexOf('<', fromIndex);
6+
return value.indexOf('<', fromIndex)
77
}
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
'use strict';
1+
'use strict'
22

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

5-
var PROTOCOLS = ['https://', 'http://', 'mailto:'];
5+
var protocols = ['https://', 'http://', 'mailto:']
66

77
function locate(value, fromIndex) {
8-
var length = PROTOCOLS.length;
9-
var index = -1;
10-
var min = -1;
11-
var position;
8+
var length = protocols.length
9+
var index = -1
10+
var min = -1
11+
var position
1212

1313
if (!this.options.gfm) {
14-
return -1;
14+
return -1
1515
}
1616

1717
while (++index < length) {
18-
position = value.indexOf(PROTOCOLS[index], fromIndex);
18+
position = value.indexOf(protocols[index], fromIndex)
1919

2020
if (position !== -1 && (position < min || min === -1)) {
21-
min = position;
21+
min = position
2222
}
2323
}
2424

25-
return min;
25+
return min
2626
}

0 commit comments

Comments
 (0)