@@ -25,35 +25,31 @@ program
25
25
. version ( pkg . version )
26
26
. argument (
27
27
'[ecmaVersion]' ,
28
- 'ecmaVersion to check files against. Can be: es3, es4, es5, es6/es2015, es7/es2016, es8/es2017, es9/es2018, es10/es2019'
29
- )
30
- . argument (
31
- '[files...]' ,
32
- 'a glob of files to to test the EcmaScript version against'
28
+ 'ecmaVersion to check files against. Can be: es3, es4, es5, es6/es2015, es7/es2016, es8/es2017, es9/es2018, es10/es2019' ,
33
29
)
30
+ . argument ( '[files...]' , 'a glob of files to to test the EcmaScript version against' )
34
31
. option ( '--module' , 'use ES modules' )
35
- . option (
36
- '--allow-hash-bang' ,
37
- 'if the code starts with #! treat it as a comment'
38
- )
32
+ . option ( '--allow-hash-bang' , 'if the code starts with #! treat it as a comment' )
39
33
. option ( '--not <files>' , 'folder or file names to skip' )
40
34
. option ( '--no-color' , 'disable use of colors in output' )
41
35
. option ( '-v, --verbose' , 'verbose mode: will also output debug messages' )
42
36
. option ( '--quiet' , 'quiet mode: only displays warn and error messages' )
43
37
. option (
44
38
'--silent' ,
45
- 'silent mode: does not output anything, giving no indication of success or failure other than the exit code'
39
+ 'silent mode: does not output anything, giving no indication of success or failure other than the exit code' ,
46
40
)
47
41
. action ( ( ecmaVersionArg , filesArg , options ) => {
48
42
const logger = winston . createLogger ( )
49
- logger . add ( new winston . transports . Console ( {
50
- silent : options . silent ,
51
- level : options . verbose ? 'silly' : options . quiet ? 'warn' : 'info' ,
52
- format : winston . format . combine (
53
- ...supportsColor . stdout ? [ winston . format . colorize ( ) ] : [ ] ,
54
- winston . format . simple ( )
55
- )
56
- } ) )
43
+ logger . add (
44
+ new winston . transports . Console ( {
45
+ silent : options . silent ,
46
+ level : options . verbose ? 'silly' : options . quiet ? 'warn' : 'info' ,
47
+ format : winston . format . combine (
48
+ ...( supportsColor . stdout ? [ winston . format . colorize ( ) ] : [ ] ) ,
49
+ winston . format . simple ( ) ,
50
+ ) ,
51
+ } ) ,
52
+ )
57
53
58
54
const configFilePath = path . resolve ( process . cwd ( ) , '.escheckrc' )
59
55
@@ -63,34 +59,22 @@ program
63
59
* - If one exists, default to those options
64
60
* - If no command line arguments are passed in
65
61
*/
66
- const config = fs . existsSync ( configFilePath )
67
- ? JSON . parse ( fs . readFileSync ( configFilePath ) )
68
- : { }
69
- const expectedEcmaVersion = ecmaVersionArg
70
- ? ecmaVersionArg
71
- : config . ecmaVersion
72
- const files =
73
- filesArg && filesArg . length ? filesArg : [ ] . concat ( config . files )
62
+ const config = fs . existsSync ( configFilePath ) ? JSON . parse ( fs . readFileSync ( configFilePath ) ) : { }
63
+ const expectedEcmaVersion = ecmaVersionArg ? ecmaVersionArg : config . ecmaVersion
64
+ const files = filesArg && filesArg . length ? filesArg : [ ] . concat ( config . files )
74
65
const esmodule = options . module ? options . module : config . module
75
- const allowHashBang = options . allowHashBang
76
- ? options . allowHashBang
77
- : config . allowHashBang
78
- const pathsToIgnore =
79
- options . not
80
- ? options . not . split ( ',' )
81
- : [ ] . concat ( config . not || [ ] )
66
+ const allowHashBang = options . allowHashBang ? options . allowHashBang : config . allowHashBang
67
+ const pathsToIgnore = options . not ? options . not . split ( ',' ) : [ ] . concat ( config . not || [ ] )
82
68
83
69
if ( ! expectedEcmaVersion ) {
84
70
logger . error (
85
- 'No ecmaScript version passed in or found in .escheckrc. Please set your ecmaScript version in the CLI or in .escheckrc'
71
+ 'No ecmaScript version passed in or found in .escheckrc. Please set your ecmaScript version in the CLI or in .escheckrc' ,
86
72
)
87
73
process . exit ( 1 )
88
74
}
89
75
90
76
if ( ! files || ! files . length ) {
91
- logger . error (
92
- 'No files were passed in please pass in a list of files to es-check!'
93
- )
77
+ logger . error ( 'No files were passed in please pass in a list of files to es-check!' )
94
78
process . exit ( 1 )
95
79
}
96
80
@@ -151,9 +135,7 @@ program
151
135
ecmaVersion = '2021'
152
136
break
153
137
default :
154
- logger . error (
155
- 'Invalid ecmaScript version, please pass a valid version, use --help for help'
156
- )
138
+ logger . error ( 'Invalid ecmaScript version, please pass a valid version, use --help for help' )
157
139
process . exit ( 1 )
158
140
}
159
141
@@ -172,10 +154,7 @@ program
172
154
const filterForIgnore = ( globbedFiles ) => {
173
155
if ( expandedPathsToIgnore && expandedPathsToIgnore . length > 0 ) {
174
156
const filtered = globbedFiles . filter (
175
- ( filePath ) =>
176
- ! expandedPathsToIgnore . some ( ( ignoreValue ) =>
177
- filePath . includes ( ignoreValue )
178
- )
157
+ ( filePath ) => ! expandedPathsToIgnore . some ( ( ignoreValue ) => filePath . includes ( ignoreValue ) ) ,
179
158
)
180
159
return filtered
181
160
}
@@ -198,38 +177,31 @@ program
198
177
const globbedFiles = glob . sync ( pattern , globOpts )
199
178
200
179
if ( globbedFiles . length === 0 ) {
201
- logger . error (
202
- `ES-Check: Did not find any files to check for ${ pattern } .`
203
- )
180
+ logger . error ( `ES-Check: Did not find any files to check for ${ pattern } .` )
204
181
process . exit ( 1 )
205
182
}
206
183
207
184
const filteredFiles = filterForIgnore ( globbedFiles )
208
185
209
186
filteredFiles . forEach ( ( file ) => {
210
187
const code = fs . readFileSync ( file , 'utf8' )
211
-
212
188
logger . debug ( `ES-Check: checking ${ file } ` )
213
189
try {
214
190
acorn . parse ( code , acornOpts )
215
191
} catch ( err ) {
216
- logger . debug (
217
- `ES-Check: failed to parse file: ${ file } \n - error: ${ err } `
218
- )
192
+ logger . debug ( `ES-Check: failed to parse file: ${ file } \n - error: ${ err } ` )
219
193
const errorObj = {
220
194
err,
221
195
stack : err . stack ,
222
- file
196
+ file,
223
197
}
224
198
errArray . push ( errorObj )
225
199
}
226
200
} )
227
201
} )
228
202
229
203
if ( errArray . length > 0 ) {
230
- logger . error (
231
- `ES-Check: there were ${ errArray . length } ES version matching errors.`
232
- )
204
+ logger . error ( `ES-Check: there were ${ errArray . length } ES version matching errors.` )
233
205
errArray . forEach ( ( o ) => {
234
206
logger . info ( `
235
207
ES-Check Error:
0 commit comments