Skip to content

Commit 8ef1af9

Browse files
committed
Refactor code-style
1 parent 9ab9f3a commit 8ef1af9

File tree

13 files changed

+535
-439
lines changed

13 files changed

+535
-439
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 & 31 deletions
This file was deleted.

.prettierignore

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

karma.conf.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
const babel = require('@rollup/plugin-babel').default;
2-
const commonjs = require('@rollup/plugin-commonjs');
3-
const json = require('@rollup/plugin-json');
4-
const resolve = require('@rollup/plugin-node-resolve').default;
1+
const babel = require('@rollup/plugin-babel').default
2+
const commonjs = require('@rollup/plugin-commonjs')
3+
const json = require('@rollup/plugin-json')
4+
const resolve = require('@rollup/plugin-node-resolve').default
55

6-
module.exports = function karmaConfig(config) {
6+
module.exports = karmaConfig
7+
8+
function karmaConfig(config) {
79
config.set({
810
frameworks: ['jasmine'],
9-
files: [
10-
{ pattern: 'src/index.test.js' },
11-
],
11+
files: [{pattern: 'src/index.test.js'}],
1212
preprocessors: {
13-
'src/*.test.js': ['rollup'],
13+
'src/*.test.js': ['rollup']
1414
},
1515
rollupPreprocessor: {
16-
output: { format: 'iife' },
16+
output: {format: 'iife'},
1717
plugins: [
1818
resolve({
1919
browser: true,
20-
extensions: ['.mjs', '.js', '.json', '.node'],
20+
extensions: ['.mjs', '.js', '.json', '.node']
2121
}),
2222
json(),
2323
commonjs(),
2424
babel({
25-
presets: [
26-
['@babel/preset-env', { modules: false }],
27-
],
28-
babelrc: false,
29-
}),
30-
],
31-
},
32-
});
33-
};
25+
presets: [['@babel/preset-env', {modules: false}]],
26+
babelrc: false
27+
})
28+
]
29+
}
30+
})
31+
}

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@
4141
"@rollup/plugin-commonjs": "^18.0.0",
4242
"@rollup/plugin-json": "^4.0.0",
4343
"@rollup/plugin-node-resolve": "^11.0.0",
44-
"babel-eslint": "^10.0.0",
4544
"babel-jest": "^26.0.0",
46-
"eslint": "^7.0.0",
47-
"eslint-config-airbnb-base": "^14.0.0",
48-
"eslint-plugin-import": "^2.0.0",
4945
"glob": "^7.0.0",
5046
"hastscript": "^6.0.0",
5147
"jasmine-core": "^3.0.0",
@@ -57,15 +53,17 @@
5753
"karma-mocha-reporter": "^2.0.0",
5854
"karma-rollup-preprocessor": "^7.0.0",
5955
"karma-safari-launcher": "^1.0.0",
56+
"prettier": "^2.0.0",
6057
"remark-cli": "^9.0.0",
6158
"remark-preset-wooorm": "^8.0.0",
6259
"rollup": "^2.0.0",
63-
"w3c-xmlserializer": "^2.0.0"
60+
"w3c-xmlserializer": "^2.0.0",
61+
"xo": "^0.38.0"
6462
},
6563
"scripts": {
6664
"clean": "rm -rf dist",
6765
"build": "rollup -c",
68-
"format": "remark . -qfo && eslint . --fix",
66+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
6967
"test:api": "jest",
7068
"test:karma": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless,Safari",
7169
"test:karma:chrome": "karma start --single-run --browsers ChromeHeadless",
@@ -74,6 +72,17 @@
7472
"test:dev": "jest --watchAll",
7573
"test": "yarn build && yarn format && yarn test:api"
7674
},
75+
"prettier": {
76+
"tabWidth": 2,
77+
"useTabs": false,
78+
"singleQuote": true,
79+
"bracketSpacing": false,
80+
"semi": false,
81+
"trailingComma": "none"
82+
},
83+
"xo": {
84+
"prettier": true
85+
},
7786
"jest": {
7887
"collectCoverage": true,
7988
"coveragePathIgnorePatterns": [

rollup.config.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import babel from '@rollup/plugin-babel';
1+
import babel from '@rollup/plugin-babel'
22

3-
import pkg from './package.json';
3+
import pkg from './package.json'
44

5-
export default {
5+
const config = {
66
input: 'src/index.js',
77
output: [
8-
{ file: pkg.main, format: 'cjs', exports: 'default' },
9-
{ file: pkg.module, format: 'es' },
8+
{file: pkg.main, format: 'cjs', exports: 'default'},
9+
{file: pkg.module, format: 'es'}
1010
],
1111
plugins: [
1212
babel({
13-
presets: [
14-
['@babel/preset-env', { modules: false }],
15-
],
16-
babelrc: false,
17-
}),
13+
presets: [['@babel/preset-env', {modules: false}]],
14+
babelrc: false
15+
})
1816
],
1917
external: [
2018
'property-information/find',
2119
'property-information/html',
2220
'property-information/svg',
23-
'web-namespaces',
24-
],
25-
};
21+
'web-namespaces'
22+
]
23+
}
24+
25+
export default config

