Skip to content

Commit 29e8dc6

Browse files
committed
Refactor code-style
1 parent 10be7d9 commit 29e8dc6

File tree

14 files changed

+191
-6869
lines changed

14 files changed

+191
-6869
lines changed

.babelrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"presets": [
3-
["@babel/env"]
4-
]
2+
"presets": [["@babel/env"]]
53
}

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ yarn-error.log
44
.DS_Store
55
/dist
66
/coverage
7+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage/
2+
dist/
3+
*.html
4+
*.md

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,33 @@
3737
"@babel/core": "^7.0.0",
3838
"@babel/preset-env": "^7.0.0",
3939
"@rollup/plugin-babel": "^5.0.0",
40-
"babel-eslint": "^10.0.0",
4140
"babel-jest": "^26.0.0",
42-
"eslint": "^7.0.0",
43-
"eslint-config-airbnb-base": "^14.0.0",
44-
"eslint-plugin-import": "^2.0.0",
4541
"glob": "^7.0.0",
4642
"jest-cli": "^26.0.0",
43+
"prettier": "^2.0.0",
4744
"remark-cli": "^9.0.0",
4845
"remark-preset-wooorm": "^8.0.0",
49-
"rollup": "^2.0.0"
46+
"rollup": "^2.0.0",
47+
"xo": "^0.39.0"
5048
},
5149
"scripts": {
5250
"build": "rollup -c",
53-
"format": "remark . -qfo && eslint . --fix",
51+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
5452
"test:api": "jest",
5553
"test:dev": "jest --watchAll",
5654
"test": "yarn build && yarn format && yarn test:api"
5755
},
56+
"prettier": {
57+
"tabWidth": 2,
58+
"useTabs": false,
59+
"singleQuote": true,
60+
"bracketSpacing": false,
61+
"semi": false,
62+
"trailingComma": "none"
63+
},
64+
"xo": {
65+
"prettier": true
66+
},
5867
"jest": {
5968
"collectCoverage": true,
6069
"coveragePathIgnorePatterns": [

rollup.config.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
import babel from '@rollup/plugin-babel';
2-
import pkg from './package.json';
1+
import babel from '@rollup/plugin-babel'
2+
import pkg from './package.json'
33

4-
export default {
4+
const config = {
55
input: 'src/index.js',
66
output: [
7-
{ file: pkg.main, format: 'cjs' },
8-
{ file: pkg.module, format: 'es' },
7+
{file: pkg.main, format: 'cjs'},
8+
{file: pkg.module, format: 'es'}
99
],
1010
plugins: [
1111
babel({
12-
presets: [
13-
['@babel/preset-env', { modules: false }],
14-
],
15-
babelrc: false,
16-
}),
12+
presets: [['@babel/preset-env', {modules: false}]],
13+
babelrc: false
14+
})
1715
],
18-
external: [
19-
'hastscript/html',
20-
'hastscript/svg',
21-
'web-namespaces',
22-
],
23-
};
16+
external: ['hastscript/html', 'hastscript/svg', 'web-namespaces']
17+
}
18+
19+
export default config

src/__fixtures__/doctype-nameless/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
]
2828
}
2929
]
30-
}
30+
}

src/__fixtures__/doctype/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
]
2828
}
2929
]
30-
}
30+
}

