@@ -257,46 +257,47 @@ export class LintFile {
257
257
258
258
constructor ( file , { cwd, processUnsupportedTypes, write, fix = true , log = true , cache } = { } ) {
259
259
this . #file = File . new ( file ) ;
260
+ this . #cwd = cwd ;
260
261
this . #processUnsupportedTypes = Boolean ( processUnsupportedTypes ) ;
261
262
this . #write = Boolean ( write ) ;
262
263
this . #cache = cache || { } ;
263
264
this . #fix = Boolean ( fix ) ;
264
265
this . #log = Boolean ( log ) ;
266
+ }
267
+
268
+ // properties
269
+ get cwd ( ) {
270
+ return this . #cwd;
271
+ }
265
272
273
+ get path ( ) {
274
+ return this . #path;
275
+ }
276
+
277
+ // public
278
+ async run ( action ) {
266
279
if ( ! this . #file. path ) {
267
- throw new Error ( "File path is required" ) ;
280
+ return result ( [ 500 , "File path is required" ] ) ;
268
281
}
269
282
270
283
if ( path . isAbsolute ( this . #file. path ) ) {
271
284
this . #path = path . normalize ( this . #file. path ) ;
272
285
}
273
286
else {
274
- if ( ! cwd ) {
275
- throw new Error ( "Cwd is required" ) ;
287
+ if ( ! this . # cwd ) {
288
+ return result ( [ 500 , "Cwd is required when file path is relative" ] ) ;
276
289
}
277
290
278
- this . #path = path . normalize ( path . join ( cwd , this . #file. path ) ) ;
291
+ this . #path = path . normalize ( path . join ( this . # cwd, this . #file. path ) ) ;
279
292
}
280
293
281
294
this . #cwd = path . dirname ( this . #path ) ;
282
- }
283
-
284
- // properties
285
- get cwd ( ) {
286
- return this . #cwd;
287
- }
288
295
289
- get path ( ) {
290
- return this . #path;
291
- }
292
-
293
- // public
294
- async run ( action ) {
295
- if ( this . #write && ! this . path ) {
296
- throw new Error ( "Path is required" ) ;
296
+ if ( this . #write && ! this . #path ) {
297
+ return result ( [ 500 , "File path is required to write content" ] ) ;
297
298
}
298
299
299
- this . #fullPath = this . path ;
300
+ this . #fullPath = this . # path;
300
301
301
302
// read file content
302
303
this . #originalData = this . #data = await this . #file. text ( "utf8" ) ;
@@ -321,7 +322,7 @@ export class LintFile {
321
322
if ( this . #type ) {
322
323
const extnames = customMime . get ( this . #type. type ) ?. extnames ;
323
324
324
- if ( extnames ?. default && ! extnames . has ( path . extname ( this . path ) ) ) {
325
+ if ( extnames ?. default && ! extnames . has ( path . extname ( this . # path ) ) ) {
325
326
this . #fullPath += extnames . default ;
326
327
}
327
328
}
@@ -340,7 +341,7 @@ export class LintFile {
340
341
res . meta . bytesDelta = this . #data. length - this . #originalData. length ;
341
342
342
343
if ( this . #write ) {
343
- await fs . promises . writeFile ( this . path , this . #data ) ;
344
+ await fs . promises . writeFile ( this . # path, this . #data ) ;
344
345
}
345
346
}
346
347
else {
@@ -499,7 +500,7 @@ export class LintFile {
499
500
this . #cache. prettierConfigs ||= { } ;
500
501
501
502
if ( ! this . #cache. prettierConfigs [ configs . prettier ] ) {
502
- this . #cache. prettierConfigs [ configs . prettier ] = await prettier . resolveConfig ( this . path , {
503
+ this . #cache. prettierConfigs [ configs . prettier ] = await prettier . resolveConfig ( this . # path, {
503
504
"config" : configs . prettier ,
504
505
"editorconfig" : false ,
505
506
} ) ;
@@ -541,7 +542,7 @@ export class LintFile {
541
542
try {
542
543
543
544
// pre-parse package.json
544
- if ( path . basename ( this . path ) === "package.json" ) {
545
+ if ( path . basename ( this . # path ) === "package.json" ) {
545
546
const res = this . #runJson( "compress" ) ;
546
547
547
548
if ( ! res . ok ) return res ;
0 commit comments