-
Notifications
You must be signed in to change notification settings - Fork 394
Warn when 'Get-' prefix was omitted. #927
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
Changes from 5 commits
26003b3
dd87390
9b1da90
db0c195
59fae3b
6e79eec
0dea943
31055fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,11 @@ Describe "AvoidUsingAlias" { | |
Test-CorrectionExtent $violationFilepath $violations[1] 1 'cls' 'Clear-Host' | ||
$violations[1].SuggestedCorrections[0].Description | Should -Be 'Replace cls with Clear-Host' | ||
} | ||
|
||
It "warns when 'Get-' prefix was omitted" { | ||
$violations = Invoke-ScriptAnalyzer -ScriptDefinition 'verb' | Where-Object { $_.RuleName -eq $violationName } | ||
$violations.Count | Should -Be 1 | ||
} | ||
} | ||
|
||
Context "Violation Extent" { | ||
|
@@ -95,5 +100,10 @@ Configuration MyDscConfiguration { | |
$violations = Invoke-ScriptAnalyzer -ScriptDefinition "CD" -Settings $settings -IncludeRule $violationName | ||
$violations.Count | Should -Be 0 | ||
} | ||
|
||
It "do not warn when about Get-* completed cmdlets when the command exists natively on Unix platforms" -skip:(!$IsLinux -and !$IsmacOS) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a bit confusing - is this better? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me both versions are of similar complexity, therefore I don't have a strong opinion on what it should be. I will change it to your version then. |
||
$violations = Invoke-ScriptAnalyzer -ScriptDefinition 'date' | Where-Object { $_.RuleName -eq $violationName } | ||
$violations.Count | Should -Be 0 | ||
} | ||
} | ||
} |
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 isn't necessarily a native command, but it's anything that will be returned by
Get-Command
. I was thinking that this was a bit open and wanted to be more specific about native apps, and there is an overload for GetCommandInfo which takes a CommandType, which would be perfect, because we could do this:var isNativeCommand = Helper.Instance.GetCommandInfo(commandName, (CommandTypes.Application|CommandTypes.ExternalScript))
unfortunately, the internal method doesn't actually use this parameter if it's passed in which is a bug - grrrr
The reason I'm worried is that we may be still casting too broad a net here, and we'll get more false positives as the call as written will find everything named 'date' including scripts/functions/etc.
The long and short of it is there's no way to return just the native apps with the bug in the engine, so this may generate false positives. So the name of the variable is not what it purports to be (a native command)
Uh oh!
There was an error while loading. Please reload this page.
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.
Unfortunately, it turns out that lots of other code seems to be indirectly relying on this bug and other things start to break if I were to fix it. I fixed therefore only the
GetCommandInfoInternal
method to actually use theCommandTypes
argument and declared the oldGetCommandInfo
method as legacy to not break existing behaviour. I think this bad behaviour is mainly due to the commandInfo cache, which is one of too many shared static members that are indirectly being modified. I re-ran the tests locally on an Ubuntu 16 VM.