Skip to content

Commit 34e6859

Browse files
committed
Refactor code-style
1 parent b454d99 commit 34e6859

File tree

5 files changed

+61
-45
lines changed

5 files changed

+61
-45
lines changed

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
*.log
3+
.nyc_output/
4+
coverage/
5+
node_modules/
6+
hast-util-parse-selector.js
7+
hast-util-parse-selector.min.js
8+
yarn.lock

index.js

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

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

5-
var dot = '.'.charCodeAt(0);
6-
var hash = '#'.charCodeAt(0);
5+
var dot = '.'.charCodeAt(0)
6+
var hash = '#'.charCodeAt(0)
77

88
/* Parse a simple CSS selector into a HAST node. */
99
function parse(selector) {
10-
var value = selector || '';
11-
var name = 'div';
12-
var props = {};
13-
var index = -1;
14-
var length = value.length;
15-
var className;
16-
var type;
17-
var code;
18-
var subvalue;
19-
var lastIndex;
10+
var value = selector || ''
11+
var name = 'div'
12+
var props = {}
13+
var index = -1
14+
var length = value.length
15+
var className
16+
var type
17+
var code
18+
var subvalue
19+
var lastIndex
2020

2121
while (++index <= length) {
22-
code = value.charCodeAt(index);
22+
code = value.charCodeAt(index)
2323

2424
if (!code || code === dot || code === hash) {
25-
subvalue = value.slice(lastIndex, index);
25+
subvalue = value.slice(lastIndex, index)
2626

2727
if (subvalue) {
2828
if (type === dot) {
2929
if (className) {
30-
className.push(subvalue);
30+
className.push(subvalue)
3131
} else {
32-
className = [subvalue];
33-
props.className = className;
32+
className = [subvalue]
33+
props.className = className
3434
}
3535
} else if (type === hash) {
36-
props.id = subvalue;
36+
props.id = subvalue
3737
} else {
38-
name = subvalue;
38+
name = subvalue
3939
}
4040
}
4141

42-
lastIndex = index + 1;
43-
type = code;
42+
lastIndex = index + 1
43+
type = code
4444
}
4545
}
4646

@@ -49,5 +49,5 @@ function parse(selector) {
4949
tagName: name,
5050
properties: props,
5151
children: []
52-
};
52+
}
5353
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,31 @@
2525
"browserify": "^16.0.0",
2626
"esmangle": "^1.0.0",
2727
"nyc": "^12.0.0",
28+
"prettier": "^1.13.5",
2829
"remark-cli": "^5.0.0",
2930
"remark-preset-wooorm": "^4.0.0",
3031
"tape": "^4.0.0",
3132
"xo": "^0.21.0"
3233
},
3334
"scripts": {
34-
"build-md": "remark . --quiet --frail --output",
35+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3536
"build-bundle": "browserify index.js --bare -s hastUtilParseSelector > hast-util-parse-selector.js",
3637
"build-mangle": "esmangle hast-util-parse-selector.js > hast-util-parse-selector.min.js",
37-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
38-
"lint": "xo",
39-
"test-api": "node test.js",
38+
"build": "npm run build-bundle && npm run build-mangle",
39+
"test-api": "node test",
4040
"test-coverage": "nyc --reporter lcov tape test.js",
41-
"test": "npm run build && npm run lint && npm run test-coverage"
41+
"test": "npm run format && npm run build && npm run test-coverage"
42+
},
43+
"prettier": {
44+
"tabWidth": 2,
45+
"useTabs": false,
46+
"singleQuote": true,
47+
"bracketSpacing": false,
48+
"semi": false,
49+
"trailingComma": "none"
4250
},
4351
"xo": {
44-
"space": true,
52+
"prettier": true,
4553
"esnext": false,
4654
"rules": {
4755
"max-depth": "off"

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ npm install hast-util-parse-selector
1313
## Usage
1414

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

18-
console.log(parseSelector('.quux#bar.baz.qux'));
18+
console.log(parseSelector('.quux#bar.baz.qux'))
1919
```
2020

2121
Yields:

test.js

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

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

6-
test('parseSelector()', function (t) {
6+
test('parseSelector()', function(t) {
77
t.deepEqual(
88
parseSelector(),
99
{
@@ -13,7 +13,7 @@ test('parseSelector()', function (t) {
1313
children: []
1414
},
1515
'should return an empty element without selector'
16-
);
16+
)
1717

1818
t.deepEqual(
1919
parseSelector('foo'),
@@ -24,7 +24,7 @@ test('parseSelector()', function (t) {
2424
children: []
2525
},
2626
'should return an element with a tag-name when given a tag-name'
27-
);
27+
)
2828

2929
t.deepEqual(
3030
parseSelector('.bar'),
@@ -35,7 +35,7 @@ test('parseSelector()', function (t) {
3535
children: []
3636
},
3737
'should return a `div` element when given a class'
38-
);
38+
)
3939

4040
t.deepEqual(
4141
parseSelector('#bar'),
@@ -46,7 +46,7 @@ test('parseSelector()', function (t) {
4646
children: []
4747
},
4848
'should return a `div` element when given an ID'
49-
);
49+
)
5050

5151
t.deepEqual(
5252
parseSelector('foo#bar.baz.qux'),
@@ -60,7 +60,7 @@ test('parseSelector()', function (t) {
6060
children: []
6161
},
6262
'should return attributes'
63-
);
63+
)
6464

6565
t.deepEqual(
6666
parseSelector('foo#bar#baz'),
@@ -71,7 +71,7 @@ test('parseSelector()', function (t) {
7171
children: []
7272
},
7373
'should return the last ID if multiple are found'
74-
);
74+
)
7575

7676
t.deepEqual(
7777
parseSelector('Foo'),
@@ -82,7 +82,7 @@ test('parseSelector()', function (t) {
8282
children: []
8383
},
8484
'should *not* case the tag-name'
85-
);
85+
)
8686

87-
t.end();
88-
});
87+
t.end()
88+
})

0 commit comments

Comments
 (0)