src/__fixtures__/svg-advanced/index.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@
77
"type": "element",
88
"tagName": "svg",
99
"properties": {
10-
"className": [
11-
"icon"
12-
],
10+
"className": ["icon"],
1311
"ariaLabel": "Verified",
14-
"viewBox": [
15-
0,
16-
0,
17-
16,
18-
16
19-
],
12+
"viewBox": [0, 0, 16, 16],
2013
"width": 18,
2114
"height": 18,
2215
"role": "img"

src/__fixtures__/svg/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@
5858
"value": "\n"
5959
}
6060
]
61-
}
61+
}

src/fixtures.test.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
import glob from 'glob';
1+
/* eslint-env jest, browser */
42

5-
import serializeNodeToHtmlString from './utils';
6-
import toDOM from './index';
3+
import fs from 'fs'
4+
import path from 'path'
5+
import glob from 'glob'
6+
import serializeNodeToHtmlString from './utils.js'
7+
import toDOM from './index.js'
78

89
describe('fixtures', () => {
9-
const root = path.join(__dirname, '__fixtures__');
10-
const fixturePaths = glob.sync(path.join(root, '**/*/'));
10+
const root = path.join(__dirname, '__fixtures__')
11+
const fixturePaths = glob.sync(path.join(root, '**/*/'))
12+
let index = -1
1113

12-
fixturePaths.forEach((fixturePath) => {
13-
const fixture = path.relative(root, fixturePath);
14-
const fixtureInput = path.join(fixturePath, 'index.json');
15-
const fixtureOutput = path.join(fixturePath, 'index.html');
14+
while (++index < fixturePaths.length) {
15+
each(fixturePaths[index])
16+
}
17+
18+
function each(fixturePath) {
19+
const fixture = path.relative(root, fixturePath)
20+
const fixtureInput = path.join(fixturePath, 'index.json')
21+
const fixtureOutput = path.join(fixturePath, 'index.html')
1622

1723
test(fixture, () => {
18-
const fixtureData = JSON.parse(fs.readFileSync(fixtureInput));
19-
const parsedActual = serializeNodeToHtmlString(toDOM(fixtureData));
24+
const fixtureData = JSON.parse(fs.readFileSync(fixtureInput))
25+
const parsedActual = serializeNodeToHtmlString(toDOM(fixtureData))
2026

21-
let parsedExpected;
27+
let parsedExpected
2228

2329
try {
24-
parsedExpected = fs.readFileSync(fixtureOutput).toString().trim();
25-
} catch (e) {
26-
fs.writeFileSync(fixtureOutput, parsedActual);
27-
return;
30+
parsedExpected = fs.readFileSync(fixtureOutput).toString().trim()
31+
} catch {
32+
fs.writeFileSync(fixtureOutput, parsedActual)
33+
return
2834
}
2935

30-
expect(parsedActual).toEqual(parsedExpected);
31-
});
32-
});
33-
});
36+
expect(parsedActual).toEqual(parsedExpected)
37+
})
38+
}
39+
})

0 commit comments

Comments
 (0)