Skip to content

Conversation

@bergmeister
Copy link
Contributor

To help fixing #3791
Fixes a few hundred warnings of type PSPossibleIncorrectComparisonWithNull, PSAvoidUsingCmdletAliases (mostly for ForEach-Object, Where-Object, Select-Object) and some PSUseDeclaredVarsMoreThanAssignment warnings.
As part of this, it was also found that a test in ParameterBindingTests needed improvement because since the null comparison is now correct, the test failed initially.

… Where-Object (?), Select-Object and a few others.

Fixed some PSUseDeclaredVarsMoreThanAssignment warnings (one must be careful with them as some of those warnings are false positives)
…omparison is now correct and also removed unnecessary initialisation that was not needed for the test but made it difficult to know what was going. Enhanced the test.

Fixed one typo in Dynamicparameters.Tests.ps1 that got introduced during the last refactoring and made 2 tests fail.
@msftclas
Copy link

msftclas commented Jul 9, 2017

@bergmeister,
Thanks for having already signed the Contribution License Agreement. Your agreement has not been validated yet. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested in #3791 we should add meta test with scriptanalyzer.

$IsFedora = $LinuxInfo.ID -match 'fedora' -and $LinuxInfo.VERSION_ID -ge 24
$IsOpenSUSE = $LinuxInfo.ID -match 'opensuse'
$IsOpenSUSE13 = $IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '13'
${IsOpenSUSE42.1} = $IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '42.1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables is unused - so Ok to remove.

build.psm1 Outdated
if ($count -eq 0)
{
sleep 1
Start-Sleep 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a parameter name.

### Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination <Folder you want this to be installed>
###
### Ensure $env:PSModulePath is updated with the location you used to install.
### Ensure $env:PSMODULEPATH is updated with the location you used to install.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use "PSModulePath" - see PowerShell-Committee conclusion #3227 (comment)

}}
if (-not $AsJob -and $job -ne $null)
if ($null -ne -not $AsJob -and $job)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrupted logic. Please see operator precedence

$xmlWriter = SaveCDXMLHeader $xmlWriter $Uri $singletonName $singletonName $CmdletAdapter

if ($associatedEntityType.BaseType -eq $null -and $associatedEntityType.BaseTypeStr -ne $null -and $associatedEntityType.BaseTypeStr -ne '')
if ($null -eq $associatedEntityType.BaseTyp -and $null -ne $associatedEntityType.BaseTypeStr -and $associatedEntityType.BaseTypeStr -ne '')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost char: $associatedEntityType.BaseTyp


