Skip to content

Commit 9e0812d

Browse files
committed
Refactor code-style
1 parent e8f2700 commit 9e0812d

File tree

12 files changed

+189
-179
lines changed

12 files changed

+189
-179
lines changed

.prettierignore

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

index.js

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

3-
var assert = require('assert');
4-
var zwitch = require('zwitch');
5-
var mapz = require('mapz');
6-
var unist = require('unist-util-assert');
3+
var assert = require('assert')
4+
var zwitch = require('zwitch')
5+
var mapz = require('mapz')
6+
var unist = require('unist-util-assert')
77

88
/* Construct. */
9-
var hast = zwitch('type');
9+
var hast = zwitch('type')
1010

11-
exports = unist.wrap(hast);
12-
module.exports = exports;
11+
exports = unist.wrap(hast)
12+
module.exports = exports
1313

14-
exports.parent = unist.wrap(parent);
15-
exports.text = unist.text;
16-
exports.void = unist.void;
17-
exports.wrap = unist.wrap;
18-
exports.all = mapz(exports, {key: 'children', indices: false});
14+
exports.parent = unist.wrap(parent)
15+
exports.text = unist.text
16+
exports.void = unist.void
17+
exports.wrap = unist.wrap
18+
exports.all = mapz(exports, {key: 'children', indices: false})
1919

2020
/* Core interface. */
21-
hast.invalid = unknown;
22-
hast.unknown = unknown;
21+
hast.invalid = unknown
22+
hast.unknown = unknown
2323

2424
/* Per-type handling. */
2525
hast.handlers = {
@@ -28,40 +28,52 @@ hast.handlers = {
2828
doctype: unist.wrap(doctype),
2929
comment: exports.text,
3030
text: exports.text
31-
};
31+
}
3232

3333
function unknown(node, ancestor) {
34-
unist(node, ancestor);
34+
unist(node, ancestor)
3535
}
3636

3737
function parent(node) {
38-
unist.parent(node);
39-
exports.all(node);
38+
unist.parent(node)
39+
exports.all(node)
4040
}
4141

4242
function root(node, ancestor) {
43-
parent(node);
43+
parent(node)
4444

45-
assert.equal(ancestor, undefined, '`root` should not have a parent');
45+
assert.equal(ancestor, undefined, '`root` should not have a parent')
4646
}
4747

4848
function element(node) {
49-
parent(node);
50-
51-
assert.equal(typeof node.tagName, 'string', '`element` should have a `tagName`');
52-
assert.notEqual(node.tagName, '', '`element.tagName` should not be empty');
49+
parent(node)
50+
51+
assert.equal(
52+
typeof node.tagName,
53+
'string',
54+
'`element` should have a `tagName`'
55+
)
56+
assert.notEqual(node.tagName, '', '`element.tagName` should not be empty')
5357
}
5458

