Skip to content

Commit d3d9d8b

Browse files
committed
style: after lint
1 parent 332eef4 commit d3d9d8b

File tree

5 files changed

+153
-150
lines changed

5 files changed

+153
-150
lines changed

ava.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const config = {
33
timeout: '1m',
44
files: ['test/test-*'],
55
extensions: ['ts'],
6-
require: ['esm', 'esbuild-register']
6+
require: ['esm', 'esbuild-register'],
77
};
88

99
export default config;

src/index.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import {Attributes, NodeText, NodeTag} from 'posthtml-parser';
55
export enum quoteStyleEnum {
66
Smart,
77
Single,
8-
Double
8+
Double,
99
}
1010

1111
export enum closingSingleTagOptionEnum {
1212
tag = 'tag',
1313
slash = 'slash',
1414
default = 'default',
15-
closeAs = 'closeAs'
15+
closeAs = 'closeAs',
1616
}
1717

1818
export enum closingSingleTagTypeEnum {
1919
tag = 'tag',
2020
slash = 'slash',
21-
default = 'default'
21+
default = 'default',
2222
}
2323

2424
export type Node = NodeText | NodeTag & {
@@ -90,7 +90,7 @@ const SINGLE_TAGS: Array<string | RegExp> = [
9090
'param',
9191
'source',
9292
'track',
93-
'wbr'
93+
'wbr',
9494
];
9595

9696
const ATTRIBUTE_QUOTES_REQUIRED = /[\t\n\f\r "'`=<>]/;
@@ -99,7 +99,7 @@ const defaultOptions = {
9999
closingSingleTag: undefined,
100100
quoteAllAttributes: true,
101101
replaceQuote: true,
102-
quoteStyle: quoteStyleEnum.Double
102+
quoteStyle: quoteStyleEnum.Double,
103103
};
104104

105105
export function render(tree?: Node | Node[], options: Options = {}): string {
@@ -112,20 +112,20 @@ export function render(tree?: Node | Node[], options: Options = {}): string {
112112
options = {
113113
...defaultOptions,
114114
...options,
115-
singleTags: st
115+
singleTags: st,
116116
};
117117

118118
const {
119119
singleTags,
120120
closingSingleTag,
121121
quoteAllAttributes,
122122
replaceQuote,
123-
quoteStyle
123+
quoteStyle,
124124
} = options;
125125

126126
const singleRegExp: RegExp[] = singleTags
127-
?.filter((tag): tag is RegExp => tag instanceof RegExp) ??
128-
[];
127+
?.filter((tag): tag is RegExp => tag instanceof RegExp)
128+
?? [];
129129

130130
if (!Array.isArray(tree)) {
131131
if (!tree) {
@@ -143,11 +143,11 @@ export function render(tree?: Node | Node[], options: Options = {}): string {
143143
for (const node of tree) {
144144
// Undefined, null, '', [], NaN
145145
if (
146-
node === false ||
147-
node === undefined ||
148-
node === null ||
149-
(typeof node === 'string' && node.length === 0) ||
150-
Number.isNaN(node)
146+
node === false
147+
|| node === undefined
148+
|| node === null
149+
|| (typeof node === 'string' && node.length === 0)
150+
|| Number.isNaN(node)
151151
) {
152152
continue;
153153
}
@@ -194,7 +194,7 @@ export function render(tree?: Node | Node[], options: Options = {}): string {
194194
const closeAs = {
195195
[closingSingleTagTypeEnum.tag]: `></${tag}>`,
196196
[closingSingleTagTypeEnum.slash]: ' />',
197-
[closingSingleTagTypeEnum.default]: '>'
197+
[closingSingleTagTypeEnum.default]: '>',
198198
};
199199

200200
if (isSingleTag(tag)) {
@@ -208,9 +208,9 @@ export function render(tree?: Node | Node[], options: Options = {}): string {
208208

209209
break;
210210
case closingSingleTagOptionEnum.closeAs:
211-
result += closeAs[node.closeAs ?
212-
closingSingleTagTypeEnum[node.closeAs] :
213-
closingSingleTagTypeEnum.default];
211+
result += closeAs[node.closeAs
212+
? closingSingleTagTypeEnum[node.closeAs]
213+
: closingSingleTagTypeEnum.default];
214214

215215
break;
216216
default:
@@ -221,9 +221,9 @@ export function render(tree?: Node | Node[], options: Options = {}): string {
221221
result += html(node.content);
222222
}
223223
} else if (closingSingleTag === closingSingleTagOptionEnum.closeAs && node.closeAs) {
224-
const type = node.closeAs ?
225-
closingSingleTagTypeEnum[node.closeAs] :
226-
closingSingleTagTypeEnum.default;
224+
const type = node.closeAs
225+
? closingSingleTagTypeEnum[node.closeAs]
226+
: closingSingleTagTypeEnum.default;
227227
result += `${closeAs[type]}${html(node.content)}`;
228228
} else {
229229
result += `>${html(node.content)}</${tag}>`;

test/templates/parser.ts

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,182 +3,182 @@ const tree = ['<!DOCTYPE html>', '\n', {
33
tag: 'html',
44
attrs: {
55
xmlns: 'http://www.w3.org/1999/xhtml',
6-
lang: 'en-US'
6+
lang: 'en-US',
77
},
88
content: ['\n', {
99
tag: 'head',
1010
content: ['\n ', {
1111
tag: 'meta',
1212
attrs: {
13-
charset: 'utf-8'
14-
}
13+
charset: 'utf-8',
14+
},
1515
}, '\n ', {
1616
tag: 'title',
17-
content: ['Html']
17+
content: ['Html'],
1818
}, '\n ', {
1919
tag: 'meta',
2020
attrs: {
2121
'http-equiv': 'X-UA-Compatible',
22-
content: 'IE=EmulateIE7, IE=9'
23-
}
22+
content: 'IE=EmulateIE7, IE=9',
23+
},
2424
}, '\n ', {
2525
tag: 'meta',
2626
attrs: {
2727
name: 'viewport',
28-
content: 'width=device-width, initial-scale=1'
29-
}
28+
content: 'width=device-width, initial-scale=1',
29+
},
3030
}, '\n ', {
3131
tag: 'meta',
3232
attrs: {
3333
name: 'description',
34-
content: 'Description'
35-
}
34+
content: 'Description',
35+
},
3636
}, '\n\n ', {
3737
tag: 'meta',
3838
attrs: {
3939
property: 'og:url',
40-
content: 'http://github.com/posthtml'
41-
}
40+
content: 'http://github.com/posthtml',
41+
},
4242
}, '\n ', {
4343
tag: 'meta',
4444
attrs: {
4545
property: 'og:type',
46-
content: 'website'
47-
}
46+
content: 'website',
47+
},
4848
}, '\n ', {
4949
tag: 'meta',
5050
attrs: {
5151
property: 'og:site_name',
52-
content: 'PostHTML'
53-
}
52+
content: 'PostHTML',
53+
},
5454
}, '\n\n ', {
5555
tag: 'link',
5656
attrs: {
5757
rel: 'stylesheet',
5858
type: 'text/css',
59-
href: 'path/to/file.css'
60-
}
59+
href: 'path/to/file.css',
60+
},
6161
}, '\n ', {
6262
tag: 'script',
6363
attrs: {
6464
src: 'path/to/file.js',
6565
type: 'text/javascript',
66-
charset: 'utf-8'
67-
}
66+
charset: 'utf-8',
67+
},
6868
}, '\n\n ', {
6969
tag: 'script',
70-
content: ['\n console.log(\'PostHTML!\');\n ']
71-
}, '\n']
70+
content: ['\n console.log(\'PostHTML!\');\n '],
71+
}, '\n'],
7272
}, '\n', {
7373
tag: 'body',
7474
attrs: {
75-
onload: 'try{if(!google.j.b){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.focus();}}catch(e){}if(document.images)new Image().src=\'/images/nav_logo231.png\''
75+
onload: 'try{if(!google.j.b){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.focus();}}catch(e){}if(document.images)new Image().src=\'/images/nav_logo231.png\'',
7676
},
7777
content: ['\n\n ', {
7878
tag: 'h1',
79-
content: ['Title']
79+
content: ['Title'],
8080
}, '\n ', {
8181
tag: 'p',
82-
content: ['Lorem ipsum dolor sit amet...']
82+
content: ['Lorem ipsum dolor sit amet...'],
8383
}, '\n\n ', {
8484
tag: 'section',
8585
attrs: {
8686
class: 'foo',
87-
style: 'color: red;'
87+
style: 'color: red;',
8888
},
8989
content: ['\n ', {
9090
tag: 'header',
9191
attrs: {
9292
class: 'foo bar',
9393
style: 'color: blue; border: 1px solid',
94-
id: 'id'
94+
id: 'id',
9595
},
9696
content: ['\n ', {
9797
tag: 'div',
9898
attrs: {
9999
class: 'foo bar baz',
100100
id: 'idd',
101-
'data-url': 'url/to/'
101+
'data-url': 'url/to/',
102102
},
103103
content: ['\n ', {
104104
tag: 'span',
105105
attrs: {
106106
id: 'idd',
107-
'data-data': '{ foo: \'bar\' }'
107+
'data-data': '{ foo: \'bar\' }',
108108
},
109109
content: ['\n ', {
110110
tag: 'a',
111111
attrs: {
112-
href: '#'
112+
href: '#',
113113
},
114114
content: ['\n ', {
115115
tag: 'img',
116116
attrs: {
117-
src: 'path/to/img'
118-
}
119-
}, '\n Link\n ']
120-
}, '\n ']
121-
}, '\n ']
122-
}, '\n ']
123-
}, '\n ']
117+
src: 'path/to/img',
118+
},
119+
}, '\n Link\n '],
120+
}, '\n '],
121+
}, '\n '],
122+
}, '\n '],
123+
}, '\n '],
124124
}, '\n\n ', {
125125
content: {
126-
tag: 'hr'
127-
}
126+
tag: 'hr',
127+
},
128128
}, '\n\n ', {
129129
tag: 'script',
130130
attrs: {
131-
type: 'text/javascript'
131+
type: 'text/javascript',
132132
},
133133
content: [
134134
'\n (function(){function k(a){++b;a=a||window.event;google.iTick(a.target||a.srcElement)}if(google.timers&&google.timers.load.t){var c,b,f;google.c.c.a&&(google.startTick("aft"),google.afte=!1);var g=document.getElementsByTagName("img");c=g.length;for(var d=b=0,a;d',
135-
'<c;++d)if(a=g[d],google.c.c.i&&"none"==a.style.display)++b;else{var h="string"!=typeof a.src||!a.src,e=h||a.complete;google.c.c.d?a.getAttribute("data-deferred")&&(e=!1,a.removeAttribute("data-deferred")):google.c.c.m&&h&&a.getAttribute("data-bsrc")&&\n (e=!1);e?++b:google.rll(a,!0,k)}f=c-b;google.rll(window,!1,function(){google.tick("load","ol");google.c.e("load","imc",String(b));google.c.e("load","imn",String(c));google.c.e("load","imp",String(f));google.unblockCSI("load","ol")});google.tick("load",["prt","iml"])}})();\n '
136-
]
135+
'<c;++d)if(a=g[d],google.c.c.i&&"none"==a.style.display)++b;else{var h="string"!=typeof a.src||!a.src,e=h||a.complete;google.c.c.d?a.getAttribute("data-deferred")&&(e=!1,a.removeAttribute("data-deferred")):google.c.c.m&&h&&a.getAttribute("data-bsrc")&&\n (e=!1);e?++b:google.rll(a,!0,k)}f=c-b;google.rll(window,!1,function(){google.tick("load","ol");google.c.e("load","imc",String(b));google.c.e("load","imn",String(c));google.c.e("load","imp",String(f));google.unblockCSI("load","ol")});google.tick("load",["prt","iml"])}})();\n ',
136+
],
137137
}, '\n\n ', {
138138
tag: 'script',
139139
attrs: {
140140
src: 'path/to/file2.js',
141141
type: 'text/javascript',
142-
charset: 'utf-8'
143-
}
144-
}, '\n']
145-
}, '\n']
142+
charset: 'utf-8',
143+
},
144+
}, '\n'],
145+
}, '\n'],
146146
}, '\n', {
147147
tag: false,
148-
content: [Number.NaN]
148+
content: [Number.NaN],
149149
}, {
150150
tag: false,
151-
content: [[]]
151+
content: [[]],
152152
}, {
153153
tag: false,
154-
content: ['']
154+
content: [''],
155155
}, {
156156
tag: false,
157-
content: [null]
157+
content: [null],
158158
}, {
159159
tag: false,
160-
content: [false]
160+
content: [false],
161161
}, {
162162
tag: false,
163-
content: [undefined]
163+
content: [undefined],
164164
}, {
165165
tag: false,
166-
content: Number.NaN
166+
content: Number.NaN,
167167
}, {
168168
tag: false,
169-
content: []
169+
content: [],
170170
}, {
171171
tag: false,
172-
content: ''
172+
content: '',
173173
}, {
174174
tag: false,
175-
content: null
175+
content: null,
176176
}, {
177177
tag: false,
178-
content: false
178+
content: false,
179179
}, {
180180
tag: false,
181-
content: undefined
181+
content: undefined,
182182
}, Number.NaN, [], '', null, false, undefined];
183183

184184
export default tree;

0 commit comments

Comments
 (0)