@@ -358,9 +358,9 @@ protected override void StopProcessing()
358358 base . StopProcessing ( ) ;
359359 }
360360
361- #endregion
361+ #endregion
362362
363- #region Private Methods
363+ #region Private Methods
364364
365365 private static bool IsBuiltinSettingPreset ( object settingPreset )
366366 {
@@ -416,6 +416,65 @@ private bool IsFileParameterSet()
416416 {
417417 return String . Equals ( this . ParameterSetName , "File" , StringComparison . OrdinalIgnoreCase ) ;
418418 }
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
420479 }
421- }
480+ }
0 commit comments