5559
function doctype(node) {
56-
unist.void(node);
60+
unist.void(node)
5761

58-
assert.equal(typeof node.name, 'string', '`doctype` should have a `name`');
62+
assert.equal(typeof node.name, 'string', '`doctype` should have a `name`')
5963

6064
if (node.public != null) {
61-
assert.equal(typeof node.public, 'string', '`doctype.public` should be `string`');
65+
assert.equal(
66+
typeof node.public,
67+
'string',
68+
'`doctype.public` should be `string`'
69+
)
6270
}
6371

6472
if (node.system != null) {
65-
assert.equal(typeof node.system, 'string', '`doctype.system` should be `string`');
73+
assert.equal(
74+
typeof node.system,
75+
'string',
76+
'`doctype.system` should be `string`'
77+
)
6678
}
6779
}

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,31 @@
2727
"browserify": "^16.0.0",
2828
"esmangle": "^1.0.1",
2929
"nyc": "^12.0.0",
30+
"prettier": "^1.13.5",
3031
"remark-cli": "^5.0.0",
3132
"remark-preset-wooorm": "^4.0.0",
3233
"tape": "^4.0.0",
3334
"xo": "^0.21.0"
3435
},
3536
"scripts": {
36-
"build-md": "remark . --quiet --frail --output",
37+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3738
"build-bundle": "browserify index.js -s hastUtilAssert > hast-util-assert.js",
3839
"build-mangle": "esmangle < hast-util-assert.js > hast-util-assert.min.js",
39-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
40-
"lint": "xo",
40+
"build": "npm run build-bundle && npm run build-mangle",
4141
"test-api": "node test",
4242
"test-coverage": "nyc --reporter lcov tape test",
43-
"test": "npm run build && npm run lint && npm run test-coverage"
43+
"test": "npm run format && npm run build && npm run test-coverage"
44+
},
45+
"prettier": {
46+
"tabWidth": 2,
47+
"useTabs": false,
48+
"singleQuote": true,
49+
"bracketSpacing": false,
50+
"semi": false,
51+
"trailingComma": "none"
4452
},
4553
"xo": {
46-
"space": true,
54+
"prettier": true,
4755
"esnext": false,
4856
"rules": {
4957
"no-eq-null": "off",

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ npm install hast-util-assert
1313
## Usage
1414

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

18-
assert({type: 'root', children: []});
19-
assert({type: 'element', tagName: 'a', properties: {}, children: []});
18+
assert({type: 'root', children: []})
19+
assert({type: 'element', tagName: 'a', properties: {}, children: []})
2020
// All OK.
2121

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

25-
assert({type: 'element', properties: {}, children: []});
25+
assert({type: 'element', properties: {}, children: []})
2626
// AssertionError: `element` should have a `tagName`: `{ type: 'element', properties: {}, children: [] }`
2727
```
2828

test/children.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var assert = require('..');
3+
var test = require('tape')
4+
var assert = require('..')
55

6-
test('children', function (t) {
6+
test('children', function(t) {
77
t.throws(
8-
function () {
9-
assert({type: 'paragraph', children: {alpha: 'bravo'}});
8+
function() {
9+
assert({type: 'paragraph', children: {alpha: 'bravo'}})
1010
},
1111
/`children` should be an array: `{ type: 'paragraph', children: { alpha: 'bravo' } }`$/,
1212
'should throw if given a non-node child in children'
13-
);
13+
)
1414

1515
t.throws(
16-
function () {
17-
assert({type: 'paragraph', children: ['one']});
16+
function() {
17+
assert({type: 'paragraph', children: ['one']})
1818
},
1919
/node should be an object: `'one'` in `{ type: 'paragraph', children: \[ 'one' ] }`$/,
2020
'should throw if given a non-node child in children'
21-
);
21+
)
2222

23-
t.doesNotThrow(
24-
function () {
25-
assert({type: 'paragraph', children: [{type: 'text', value: 'alpha'}]});
26-
},
27-
'should not throw on vald children'
28-
);
23+
t.doesNotThrow(function() {
24+
assert({type: 'paragraph', children: [{type: 'text', value: 'alpha'}]})
25+
}, 'should not throw on vald children')
2926

3027
t.throws(
31-
function () {
32-
assert({type: 'paragraph', children: [{
33-
type: 'bar',
34-
children: ['one']
35-
}]});
28+
function() {
29+
assert({
30+
type: 'paragraph',
31+
children: [
32+
{
33+
type: 'bar',
34+
children: ['one']
35+
}
36+
]
37+
})
3638
},
3739
/node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/,
3840
'should throw on invalid descendants'
39-
);
41+
)
4042

41-
t.end();
42-
});
43+
t.end()
44+
})

test/comment.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var assert = require('..');
3+
var test = require('tape')
4+
var assert = require('..')
55

6-
test('assert(comment)', function (t) {
6+
test('assert(comment)', function(t) {
77
t.throws(
8-
function () {
9-
assert({type: 'comment'});
8+
function() {
9+
assert({type: 'comment'})
1010
},
1111
/text should have `value`: `{ type: 'comment' }`$/,
1212
'should throw if a `comment` doesn’t have a value'
13-
);
13+
)
1414

15-
t.doesNotThrow(
16-
function () {
17-
assert({type: 'comment', value: 'Alpha'});
18-
},
19-
'should allow `value`'
20-
);
15+
t.doesNotThrow(function() {
16+
assert({type: 'comment', value: 'Alpha'})
17+
}, 'should allow `value`')
2118

22-
t.end();
23-
});
19+
t.end()
20+
})

test/doctype.js

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var assert = require('..');
3+
var test = require('tape')
4+
var assert = require('..')
55

6-
test('assert(doctype)', function (t) {
6+
test('assert(doctype)', function(t) {
77
t.throws(
8-
function () {
9-
assert({type: 'doctype'});
8+
function() {
9+
assert({type: 'doctype'})
1010
},
1111
/`doctype` should have a `name`: `{ type: 'doctype' }`$/,
1212
'should throw if a `doctype` doesn’t have a name'
13-
);
13+
)
1414

15-
t.doesNotThrow(
16-
function () {
17-
assert({type: 'doctype', name: 'html'});
18-
},
19-
'should allow names'
20-
);
15+
t.doesNotThrow(function() {
16+
assert({type: 'doctype', name: 'html'})
17+
}, 'should allow names')
2118

22-
t.doesNotThrow(
23-
function () {
24-
assert({type: 'doctype', name: ''});
25-
},
26-
'should allow empty names'
27-
);
19+
t.doesNotThrow(function() {
20+
assert({type: 'doctype', name: ''})
21+
}, 'should allow empty names')
2822

2923
t.throws(
30-
function () {
31-
assert({type: 'doctype', name: 'html', public: true});
24+
function() {
25+
assert({type: 'doctype', name: 'html', public: true})
3226
},
3327
/`doctype.public` should be `string`: `{ type: 'doctype', name: 'html', public: true }`$/,
3428
'should throw if a `public` isn’t string'
35-
);
29+
)
3630

3731
t.throws(
38-
function () {
39-
assert({type: 'doctype', name: 'html', system: false});
32+
function() {
33+
assert({type: 'doctype', name: 'html', system: false})
4034
},
4135
/`doctype.system` should be `string`: `{ type: 'doctype', name: 'html', system: false }`$/,
4236
'should throw if a `system` isn’t string'
43-
);
37+
)
4438

45-
t.doesNotThrow(
46-
function () {
47-
assert({type: 'doctype', name: 'html', public: 'a', system: 'b'});
48-
},
49-
'should allow string `public` and `system`'
50-
);
39+
t.doesNotThrow(function() {
40+
assert({type: 'doctype', name: 'html', public: 'a', system: 'b'})
41+
}, 'should allow string `public` and `system`')
5142

52-
t.end();
53-
});
43+
t.end()
44+
})

0 commit comments

Comments
 (0)