Skip to content

Commit e64ef55

Browse files
committed
Refactor code-style
1 parent e533752 commit e64ef55

File tree

5 files changed

+139
-200
lines changed

5 files changed

+139
-200
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,mdastrc,eslintrc}]
12-
indent_size = 2
13-
14-
[*.md]
15-
trim_trailing_whitespace = false

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
.DS_Store
22
*.log
3-
bower_components/
4-
build/
5-
components/
63
coverage/
74
node_modules/
8-
build.js

index.js

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,41 @@
1-
/**
2-
* @author Titus Wormer
3-
* @copyright 2015 Titus Wormer
4-
* @license MIT
5-
* @module unist:util:find-all-before
6-
* @fileoverview Utility to find nodes before another node.
7-
*/
8-
91
'use strict';
102

11-
/* eslint-env commonjs */
12-
13-
/*
14-
* Dependencies.
15-
*/
16-
173
var is = require('unist-util-is');
184

19-
/**
20-
* Find nodes before `index` in `parent` which pass `test`.
21-
*
22-
* @param {Node} parent - Parent to search in.
23-
* @param {number|Node} index - (Position of) node to
24-
* search before.
25-
* @param {*} test - See `wooorm/unist-util-is`.
26-
* @return {Node?} - A child node of `parent` which pass
27-
* `test`.
28-
*/
5+
module.exports = findAllBefore;
6+
7+
/* Find nodes before `index` in `parent` which pass `test`. */
298
function findAllBefore(parent, index, test) {
30-
var results = [];
31-
var children;
32-
var child;
9+
var results = [];
10+
var children;
11+
var child;
3312

34-
if (!parent || !parent.type || !parent.children) {
35-
throw new Error('Expected parent node');
36-
}
13+
if (!parent || !parent.type || !parent.children) {
14+
throw new Error('Expected parent node');
15+
}
3716

38-
children = parent.children;
17+
children = parent.children;
3918

40-
if (index && index.type) {
41-
index = children.indexOf(index);
42-
}
19+
if (index && index.type) {
20+
index = children.indexOf(index);
21+
}
4322

44-
if (isNaN(index) || index < 0 || index === Infinity) {
45-
throw new Error('Expected positive finite index or child node');
46-
}
23+
if (isNaN(index) || index < 0 || index === Infinity) {
24+
throw new Error('Expected positive finite index or child node');
25+
}
4726

48-
/* Performance. */
49-
if (index > children.length) {
50-
index = children.length;
51-
}
27+
/* Performance. */
28+
if (index > children.length) {
29+
index = children.length;
30+
}
5231

53-
while (index--) {
54-
child = children[index];
32+
while (index--) {
33+
child = children[index];
5534

56-
if (is(test, child, index, parent)) {
57-
results.push(child);
58-
}
35+
if (is(test, child, index, parent)) {
36+
results.push(child);
5937
}
38+
}
6039

61-
return results;
40+
return results;
6241
}
63-
64-
/*
65-
* Expose.
66-
*/
67-
68-
module.exports = findAllBefore;

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,33 @@
3333
],
3434
"devDependencies": {
3535
"browserify": "^11.0.0",
36-
"eslint": "^1.0.0",
3736
"esmangle": "^1.0.0",
3837
"istanbul": "^0.3.0",
39-
"jscs": "^2.0.0",
40-
"jscs-jsdoc": "^1.0.0",
4138
"mdast": "^1.0.0",
4239
"mdast-comment-config": "^1.0.0",
4340
"mdast-github": "^1.0.0",
4441
"mdast-lint": "^1.0.0",
4542
"mdast-slug": "^2.0.0",
4643
"mdast-validate-links": "^1.0.0",
47-
"mocha": "^2.0.0"
44+
"mocha": "^2.0.0",
45+
"xo": "^0.17.1"
4846
},
4947
"scripts": {
5048
"test-api": "mocha --check-leaks test.js",
5149
"test-coverage": "istanbul cover _mocha -- test.js",
5250
"test-travis": "npm run test-coverage",
5351
"test": "npm run test-api",
54-
"lint-api": "eslint .",
55-
"lint-style": "jscs --reporter inline .",
56-
"lint": "npm run lint-api && npm run lint-style",
52+
"lint": "xo",
5753
"make": "npm run lint && npm run test-coverage",
5854
"bundle": "browserify index.js --no-builtins -s unistUtilFindAllBefore > unist-util-find-all-before.js",
5955
"postbundle": "esmangle unist-util-find-all-before.js > unist-util-find-all-before.min.js",
6056
"build-md": "mdast . --quiet",
6157
"build": "npm run bundle && npm run build-md"
58+
},
59+
"xo": {
60+
"space": true,
61+
"ignore": [
62+
"unist-util-find-all-before.js"
63+
]
6264
}
6365
}

0 commit comments

Comments
 (0)