File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -280,8 +280,12 @@ protected override void BeginProcessing()
280
280
281
281
// For includeDefaultRules and RecurseCustomRulePath we override the value in the settings file by
282
282
// command line argument.
283
- combRecurseCustomRulePath = combRecurseCustomRulePath || settingsObj . RecurseCustomRulePath ;
284
- combIncludeDefaultRules = combIncludeDefaultRules || settingsObj . IncludeDefaultRules ;
283
+ combRecurseCustomRulePath = OverrideSwitchParam (
284
+ settingsObj . RecurseCustomRulePath ,
285
+ "RecurseCustomRulePath" ) ;
286
+ combIncludeDefaultRules = OverrideSwitchParam (
287
+ settingsObj . IncludeDefaultRules ,
288
+ "IncludeDefaultRules" ) ;
285
289
}
286
290
287
291
// Ideally we should not allow the parameter to be set from settings and command line
@@ -410,6 +414,13 @@ private bool IsFileParameterSet()
410
414
return String . Equals ( this . ParameterSetName , "File" , StringComparison . OrdinalIgnoreCase ) ;
411
415
}
412
416
417
+ private bool OverrideSwitchParam ( bool paramValue , string paramName )
418
+ {
419
+ return MyInvocation . BoundParameters . ContainsKey ( paramName )
420
+ ? ( ( SwitchParameter ) MyInvocation . BoundParameters [ paramName ] ) . ToBool ( )
421
+ : paramValue ;
422
+ }
423
+
413
424
#endregion // Private Methods
414
425
}
415
426
}
Original file line number Diff line number Diff line change @@ -418,6 +418,35 @@ Describe "Test CustomizedRulePath" {
418
418
$v.Count | Should Be 3
419
419
}
420
420
}
421
+
422
+ Context " When used from settings file and command line simulataneusly" {
423
+ BeforeAll {
424
+ $settings = @ {
425
+ CustomRulePath = " $directory \samplerule"
426
+ IncludeDefaultRules = $false
427
+ RecurseCustomRulePath = $false
428
+ }
429
+ $isaParams = @ {
430
+ Path = " $directory \TestScript.ps1"
431
+ Settings = $settings
432
+ }
433
+ }
434
+
435
+ It " Should combine CustomRulePaths" {
436
+ $v = Invoke-ScriptAnalyzer @isaParams - CustomRulePath " $directory \CommunityAnalyzerRules"
437
+ $v.Count | Should Be 2
438
+ }
439
+
440
+ It " Should override the settings IncludeDefaultRules parameter" {
441
+ $v = Invoke-ScriptAnalyzer @isaParams - IncludeDefaultRules
442
+ $v.Count | Should Be 2
443
+ }
444
+
445
+ It " Should override the settings RecurseCustomRulePath parameter" {
446
+ $v = Invoke-ScriptAnalyzer @isaParams - RecurseCustomRulePath
447
+ $v.Count | Should Be 3
448
+ }
449
+ }
421
450
}
422
451
423
452
Context " When used incorrectly" {
You can’t perform that action at this time.
0 commit comments