Skip to content

Commit de18d7d

Browse files
committed
Refactor code-style
1 parent 0ecce3b commit de18d7d

20 files changed

+473
-476
lines changed

.prettierignore

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

index.js

+106-71
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
'use strict';
1+
'use strict'
22

3-
/* Dependencies. */
4-
var assert = require('assert');
5-
var array = require('x-is-array');
6-
var zwitch = require('zwitch');
7-
var mapz = require('mapz');
8-
var unist = require('unist-util-assert');
3+
var assert = require('assert')
4+
var array = require('x-is-array')
5+
var zwitch = require('zwitch')
6+
var mapz = require('mapz')
7+
var unist = require('unist-util-assert')
98

109
/* Construct. */
11-
var mdast = zwitch('type');
10+
var mdast = zwitch('type')
1211

1312
/* Expose. */
14-
exports = unist.wrap(mdast);
15-
module.exports = exports;
13+
exports = unist.wrap(mdast)
14+
module.exports = exports
1615

17-
exports.parent = unist.wrap(parent);
18-
exports.text = unist.text;
19-
exports.void = unist.void;
20-
exports.wrap = unist.wrap;
21-
exports.all = mapz(exports, {key: 'children', indices: false});
16+
exports.parent = unist.wrap(parent)
17+
exports.text = unist.text
18+
exports.void = unist.void
19+
exports.wrap = unist.wrap
20+
exports.all = mapz(exports, {key: 'children', indices: false})
2221

2322
/* Core interface. */
24-
mdast.unknown = unknown;
25-
mdast.invalid = unknown;
23+
mdast.unknown = unknown
24+
mdast.invalid = unknown
2625

2726
/* Per-type handling. */
2827
mdast.handlers = {
@@ -53,184 +52,220 @@ mdast.handlers = {
5352
footnoteReference: unist.wrap(footnoteReference),
5453
table: unist.wrap(table),
5554
html: exports.text
56-
};
55+
}
5756

5857
function unknown(node, ancestor) {
59-
unist(node, ancestor);
58+
unist(node, ancestor)
6059
}
6160

6261
function parent(node) {
63-
unist.parent(node);
64-
exports.all(node);
62+
unist.parent(node)
63+
exports.all(node)
6564
}
6665

6766
function root(node, ancestor) {
68-
parent(node);
67+
parent(node)
6968

70-
assert.strictEqual(ancestor, undefined, '`root` should not have a parent');
69+
assert.strictEqual(ancestor, undefined, '`root` should not have a parent')
7170
}
7271

7372
function list(node) {
74-
parent(node);
73+
parent(node)
7574

7675
if (node.loose != null) {
77-
assert.strictEqual(typeof node.loose, 'boolean', '`loose` must be `boolean`');
76+
assert.strictEqual(
77+
typeof node.loose,
78+
'boolean',
79+
'`loose` must be `boolean`'
80+
)
7881
}
7982

8083
if (node.ordered != null) {
81-
assert.strictEqual(typeof node.ordered, 'boolean', '`ordered` must be `boolean`');
84+
assert.strictEqual(
85+
typeof node.ordered,
86+
'boolean',
87+
'`ordered` must be `boolean`'
88+
)
8289
}
8390

8491
if (!node.ordered) {
85-
assert.ok(node.start == null, 'unordered lists must not have `start`');
92+
assert.ok(node.start == null, 'unordered lists must not have `start`')
8693
} else if (node.start != null) {
87-
assert.strictEqual(typeof node.start, 'number', 'ordered lists must have `start`');
88-
assert.ok(node.start >= 0, '`start` must be gte `0`');
94+
assert.strictEqual(
95+
typeof node.start,
96+
'number',
97+
'ordered lists must have `start`'
98+
)
99+
assert.ok(node.start >= 0, '`start` must be gte `0`')
89100
}
90101
}
91102

