Skip to content

Commit 045a5de

Browse files
committed
Refactor code-style
1 parent 2884ad6 commit 045a5de

File tree

4 files changed

+70
-135
lines changed

4 files changed

+70
-135
lines changed

.editorconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ root = true
22

33
[*]
44
indent_style = space
5-
indent_size = 4
5+
indent_size = 2
66
end_of_line = lf
77
charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
10-
11-
[*.{json,html,svg,css,remarkrc,eslintrc}]
12-
indent_size = 2
13-
14-
[*.md]
15-
trim_trailing_whitespace = false

index.js

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,19 @@
1-
/**
2-
* @author Titus Wormer
3-
* @copyright 2016 Titus Wormer
4-
* @license MIT
5-
* @module unist:util:generated
6-
* @fileoverview Check if a node is generated.
7-
*/
8-
91
'use strict';
102

11-
/* eslint-env commonjs */
12-
13-
/**
14-
* Return `value` if it’s an object, an empty object
15-
* otherwise.
16-
*
17-
* @private
18-
* @param {*} value - Value to check.
19-
* @return {Object} - `value` or `{}`.
20-
*/
21-
function optional(value) {
22-
return value && typeof value === 'object' ? value : {};
23-
}
3+
/* Expose. */
4+
module.exports = generated;
245

25-
/**
26-
* Detect if a node was available in the original document.
27-
*
28-
* @example
29-
* generated(); // true
30-
*
31-
* generated({
32-
* start: {
33-
* line: 1,
34-
* column: 1
35-
* },
36-
* end: {
37-
* line: 1,
38-
* column: 2
39-
* }
40-
* }); // false
41-
*
42-
* @param {Node} node - Node to check.
43-
* @return {boolean} - Whether or not `node` is generated.
44-
*/
6+
/* Detect if a node was available in the original document. */
457
function generated(node) {
46-
var position = optional(optional(node).position);
47-
var start = optional(position.start);
48-
var end = optional(position.end);
8+
var position = optional(optional(node).position);
9+
var start = optional(position.start);
10+
var end = optional(position.end);
4911

50-
return !start.line || !start.column || !end.line || !end.column;
12+
return !start.line || !start.column || !end.line || !end.column;
5113
}
5214

53-
/*
54-
* Expose.
55-
*/
56-
57-
module.exports = generated;
15+
/* Return `value` if it’s an object, an empty object
16+
* otherwise. */
17+
function optional(value) {
18+
return value && typeof value === 'object' ? value : {};
19+
}

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,30 @@
2525
],
2626
"devDependencies": {
2727
"browserify": "^13.0.0",
28-
"eslint": "^2.0.0",
2928
"esmangle": "^1.0.0",
3029
"istanbul": "^0.4.0",
31-
"jscs": "^3.0.0",
32-
"jscs-jsdoc": "^2.0.0",
3330
"remark": "^4.0.0",
3431
"remark-comment-config": "^3.0.0",
3532
"remark-github": "^4.0.0",
3633
"remark-lint": "^3.0.0",
3734
"remark-usage": "^3.0.0",
38-
"tape": "^4.5.1"
35+
"tape": "^4.5.1",
36+
"xo": "^0.17.1"
3937
},
4038
"scripts": {
4139
"build-md": "remark . --quiet --frail",
4240
"build-bundle": "browserify index.js --no-builtins -s unistUtilGenerated > unist-util-generated.js",
4341
"build-mangle": "esmangle unist-util-generated.js > unist-util-generated.min.js",
4442
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
45-
"lint-api": "eslint .",
46-
"lint-style": "jscs --reporter inline .",
47-
"lint": "npm run lint-api && npm run lint-style",
43+
"lint": "xo",
4844
"test-api": "node test.js",
4945
"test-coverage": "istanbul cover test.js",
5046
"test": "npm run build && npm run lint && npm run test-coverage"
47+
},
48+
"xo": {
49+
"space": true,
50+
"ignores": [
51+
"unist-util-generated.js"
52+
]
5153
}
5254
}

test.js

Lines changed: 48 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,55 @@
1-
/**
2-
* @author Titus Wormer
3-
* @copyright 2016 Titus Wormer
4-
* @license MIT
5-
* @module unist:util:generated
6-
* @fileoverview Test suite for `unist-util-generated`.
7-
*/
8-
91
'use strict';
102

11-
/* eslint-env node */
12-
13-
/*
14-
* Dependencies.
15-
*/
16-
173
var test = require('tape');
184
var generated = require('./index.js');
195

20-
/*
21-
* Tests.
22-
*/
23-
246
test('generated', function (t) {
25-
t.equal(
26-
generated(),
27-
true,
28-
'should not throw without node'
29-
);
30-
31-
t.equal(
32-
generated({
33-
'position': {
34-
'start': {
35-
'line': 1,
36-
'column': 1,
37-
'indent': [],
38-
'offset': 0
39-
},
40-
'end': {
41-
'line': 1,
42-
'column': 2,
43-
'indent': [],
44-
'offset': 1
45-
}
46-
}
47-
}),
48-
false,
49-
'should return false when with properties'
50-
);
51-
52-
t.equal(
53-
generated({
54-
'position': {
55-
'start': {},
56-
'end': {}
57-
}
58-
}),
59-
true,
60-
'should return true when without properties'
61-
);
62-
63-
t.equal(
64-
generated({
65-
'position': {}
66-
}),
67-
true,
68-
'should return true when without objects'
69-
);
70-
71-
t.equal(
72-
generated({}),
73-
true,
74-
'should return true when without position'
75-
);
76-
77-
t.end();
7+
t.equal(
8+
generated(),
9+
true,
10+
'should not throw without node'
11+
);
12+
13+
t.equal(
14+
generated({
15+
position: {
16+
start: {
17+
line: 1,
18+
column: 1,
19+
indent: [],
20+
offset: 0
21+
},
22+
end: {
23+
line: 1,
24+
column: 2,
25+
indent: [],
26+
offset: 1
27+
}
28+
}
29+
}),
30+
false,
31+
'should return false when with properties'
32+
);
33+
34+
t.equal(
35+
generated({
36+
position: {start: {}, end: {}}
37+
}),
38+
true,
39+
'should return true when without properties'
40+
);
41+
42+
t.equal(
43+
generated({position: {}}),
44+
true,
45+
'should return true when without objects'
46+
);
47+
48+
t.equal(
49+
generated({}),
50+
true,
51+
'should return true when without position'
52+
);
53+
54+
t.end();
7855
});

0 commit comments

Comments
 (0)