Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow -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 { | |||
This comment has been minimized.
This comment has been minimized.
JamesWTruher
Mar 21, 2018
Member
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
This comment has been minimized.
This comment has been minimized.
bergmeister
Mar 23, 2018
Author
Collaborator
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); |
This comment has been minimized.
This comment has been minimized.
JamesWTruher
Mar 21, 2018
Member
there's no check of the return, does it not matter if we get to this point?
This comment has been minimized.
This comment has been minimized.
bergmeister
Mar 23, 2018
Author
Collaborator
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.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

bergmeister commentedMar 11, 2018
•
edited
PR Summary
Fixes issue #807
Similar to the recent improvement to allow parsing the
-Settingobject 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
xbetween 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