@@ -358,9 +358,9 @@ protected override void StopProcessing()
358
358
base . StopProcessing ( ) ;
359
359
}
360
360
361
- #endregion
361
+ #endregion
362
362
363
- #region Private Methods
363
+ #region Private Methods
364
364
365
365
private static bool IsBuiltinSettingPreset ( object settingPreset )
366
366
{
@@ -416,6 +416,65 @@ private bool IsFileParameterSet()
416
416
{
417
417
return String . Equals ( this . ParameterSetName , "File" , StringComparison . OrdinalIgnoreCase ) ;
418
418
}
419
- #endregion // Private Methods
419
+
420
+ private SettingsMode FindSettingsMode ( out object settingsFound )
421
+ {
422
+ var settingsMode = SettingsMode . None ;
423
+ settingsFound = this . settings ;
424
+ if ( settingsFound == null )
425
+ {
426
+ if ( processedPaths != null && processedPaths . Count == 1 )
427
+ {
428
+ // add a directory separator character because if there is no trailing separator character, it will return the parent
429
+ var directory = processedPaths [ 0 ] . TrimEnd ( System . IO . Path . DirectorySeparatorChar ) ;
430
+ if ( File . Exists ( directory ) )
431
+ {
432
+ // if given path is a file, get its directory
433
+ directory = System . IO . Path . GetDirectoryName ( directory ) ;
434
+ }
435
+
436
+ if ( Directory . Exists ( directory ) )
437
+ {
438
+ // if settings are not provided explicitly, look for it in the given path
439
+ // check if pssasettings.psd1 exists
440
+ var settingsFilename = "PSScriptAnalyzerSettings.psd1" ;
441
+ var settingsFilePath = System . IO . Path . Combine ( directory , settingsFilename ) ;
442
+ settingsFound = settingsFilePath ;
443
+ if ( File . Exists ( settingsFilePath ) )
444
+ {
445
+ settingsMode = SettingsMode . Auto ;
446
+ }
447
+ }
448
+ }
449
+ }
450
+ else
451
+ {
452
+ var settingsFilePath = settingsFound as String ;
453
+ if ( settingsFilePath != null )
454
+ {
455
+ if ( IsBuiltinSettingPreset ( settingsFilePath ) )
456
+ {
457
+ settingsMode = SettingsMode . Preset ;
458
+ settingsFound = Helper . GetSettingPresetFilePath ( settingsFilePath ) ;
459
+ }
460
+ else
461
+ {
462
+ settingsMode = SettingsMode . File ;
463
+ settingsFound = settingsFilePath ;
464
+ }
465
+ }
466
+ else
467
+ {
468
+ if ( settingsFound is Hashtable )
469
+ {
470
+ settingsMode = SettingsMode . Hashtable ;
471
+ }
472
+ }
473
+ }
474
+
475
+ return settingsMode ;
476
+ }
477
+
478
+ #endregion // Private Methods
420
479
}
421
- }
480
+ }
0 commit comments