File tree Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -278,6 +278,13 @@ protected override void BeginProcessing()
278
278
path ) ) ;
279
279
}
280
280
}
281
+ else if ( IsBuiltinSettingPreset ( settings ) )
282
+ {
283
+ settingFileHasErrors = ! ScriptAnalyzer . Instance . ParseProfile (
284
+ Helper . GetSettingPresetFilePath ( settings as string ) ,
285
+ this . SessionState . Path ,
286
+ this ) ;
287
+ }
281
288
else
282
289
{
283
290
settingFileHasErrors = ! ScriptAnalyzer . Instance . ParseProfile ( this . settings , this . SessionState . Path , this ) ;
@@ -348,7 +355,19 @@ protected override void StopProcessing()
348
355
349
356
#endregion
350
357
351
- #region Methods
358
+ #region Private Methods
359
+
360
+ private static bool IsBuiltinSettingPreset ( object settingPreset )
361
+ {
362
+ var preset = settingPreset as string ;
363
+ if ( preset != null )
364
+ {
365
+ return Helper . GetBuiltinSettingPresets ( ) . Contains ( preset , StringComparer . OrdinalIgnoreCase ) ;
366
+ }
367
+
368
+ return false ;
369
+ }
370
+
352
371
private void ProcessInput ( )
353
372
{
354
373
IEnumerable < DiagnosticRecord > diagnosticsList = Enumerable . Empty < DiagnosticRecord > ( ) ;
@@ -392,6 +411,6 @@ private bool IsFileParameterSet()
392
411
{
393
412
return String . Equals ( this . ParameterSetName , "File" , StringComparison . OrdinalIgnoreCase ) ;
394
413
}
395
- #endregion
414
+ #endregion // Private Methods
396
415
}
397
416
}
Original file line number Diff line number Diff line change @@ -201,6 +201,42 @@ public static string GetShippedSettingsDirectory()
201
201
return settingsPath ;
202
202
}
203
203
204
+ /// <summary>
205
+ /// Returns the builtin setting presets
206
+ ///
207
+ /// Looks for powershell data files (*.psd1) in the PSScriptAnalyzer module settings directory
208
+ /// and returns the names of the files without extension
209
+ /// </summary>
210
+ internal static IEnumerable < string > GetBuiltinSettingPresets ( )
211
+ {
212
+ var settingsPath = GetShippedSettingsDirectory ( ) ;
213
+ if ( settingsPath != null )
214
+ {
215
+ foreach ( var filepath in System . IO . Directory . EnumerateFiles ( settingsPath , "*.psd1" ) )
216
+ {
217
+ yield return System . IO . Path . GetFileNameWithoutExtension ( filepath ) ;
218
+ }
219
+ }
220
+ }
221
+
222
+ /// <summary>
223
+ /// Gets the path to the settings file corresponding to the given preset.
224
+ ///
225
+ /// If the corresponding preset file is not found, the method returns null.
226
+ /// </summary>
227
+ internal static string GetSettingPresetFilePath ( string settingPreset )
228
+ {
229
+ var settingsPath = GetShippedSettingsDirectory ( ) ;
230
+ if ( settingsPath != null )
231
+ {
232
+ if ( GetBuiltinSettingPresets ( ) . Contains ( settingPreset , StringComparer . OrdinalIgnoreCase ) )
233
+ {
234
+ return System . IO . Path . Combine ( settingsPath , settingPreset + ".psd1" ) ;
235
+ }
236
+ }
237
+
238
+ return null ;
239
+ }
204
240
205
241
/// <summary>
206
242
/// Returns all the rule arguments
You can’t perform that action at this time.
0 commit comments