src/__fixtures__/svg/index.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@
8585
"type": "element",
8686
"tagName": "text",
8787
"properties": {
88-
"systemLanguage": [
89-
"en"
90-
]
88+
"systemLanguage": ["en"]
9189
},
9290
"children": [
9391
{

src/index.js

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import ns from 'web-namespaces';
2-
import h from 'hastscript/html';
3-
import s from 'hastscript/svg';
1+
import ns from 'web-namespaces'
2+
import h from 'hastscript/html.js'
3+
import s from 'hastscript/svg.js'
44

5-
const ELEMENT_NODE = 1;
6-
const TEXT_NODE = 3;
7-
const COMMENT_NODE = 8;
8-
const DOCUMENT_NODE = 9;
9-
const DOCUMENT_TYPE_NODE = 10;
10-
const DOCUMENT_FRAGMENT_NODE = 11;
5+
const ELEMENT_NODE = 1
6+
const TEXT_NODE = 3
7+
const COMMENT_NODE = 8
8+
const DOCUMENT_NODE = 9
9+
const DOCUMENT_TYPE_NODE = 10
10+
const DOCUMENT_FRAGMENT_NODE = 11
1111

1212
function transform(value) {
13-
const node = value || {};
13+
const node = value || {}
1414

1515
switch (node.nodeType) {
1616
case ELEMENT_NODE:
17-
return element(node);
17+
return element(node)
1818
case DOCUMENT_NODE:
1919
case DOCUMENT_FRAGMENT_NODE:
20-
return root(node);
20+
return root(node)
2121
case TEXT_NODE:
22-
return text(node);
22+
return text(node)
2323
case COMMENT_NODE:
24-
return comment(node);
24+
return comment(node)
2525
case DOCUMENT_TYPE_NODE:
26-
return doctype(node);
26+
return doctype(node)
2727
default:
28-
return null;
28+
return null
2929
}
3030
}
3131

3232
// Transform a document.
3333
function root(node) {
34-
return { type: 'root', children: all(node) };
34+
return {type: 'root', children: all(node)}
3535
}
3636

3737
// Transform a doctype.
@@ -40,59 +40,60 @@ function doctype(node) {
4040
type: 'doctype',
4141
name: node.name || '',
4242
public: node.publicId || null,
43-
system: node.systemId || null,
44-
};
43+
system: node.systemId || null
44+
}
4545
}
4646

4747
// Transform text.
4848
function text(node) {
49-
return { type: 'text', value: node.nodeValue };
49+
return {type: 'text', value: node.nodeValue}
5050
}
5151

5252
// Transform a comment.
5353
function comment(node) {
54-
return { type: 'comment', value: node.nodeValue };
54+
return {type: 'comment', value: node.nodeValue}
5555
}
5656

5757
// Transform an element.
5858
function element(node) {
59-
const space = node.namespaceURI;
60-
const fn = space === ns.svg ? s : h;
61-
const tagName = space === ns.html ? node.tagName.toLowerCase() : node.tagName;
62-
const content = space === ns.html && tagName === 'template' ? node.content : node;
63-
const attributes = node.getAttributeNames();
64-
const { length } = attributes;
65-
const props = {};
66-
let index = 0;
59+
const space = node.namespaceURI
60+
const fn = space === ns.svg ? s : h
61+
const tagName = space === ns.html ? node.tagName.toLowerCase() : node.tagName
62+
const content =
63+
space === ns.html && tagName === 'template' ? node.content : node
64+
const attributes = node.getAttributeNames()
65+
const {length} = attributes
66+
const props = {}
67+
let index = 0
6768

6869
while (index < length) {
69-
const key = attributes[index];
70-
props[key] = node.getAttribute(key);
71-
index += 1;
70+
const key = attributes[index]
71+
props[key] = node.getAttribute(key)
72+
index += 1
7273
}
7374

74-
return fn(tagName, props, all(content));
75+
return fn(tagName, props, all(content))
7576
}
7677

7778
function all(node) {
78-
const nodes = node.childNodes;
79-
const { length } = nodes;
80-
const children = [];
81-
let index = 0;
79+
const nodes = node.childNodes
80+
const {length} = nodes
81+
const children = []
82+
let index = 0
8283

8384
while (index < length) {
84-
const child = transform(nodes[index]);
85+
const child = transform(nodes[index])
8586

8687
if (child !== null) {
87-
children.push(child);
88+
children.push(child)
8889
}
8990

90-
index += 1;
91+
index += 1
9192
}
9293

93-
return children;
94+
return children
9495
}
9596

9697
export default function fromDOM(node) {
97-
return transform(node) || { type: 'root', children: [] };
98+
return transform(node) || {type: 'root', children: []}
9899
}

0 commit comments

Comments
 (0)