Skip to content

Commit f40c70f

Browse files
committed
Refactor code-style
1 parent 8b24c8e commit f40c70f

File tree

5 files changed

+70
-60
lines changed

5 files changed

+70
-60
lines changed

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
nlcst-affix-emoticon-modifier.js
3+
nlcst-affix-emoticon-modifier.min.js

index.js

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
1-
'use strict';
1+
'use strict'
22

3-
var modifier = require('unist-util-modify-children');
3+
var modifier = require('unist-util-modify-children')
44

5-
module.exports = modifier(mergeAffixEmoticon);
5+
module.exports = modifier(mergeAffixEmoticon)
66

7-
var EMOTICON_NODE = 'EmoticonNode';
7+
var EMOTICON_NODE = 'EmoticonNode'
88

99
/* Merge emoticons into an `EmoticonNode`. */
1010
function mergeAffixEmoticon(child, index, parent) {
11-
var children = child.children;
12-
var position;
13-
var node;
14-
var prev;
11+
var children = child.children
12+
var position
13+
var node
14+
var prev
1515

1616
if (children && children.length !== 0 && index !== 0) {
17-
position = -1;
17+
position = -1
1818

1919
while (children[++position]) {
20-
node = children[position];
20+
node = children[position]
2121

2222
if (node.type === EMOTICON_NODE) {
23-
prev = parent.children[index - 1];
23+
prev = parent.children[index - 1]
2424

25-
prev.children = prev.children.concat(
26-
children.slice(0, position + 1)
27-
);
28-
29-
child.children = children.slice(position + 1);
25+
prev.children = prev.children.concat(children.slice(0, position + 1))
26+
child.children = children.slice(position + 1)
3027

3128
if (node.position && child.position && prev.position) {
32-
prev.position.end = node.position.end;
33-
child.position.start = node.position.end;
29+
prev.position.end = node.position.end
30+
child.position.start = node.position.end
3431
}
3532

3633
/* Next, iterate over the node again. */
37-
return index;
34+
return index
3835
}
3936

4037
if (node.type !== 'WhiteSpaceNode') {
41-
break;
38+
break
4239
}
4340
}
4441
}

package.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"nlcst-emoji-modifier": "^2.0.1",
2727
"nlcst-emoticon-modifier": "^1.0.0",
2828
"nyc": "^11.0.0",
29+
"prettier": "^1.12.1",
2930
"remark-cli": "^5.0.0",
3031
"remark-preset-wooorm": "^4.0.0",
3132
"retext-english": "^3.0.0",
@@ -35,29 +36,35 @@
3536
"xo": "^0.20.0"
3637
},
3738
"scripts": {
38-
"build-md": "remark . --quiet --frail",
39+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3940
"build-bundle": "browserify index.js --bare -s nlcstAffixEmoticonModifier > nlcst-affix-emoticon-modifier.js",
4041
"build-mangle": "esmangle < nlcst-affix-emoticon-modifier.js > nlcst-affix-emoticon-modifier.min.js",
41-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
42-
"lint": "xo",
42+
"build": "npm run build-bundle && npm run build-mangle",
4343
"test-api": "node test",
4444
"test-coverage": "nyc --reporter lcov tape test/index.js",
45-
"test": "npm run build && npm run lint && npm run test-coverage"
45+
"test": "npm run format && npm run build && npm run test-coverage"
4646
},
4747
"nyc": {
4848
"check-coverage": true,
4949
"lines": 100,
5050
"functions": 100,
5151
"branches": 100
5252
},
53+
"prettier": {
54+
"tabWidth": 2,
55+
"useTabs": false,
56+
"singleQuote": true,
57+
"bracketSpacing": false,
58+
"semi": false,
59+
"trailingComma": "none"
60+
},
5361
"xo": {
54-
"space": true,
62+
"prettier": true,
5563
"esnext": false,
5664
"rules": {
5765
"guard-for-in": "off",
5866
"no-var": "off",
59-
"prefer-arrow-callback": "off",
60-
"guard-for-in": "off"
67+
"prefer-arrow-callback": "off"
6168
},
6269
"ignore": [
6370
"nlcst-affix-emoticon-modifier.js"

readme.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ npm install nlcst-affix-emoticon-modifier
1818
## Usage
1919

2020
```js
21-
var affixEmoticon = require('nlcst-affix-emoticon-modifier');
22-
var emoticon = require('nlcst-emoticon-modifier');
23-
var inspect = require('unist-util-inspect');
24-
var english = require('parse-english')();
21+
var affixEmoticon = require('nlcst-affix-emoticon-modifier')
22+
var emoticon = require('nlcst-emoticon-modifier')
23+
var inspect = require('unist-util-inspect')
24+
var english = require('parse-english')()
2525

26-
english.useFirst('tokenizeSentence', emoticon);
27-
english.useFirst('tokenizeParagraph', affixEmoticon);
26+
english.useFirst('tokenizeSentence', emoticon)
27+
english.useFirst('tokenizeParagraph', affixEmoticon)
2828

29-
console.log(inspect(english.parse('Hey. :) How is it going?')));
29+
console.log(inspect(english.parse('Hey. :) How is it going?')))
3030
```
3131

3232
Yields:

test/index.js

+29-26
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,69 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var unified = require('unified');
5-
var english = require('retext-english');
6-
var emojiModifier = require('nlcst-emoji-modifier');
7-
var emoticonModifier = require('nlcst-emoticon-modifier');
8-
var remove = require('unist-util-remove-position');
9-
var modifier = require('..');
3+
var test = require('tape')
4+
var unified = require('unified')
5+
var english = require('retext-english')
6+
var emojiModifier = require('nlcst-emoji-modifier')
7+
var emoticonModifier = require('nlcst-emoticon-modifier')
8+
var remove = require('unist-util-remove-position')
9+
var modifier = require('..')
1010

11-
var lollipop = require('./fixtures/lollipop');
12-
var smile = require('./fixtures/smile');
11+
var lollipop = require('./fixtures/lollipop')
12+
var smile = require('./fixtures/smile')
1313

14-
test('nlcst-affix-emoticon-modifier()', function (t) {
14+
test('nlcst-affix-emoticon-modifier()', function(t) {
1515
t.throws(
16-
function () {
17-
modifier({});
16+
function() {
17+
modifier({})
1818
},
1919
/Missing children in `parent`/,
2020
'should throw when not given a parent'
21-
);
21+
)
2222

2323
t.deepEqual(
2424
process('Lol! :lollipop: That’s cool.'),
2525
lollipop,
2626
'should merge at sentence-start (1)'
27-
);
27+
)
2828

2929
t.deepEqual(
3030
process('Lol! :lollipop: That’s cool.', true),
3131
remove(lollipop, true),
3232
'should merge at sentence-start (1, positionless)'
33-
);
33+
)
3434

3535
t.deepEqual(
3636
process('Lol! :) That’s cool.'),
3737
smile,
3838
'should merge at sentence-start (2)'
39-
);
39+
)
4040

4141
t.deepEqual(
4242
process('Lol! :) That’s cool.', true),
4343
remove(smile, true),
4444
'should merge at sentence-start (2, positionless)'
45-
);
45+
)
4646

47-
t.end();
48-
});
47+
t.end()
48+
})
4949

5050
/* Short-cut to access the CST. */
5151
function process(fixture, positionless) {
52-
var processor = unified().use(english).use(plugin).freeze();
52+
var processor = unified()
53+
.use(english)
54+
.use(plugin)
55+
.freeze()
5356

5457
if (positionless) {
55-
processor.Parser.prototype.position = false;
58+
processor.Parser.prototype.position = false
5659
}
5760

58-
return processor.runSync(processor.parse(fixture));
61+
return processor.runSync(processor.parse(fixture))
5962
}
6063

6164
/* Add modifier to processor. */
6265
function plugin() {
63-
this.Parser.prototype.useFirst('tokenizeSentence', emojiModifier);
64-
this.Parser.prototype.useFirst('tokenizeSentence', emoticonModifier);
65-
this.Parser.prototype.useFirst('tokenizeParagraph', modifier);
66+
this.Parser.prototype.useFirst('tokenizeSentence', emojiModifier)
67+
this.Parser.prototype.useFirst('tokenizeSentence', emoticonModifier)
68+
this.Parser.prototype.useFirst('tokenizeParagraph', modifier)
6669
}

0 commit comments

Comments
 (0)