@@ -43,8 +43,7 @@ class Purgecss {
43
43
* @param {string } configFile Path of the config file
44
44
*/
45
45
loadConfigFile ( configFile : string ) {
46
- const pathConfig =
47
- typeof configFile === 'undefined' ? CONFIG_FILENAME : configFile
46
+ const pathConfig = typeof configFile === 'undefined' ? CONFIG_FILENAME : configFile
48
47
let options
49
48
try {
50
49
const t = path . resolve ( process . cwd ( ) , pathConfig )
@@ -61,10 +60,8 @@ class Purgecss {
61
60
*/
62
61
checkOptions ( options : Options ) {
63
62
if ( typeof options !== 'object' ) throw new TypeError ( ERROR_OPTIONS_TYPE )
64
- if ( ! options . content || ! options . content . length )
65
- throw new Error ( ERROR_MISSING_CONTENT )
66
- if ( ! options . css || ! options . css . length )
67
- throw new Error ( ERROR_MISSING_CSS )
63
+ if ( ! options . content || ! options . content . length ) throw new Error ( ERROR_MISSING_CONTENT )
64
+ if ( ! options . css || ! options . css . length ) throw new Error ( ERROR_MISSING_CSS )
68
65
if ( options . output && typeof options . output !== 'string' )
69
66
throw new TypeError ( ERROR_OUTPUT_TYPE )
70
67
if ( options . extractors && ! Array . isArray ( options . extractors ) )
@@ -73,8 +70,7 @@ class Purgecss {
73
70
throw new TypeError ( ERROR_WHITELIST_TYPE )
74
71
if ( options . stdout && typeof options . stdout !== 'boolean' )
75
72
throw new TypeError ( ERROR_STDOUT_TYPE )
76
- if ( options . info && typeof options . info !== 'boolean' )
77
- throw new TypeError ( ERROR_INFO_TYPE )
73
+ if ( options . info && typeof options . info !== 'boolean' ) throw new TypeError ( ERROR_INFO_TYPE )
78
74
if ( options . rejected && typeof options . rejected !== 'boolean' )
79
75
throw new TypeError ( ERROR_REJECTED_TYPE )
80
76
}
@@ -84,16 +80,11 @@ class Purgecss {
84
80
*/
85
81
purge ( ) {
86
82
// Get selectors from content files
87
- let cssClasses = this . extractFileSelector (
88
- this . options . content ,
89
- this . options . extractors
90
- )
83
+ let cssClasses = this . extractFileSelector ( this . options . content , this . options . extractors )
91
84
// Get css selectors and remove unused ones
92
85
let files = [ ]
93
86
for ( let file of this . options . css ) {
94
- const cssContent = this . options . stdin
95
- ? file
96
- : fs . readFileSync ( file , 'utf8' )
87
+ const cssContent = this . options . stdin ? file : fs . readFileSync ( file , 'utf8' )
97
88
files . push ( {
98
89
file,
99
90
css : this . getSelectorsCss ( cssContent , cssClasses )
@@ -107,10 +98,7 @@ class Purgecss {
107
98
* @param {array } files Array of files path or glob pattern
108
99
* @param {array } extractors Array of extractors
109
100
*/
110
- extractFileSelector (
111
- files : Array < string > ,
112
- extractors ?: Array < ExtractorsObj >
113
- ) : Set < string > {
101
+ extractFileSelector ( files : Array < string > , extractors ?: Array < ExtractorsObj > ) : Set < string > {
114
102
let selectors = new Set ( )
115
103
for ( let globfile of files ) {
116
104
let filesnames = [ ]
@@ -122,10 +110,7 @@ class Purgecss {
122
110
for ( let file of filesnames ) {
123
111
const content = fs . readFileSync ( file , 'utf8' )
124
112
const extractor = this . getFileExtractor ( file , extractors )
125
- selectors = new Set (
126
- ...selectors ,
127
- this . extractSelectors ( content , extractor )
128
- )
113
+ selectors = new Set ( ...selectors , this . extractSelectors ( content , extractor ) )
129
114
}
130
115
}
131
116
@@ -190,10 +175,7 @@ class Purgecss {
190
175
}
191
176
}
192
177
193
- let keepSelector = this . shouldKeepSelector (
194
- selectors ,
195
- selectorsInRule
196
- )
178
+ let keepSelector = this . shouldKeepSelector ( selectors , selectorsInRule )
197
179
if ( ! keepSelector ) {
198
180
selector . remove ( )
199
181
}
@@ -227,11 +209,9 @@ class Purgecss {
227
209
isRuleEmpty ( node : Object ) {
228
210
if (
229
211
( node . type === 'decl' && ! node . value ) ||
230
- ( ( node . type === 'rule' && ! node . selector ) ||
231
- ( node . nodes && ! node . nodes . length ) ) ||
212
+ ( ( node . type === 'rule' && ! node . selector ) || ( node . nodes && ! node . nodes . length ) ) ||
232
213
( node . type === 'atrule' &&
233
- ( ( ! node . nodes && ! node . params ) ||
234
- ( ! node . params && ! node . nodes . length ) ) )
214
+ ( ( ! node . nodes && ! node . params ) || ( ! node . params && ! node . nodes . length ) ) )
235
215
) {
236
216
return true
237
217
}
@@ -243,10 +223,7 @@ class Purgecss {
243
223
* @param {Set } selectorsInContent Set of css selectors found in the content files
244
224
* @param {Array } selectorsInRule Array of selectors
245
225
*/
246
- shouldKeepSelector (
247
- selectorsInContent : Set < string > ,
248
- selectorsInRule : Array < string >
249
- ) {
226
+ shouldKeepSelector ( selectorsInContent : Set < string > , selectorsInRule : Array < string > ) {
250
227
for ( let selector of selectorsInRule ) {
251
228
// legacy
252
229
if ( this . options . legacy ) {
@@ -258,16 +235,13 @@ class Purgecss {
258
235
keepSelector = true
259
236
}
260
237
if ( keepSelector ) return true
261
- if ( selectorsInContent . has ( selector ) || CSS_WHITELIST . includes ( selector ) ) return true
262
- }
263
- // non legacy extractors
264
- else {
238
+ if ( selectorsInContent . has ( selector ) || CSS_WHITELIST . includes ( selector ) )
239
+ return true
240
+ } else {
241
+ // non legacy extractors
265
242
// pseudo class
266
243
if ( selector . startsWith ( ':' ) ) continue
267
- if (
268
- ! ( selectorsInContent . has ( selector ) ||
269
- CSS_WHITELIST . includes ( selector ) )
270
- ) {
244
+ if ( ! ( selectorsInContent . has ( selector ) || CSS_WHITELIST . includes ( selector ) ) ) {
271
245
return false
272
246
}
273
247
}
0 commit comments