92103
function listItem(node) {
93-
parent(node);
104+
parent(node)
94105

95106
if (node.loose != null) {
96-
assert.strictEqual(typeof node.loose, 'boolean', '`loose` must be `boolean`');
107+
assert.strictEqual(
108+
typeof node.loose,
109+
'boolean',
110+
'`loose` must be `boolean`'
111+
)
97112
}
98113

99114
if (node.checked != null) {
100-
assert.strictEqual(typeof node.checked, 'boolean', '`checked` must be `boolean`');
115+
assert.strictEqual(
116+
typeof node.checked,
117+
'boolean',
118+
'`checked` must be `boolean`'
119+
)
101120
}
102121
}
103122

104123
function heading(node) {
105-
parent(node);
124+
parent(node)
106125

107-
assert.ok(node.depth > 0, '`depth` should be gte `1`');
108-
assert.ok(node.depth <= 6, '`depth` should be lte `6`');
126+
assert.ok(node.depth > 0, '`depth` should be gte `1`')
127+
assert.ok(node.depth <= 6, '`depth` should be lte `6`')
109128
}
110129

111130
function code(node) {
112-
unist.text(node);
131+
unist.text(node)
113132

114133
if (node.lang != null) {
115-
assert.strictEqual(typeof node.lang, 'string', '`lang` must be `string`');
134+
assert.strictEqual(typeof node.lang, 'string', '`lang` must be `string`')
116135
}
117136
}
118137

119138
function footnoteDefinition(node) {
120-
parent(node);
139+
parent(node)
121140

122-
assert.strictEqual(typeof node.identifier, 'string', '`footnoteDefinition` must have `identifier`');
141+
assert.strictEqual(
142+
typeof node.identifier,
143+
'string',
144+
'`footnoteDefinition` must have `identifier`'
145+
)
123146
}
124147

125148
function definition(node) {
126-
unist.void(node);
149+
unist.void(node)
127150

128-
assert.strictEqual(typeof node.identifier, 'string', '`identifier` must be `string`');
151+
assert.strictEqual(
152+
typeof node.identifier,
153+
'string',
154+
'`identifier` must be `string`'
155+
)
129156

130157
if (node.url != null) {
131-
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`');
158+
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
132159
}
133160

134161
if (node.title != null) {
135-
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`');
162+
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`')
136163
}
137164
}
138165

139166
function link(node) {
140-
parent(node);
167+
parent(node)
141168

142169
if (node.url != null) {
143-
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`');
170+
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
144171
}
145172

146173
if (node.title != null) {
147-
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`');
174+
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`')
148175
}
149176
}
150177

151178
function image(node) {
152-
unist.void(node);
179+
unist.void(node)
153180

154181
if (node.url != null) {
155-
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`');
182+
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
156183
}
157184

158185
if (node.alt != null) {
159-
assert.strictEqual(typeof node.alt, 'string', '`alt` must be `string`');
186+
assert.strictEqual(typeof node.alt, 'string', '`alt` must be `string`')
160187
}
161188

162189
if (node.title != null) {
163-
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`');
190+
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`')
164191
}
165192
}
166193

167194
function linkReference(node) {
168-
parent(node);
195+
parent(node)
169196

170-
assert.strictEqual(typeof node.identifier, 'string', '`identifier` must be `string`');
197+
assert.strictEqual(
198+
typeof node.identifier,
199+
'string',
200+
'`identifier` must be `string`'
201+
)
171202

172203
if (node.referenceType != null) {
173204
assert.notStrictEqual(
174205
['shortcut', 'collapsed', 'full'].indexOf(node.referenceType),
175206
-1,
176207
'`referenceType` must be `shortcut`, `collapsed`, or `full`'
177-
);
208+
)
178209
}
179210
}
180211

181212
function imageReference(node) {
182-
unist.void(node);
213+
unist.void(node)
183214

184215
assert.strictEqual(
185216
typeof node.identifier,
186217
'string',
187218
'`identifier` must be `string`'
188-
);
219+
)
189220

190221
if (node.alt != null) {
191-
assert.strictEqual(typeof node.alt, 'string', '`alt` must be `string`');
222+
assert.strictEqual(typeof node.alt, 'string', '`alt` must be `string`')
192223
}
193224

194225
if (node.referenceType != null) {
195226
assert.notStrictEqual(
196227
['shortcut', 'collapsed', 'full'].indexOf(node.referenceType),
197228
-1,
198229
'`referenceType` must be `shortcut`, `collapsed`, or `full`'
199-
);
230+
)
200231
}
201232
}
202233

203234
function footnoteReference(node) {
204-
unist.void(node);
235+
unist.void(node)
205236

206-
assert.strictEqual(typeof node.identifier, 'string', '`identifier` must be `string`');
237+
assert.strictEqual(
238+
typeof node.identifier,
239+
'string',
240+
'`identifier` must be `string`'
241+
)
207242
}
208243

209244
function table(node) {
210-
var align;
211-
var val;
212-
var length;
213-
var index;
245+
var align
246+
var val
247+
var length
248+
var index
214249

215-
parent(node);
250+
parent(node)
216251

217-
align = node.align;
252+
align = node.align
218253

219254
if (align != null) {
220-
assert.ok(array(align), '`align` must be `array`');
255+
assert.ok(array(align), '`align` must be `array`')
221256

222-
length = align.length;
223-
index = -1;
257+
length = align.length
258+
index = -1
224259

225260
while (++index < length) {
226-
val = align[index];
261+
val = align[index]
227262

228263
if (val != null) {
229264
assert.notStrictEqual(
230265
['left', 'right', 'center'].indexOf(val),
231266
-1,
232-
'each align in table must be `null, \'left\', \'right\', \'center\'`'
233-
);
267+
"each align in table must be `null, 'left', 'right', 'center'`"
268+
)
234269
}
235270
}
236271
}