It "Should be able to use the alias" {
{ $dirObject | select } | Should Not Throw
{ $dirObject | Select-Object} | Should Not Throw
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the change.

$gpp = Get-PackageProvider

$gpp | ?{ $_.name -eq "NuGet" } | should not BeNullOrEmpty
$gpp | Where-Object{ $_.name -eq "NuGet" } | should not BeNullOrEmpty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space after Where-Object.

$gpp | Where-Object{ $_.name -eq "NuGet" } | should not BeNullOrEmpty

$gpp | ?{ $_.name -eq "PowerShellGet" } | should not BeNullOrEmpty
$gpp | Where-Object{ $_.name -eq "PowerShellGet" } | should not BeNullOrEmpty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space after Where-Object.

$c1 = $r1.Assembly.ClassCoverage | ?{$_.ClassName -eq $Class }
$c2 = $r2.Assembly.ClassCoverage | ?{$_.ClassName -eq $Class }
$c1 = $r1.Assembly.ClassCoverage | Where-Object{$_.ClassName -eq $Class }
$c2 = $r2.Assembly.ClassCoverage | Where-Object{$_.ClassName -eq $Class }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space after Where-Object in both lines.

}
$CoverageData.PSTypeNames.Insert(0,"OpenCover.CoverageData")
Add-Member -InputObject $CoverageData -MemberType ScriptMethod -Name GetClassCoverage -Value { param ( $name ) $this.assembly.classcoverage | ?{$_.classname -match $name } }
Add-Member -InputObject $CoverageData -MemberType ScriptMethod -Name GetClassCoverage -Value { param ( $name ) $this.assembly.classcoverage | Where-Object{$_.classname -match $name } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space after Where-Object.

…ludes spaces after Where-Object/Select-Object, 4 lines being reverted due to accidental changes and minor test refactoring.

The test refactoring idea was basically to change '$null -eq $something | Should Be $true' to '$something | Should BeNullOrEmpty'
@bergmeister
Copy link
Contributor Author

Thanks @iSazonov for taking such a detailed look and spotting the accidental mistakes that I made when going through the hundreds of refactorings. I have followed all your suggestions and submitted the fix as you can see above. The total number of warnings seems to have gone down by about 350.

td24.Members.Add("IPV4Address",
new ScriptPropertyData(@"IPV4Address", GetScriptBlock(@"$iphost = [System.Net.Dns]::GetHostEntry($this.address)
$iphost.AddressList | Where-Object{ $_.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork } | Select-Object -first 1"), null));
$iphost.AddressList | Where-Object{ $_.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork } | Select-Object -first 1"), null));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extra space before $_ and add space after Where-Object and before {.

The same typo is below.


$newacl = get-acl $directory
$newrule = $newacl.Access | Where-Object{ $accessrule.FileSystemRights -eq $_.FileSystemRights -and $accessrule.AccessControlType -eq $_.AccessControlType -and $accessrule.IdentityReference -eq $_.IdentityReference }
$newrule = $newacl.Access | Where-Object{ $accessrule.FileSystemRights -eq $_.FileSystemRights -and $accessrule.AccessControlType -eq $_.AccessControlType -and $accessrule.IdentityReference -eq $_.IdentityReference }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space after Where-Object and remove extra space before $accessrule.


It "Temporary module should be automatically removed after runspace is closed" -Skip:$skipTest {
($null -eq (Get-Module | Where-Object { $_.Path -eq $module.Path })) | Should Be $true
(Get-Module | Where-Object { $_.Path -eq $module.Path }) | Should BeNullOrEmpty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

$gpp = Get-PackageProvider

$gpp | Where-Object{ $_.name -eq "NuGet" } | should not BeNullOrEmpty
$gpp | Where-Object{ $_.name -eq "NuGet" } | should not BeNullOrEmpty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extra space.

$gpp | Where-Object{ $_.name -eq "NuGet" } | should not BeNullOrEmpty

$gpp | Where-Object{ $_.name -eq "PowerShellGet" } | should not BeNullOrEmpty
$gpp | Where-Object{ $_.name -eq "PowerShellGet" } | should not BeNullOrEmpty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extra space.

}
$CoverageData.PSTypeNames.Insert(0,"OpenCover.CoverageData")
Add-Member -InputObject $CoverageData -MemberType ScriptMethod -Name GetClassCoverage -Value { param ( $name ) $this.assembly.classcoverage | Where-Object{$_.classname -match $name } }
Add-Member -InputObject $CoverageData -MemberType ScriptMethod -Name GetClassCoverage -Value { param ( $name ) $this.assembly.classcoverage | Where-Object{ $_.classname -match $name } }
Copy link
Collaborator

@iSazonov iSazonov Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space after Where-Object.

$xmlWriter = SaveCDXMLHeader $xmlWriter $Uri $singletonName $singletonName $CmdletAdapter

if ($null -eq $associatedEntityType.BaseTyp -and $null -ne $associatedEntityType.BaseTypeStr -and $associatedEntityType.BaseTypeStr -ne '')
if ($null -eq $associatedEntityType.BaseType -and $null -ne $associatedEntityType.BaseTypeStr -and $associatedEntityType.BaseTypeStr -ne '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anmenaga - this looks like a bug that should get fixed in Windows PowerShell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lzybkr : I'm not sure what you mean but the missing 'e' on 'BaseType' was an accidental deletion that happened in the first commit that I corrected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - this is a good example of why I'm not a fan of mixing minor changes in one big commit, because I do sometimes review commits by themselves instead of the full PR.

@lzybkr
Copy link
Contributor

lzybkr commented Jul 10, 2017

I'm seeing different sorts of changes in a single commit - and with this many changes, it would be easier to review and safer to keep each refactoring as a single commit.

@iSazonov
Copy link
Collaborator

+1 for multiple commits. Maybe:

  1. Build.psm1
  2. Rest tool scripts
  3. Test scripts
  4. Rest files.

@bergmeister
Copy link
Contributor Author

@iSazonov I have fixed your requested changes about the fine-tuning of the spacing. When I started out doing that, I initially wanted to fix only most PSPossibleIncorrectComparisonWithNull violations but then I came across lots of other things to be improved like e.g. the aliases. Because the contribution guide here recommended to have just one commit per change, I thought I'd try to put it all into one commit for the pull request. I am not sure how one would change the commit history now that the commits are already pushed to the remote. Sorry, maybe I should have rather checked with you before.

@iSazonov
Copy link
Collaborator

iSazonov commented Jul 10, 2017

You would rebase and split - see https://stackoverflow.com/questions/6217156/break-a-previous-commit-into-multiple-commits
You already fixed most typos so we can rebase to save maintainer's time.

@bergmeister
Copy link
Contributor Author

bergmeister commented Jul 10, 2017

@iSazonov OK, thanks. I did not feel confident/adventurous enough to rebase commits that are already pushed to the remote, so I have created a new branch, pulled in my commit changes and made then the 4 separate commits as requested by you. I have created the new PR #4213 for that, so feel free to close this one. Sorry, if this PR turned out to be messier than initially anticipated. I hope you are satisfied with this cleaner version now and I could try to help improve your codebase a bit.

@iSazonov iSazonov closed this Jul 11, 2017
bergmeister added a commit to bergmeister/PowerShell that referenced this pull request Jul 14, 2017
…thNull. Essentially, $null has to be on the left hand side when using it for comparison.

A Test in ParameterBinding.Tests.ps1 needed adapting as this test used to rely on the wrong null comparison
It was also suggested in the initial PR PowerShell#4205 to replace a subset of tests of kind '($object -eq $null) | Should Be $true' with '($null -eq $object) | Should BeNullOrEmpty'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants