Skip to content

Commit 50aee7e

Browse files
committed
Refactor code-style
1 parent 298643e commit 50aee7e

File tree

4 files changed

+124
-175
lines changed

4 files changed

+124
-175
lines changed

.prettierignore

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

index.js

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

33
/* Expose. */
4-
module.exports = marker;
4+
module.exports = marker
55

66
/* HTML type. */
7-
var T_HTML = 'html';
7+
var T_HTML = 'html'
88

99
/* Expression for eliminating extra spaces */
10-
var SPACES = /\s+/g;
10+
var SPACES = /\s+/g
1111

1212
/* Expression for parsing parameters. */
1313
var PARAMETERS = new RegExp(
1414
'\\s+' +
15-
'(' +
15+
'(' +
1616
'[-a-z0-9_]+' +
17-
')' +
18-
'(?:' +
17+
')' +
18+
'(?:' +
1919
'=' +
2020
'(?:' +
21-
'"' +
22-
'(' +
23-
'(?:' +
24-
'\\\\[\\s\\S]' +
25-
'|' +
26-
'[^"]' +
27-
')+' +
28-
')' +
29-
'"' +
30-
'|' +
31-
'\'' +
32-
'(' +
33-
'(?:' +
34-
'\\\\[\\s\\S]' +
35-
'|' +
36-
'[^\']' +
37-
')+' +
38-
')' +
39-
'\'' +
40-
'|' +
41-
'(' +
42-
'(?:' +
43-
'\\\\[\\s\\S]' +
44-
'|' +
45-
'[^"\'\\s]' +
46-
')+' +
47-
')' +
21+
'"' +
22+
'(' +
23+
'(?:' +
24+
'\\\\[\\s\\S]' +
25+
'|' +
26+
'[^"]' +
27+
')+' +
28+
')' +
29+
'"' +
30+
'|' +
31+
"'" +
32+
'(' +
33+
'(?:' +
34+
'\\\\[\\s\\S]' +
35+
'|' +
36+
"[^']" +
37+
')+' +
38+
')' +
39+
"'" +
40+
'|' +
41+
'(' +
42+
'(?:' +
43+
'\\\\[\\s\\S]' +
44+
'|' +
45+
'[^"\'\\s]' +
46+
')+' +
4847
')' +
49-
')?',
48+
')' +
49+
')?',
5050
'gi'
51-
);
51+
)
5252

5353
var MARKER = new RegExp(
5454
'(' +
@@ -60,60 +60,61 @@ var MARKER = new RegExp(
6060
'\\s*' +
6161
'-->' +
6262
'\\s*' +
63-
')'
64-
);
63+
')'
64+
)
6565

6666
/* Parse a comment marker */
6767
function marker(node) {
68-
var value;
69-
var match;
70-
var params;
68+
var value
69+
var match
70+
var params
7171

7272
if (!node || node.type !== T_HTML) {
73-
return null;
73+
return null
7474
}
7575

76-
value = node.value;
77-
match = value.match(MARKER);
76+
value = node.value
77+
match = value.match(MARKER)
7878

7979
if (!match || match[1].length !== value.length) {
80-
return null;
80+
return null
8181
}
8282

83-
params = parameters(match[3] || '');
83+
params = parameters(match[3] || '')
8484

8585
if (!params) {
86-
return null;
86+
return null
8787
}
8888

8989
return {
9090
name: match[2],
9191
attributes: match[4] || '',
9292
parameters: params,
9393
node: node
94-
};
94+
}
9595
}
9696

97-
/* eslint-disable max-params */
98-
9997
/* Parse `value` into an object. */
10098
function parameters(value) {
101-
var attributes = {};
102-
var rest = value.replace(PARAMETERS, function ($0, $1, $2, $3, $4) {
103-
var result = $2 || $3 || $4 || '';
99+
var attributes = {}
100+
var rest = value.replace(PARAMETERS, replacer)
101+
102+
return rest.replace(SPACES, '') ? null : attributes
103+
104+
/* eslint-disable max-params */
105+
function replacer($0, $1, $2, $3, $4) {
106+
var result = $2 || $3 || $4 || ''
104107

105108
if (result === 'true' || result === '') {
106-
result = true;
109+
result = true
107110
} else if (result === 'false') {
108-
result = false;
111+
result = false
109112
} else if (!isNaN(result)) {
110-
result = Number(result);
113+
result = Number(result)
111114
}
112115

113-
attributes[$1] = result;
114-
115-
return '';
116-
});
116+
attributes[$1] = result
117117

118-
return rest.replace(SPACES, '') ? null : attributes;
118+
return ''
119+
}
119120
}

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,38 @@
2323
"devDependencies": {
2424
"browserify": "^16.0.0",
2525
"nyc": "^12.0.0",
26+
"prettier": "^1.14.2",
2627
"remark-cli": "^5.0.0",
2728
"remark-preset-wooorm": "^4.0.0",
2829
"tape": "^4.0.0",
2930
"tinyify": "^2.4.3",
3031
"xo": "^0.22.0"
3132
},
3233
"scripts": {
33-
"build-md": "remark . -qfo",
34+
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
3435
"build-bundle": "browserify . -s mdastCommentMarker > mdast-comment-marker.js",
3536
"build-mangle": "browserify . -s mdastCommentMarker -p tinyify > mdast-comment-marker.min.js",
36-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
37-
"lint": "xo",
37+
"build": "npm run build-bundle && npm run build-mangle",
3838
"test-api": "node test",
3939
"test-coverage": "nyc --reporter lcov tape test.js",
40-
"test": "npm run build && npm run lint && npm run test-coverage"
40+
"test": "npm run format && npm run build && npm run test-coverage"
4141
},
4242
"nyc": {
4343
"check-coverage": true,
4444
"lines": 100,
4545
"functions": 100,
4646
"branches": 100
4747
},
48+
"prettier": {
49+
"tabWidth": 2,
50+
"useTabs": false,
51+
"singleQuote": true,
52+
"bracketSpacing": false,
53+
"semi": false,
54+
"trailingComma": "none"
55+
},
4856
"xo": {
49-
"space": true,
57+
"prettier": true,
5058
"esnext": false,
5159
"ignore": [
5260
"mdast-comment-marker.js"

0 commit comments

Comments
 (0)