package.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,35 @@
2828
"browserify": "^16.0.0",
2929
"esmangle": "^1.0.1",
3030
"nyc": "^12.0.0",
31+
"prettier": "^1.14.2",
3132
"remark-cli": "^5.0.0",
3233
"remark-preset-wooorm": "^4.0.0",
3334
"tape": "^4.0.0",
3435
"xo": "^0.22.0"
3536
},
3637
"scripts": {
37-
"build-md": "remark . --quiet --frail --output",
38+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3839
"build-bundle": "browserify index.js -s mdastUtilAssert > mdast-util-assert.js",
3940
"build-mangle": "esmangle < mdast-util-assert.js > mdast-util-assert.min.js",
40-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
41-
"lint": "xo",
41+
"build": "npm run build-bundle && npm run build-mangle",
4242
"test-api": "node test",
4343
"test-coverage": "nyc --reporter lcov tape test",
44-
"test": "npm run build && npm run lint && npm run test-coverage"
44+
"test": "npm run format && npm run build && npm run test-coverage"
45+
},
46+
"prettier": {
47+
"tabWidth": 2,
48+
"useTabs": false,
49+
"singleQuote": true,
50+
"bracketSpacing": false,
51+
"semi": false,
52+
"trailingComma": "none"
4553
},
4654
"xo": {
47-
"space": true,
55+
"prettier": true,
4856
"esnext": false,
4957
"rules": {
5058
"no-eq-null": "off",
51-
"eqeqeq": "off",
52-
"guard-for-in": "off"
59+
"eqeqeq": "off"
5360
},
5461
"ignores": [
5562
"mdast-util-assert.js"

readme.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ npm install mdast-util-assert
1313
## Usage
1414

1515
```javascript
16-
var assert = require('mdast-util-assert');
16+
var assert = require('mdast-util-assert')
1717

18-
assert({type: 'root', children: []});
19-
assert({type: 'break'});
20-
assert({type: 'listItem', checked: true, children: []});
18+
assert({type: 'root', children: []})
19+
assert({type: 'break'})
20+
assert({type: 'listItem', checked: true, children: []})
2121
// All OK.
2222

23-
assert({children: []});
23+
assert({children: []})
2424
// AssertionError: node should have a type: `{ children: [] }`
2525

26-
assert({type: 'paragraph', value: 'foo'});
26+
assert({type: 'paragraph', value: 'foo'})
2727
// AssertionError: parent should have children: `{ type: 'paragraph', value: 'foo' }`
2828
```
2929

0 commit comments

Comments
 (0)