-
Notifications
You must be signed in to change notification settings - Fork 394
Allow -Setting parameter to resolve setting presets as well when object is still a PSObject in BeginProcessing #928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow -Setting parameter to resolve setting presets as well when object is still a PSObject in BeginProcessing #928
Conversation
…ject is not resolved to a string yet. Tidy up existing logic. TODO: add test (we do not have test coverage for setting presets)
@@ -406,6 +406,13 @@ Describe "Test CustomizedRulePath" { | |||
Pop-Location | |||
} | |||
} | |||
|
|||
It "resolves rule preset when passed in via pipeline" { | |||
$warnings = 'CodeFormattingStroustrup' | ForEach-Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems overly complicated, isn't this just:
$warnings = Invoke-ScriptAnalyzer -ScriptDefinition 'if ($true){}' -Settings CodeFormattingStroustrup
$warnings.Count | Should -Be 1
$warnings.RuleName | Should -Be 'PSUseConsistentWhitespace'
all the pipes and where's aren't needed and only add complexity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pipes are needed to reproduce the actual bug because otherwise the settings object is already resolved to a string in your case but I will get rid of the where clause and add the additional assertion as you suggested.
settingsMode = SettingsMode.File; | ||
} | ||
} | ||
TryResolveSettingForStringType(settingsFoundPSObject.BaseObject, ref settingsMode, ref settingsFound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no check of the return, does it not matter if we get to this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for the return value is only needed for the first method call. If we still cannot resolve the settings type at this point, then the mode will be SettingsMode.None
(this is the initial default) and that gets handled later on.
…nalyzer into FixSettingsParsingAsPreset
PR Summary
Fixes issue #807
Similar to the recent improvement to allow parsing the
-Setting
object as string when the object is still a PSObject also take into account setting presets like e.g. 'CodeFormattingStroustrup'.Existing code was cleaned up to reduce duplication.
PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
x
between the square brackets. Please mark anything not applicable to this PRNA
.WIP:
to the beginning of the title and remove the prefix when the PR is ready