winget-pkgs icon indicating copy to clipboard operation
winget-pkgs copied to clipboard

PR Watcher and Manual Validation update.

Open stephengillie opened this issue 2 years ago • 12 comments

  • [ ] Have you signed the Contributor License Agreement?
  • [ ] Have you checked that there aren't other open pull requests for the same manifest update/change?
  • [ ] This PR only modifies one (1) manifest
  • [ ] Have you validated your manifest locally with winget validate --manifest <path>?
  • [ ] Have you tested your manifest locally with winget install --manifest <path>?
  • [ ] Does your manifest conform to the 1.5 schema?

Note: <path> is the name of the directory containing the manifest you're submitting.


Microsoft Reviewers: Open in CodeFlow

stephengillie avatar Dec 21 '23 18:12 stephengillie

Service Badge  Service Badge  

wingetbot avatar Dec 21 '23 18:12 wingetbot

Also some analyzer warnings in your other scripts -

Mostly around -

  • Write-Host
    • These can probably be suprressed with [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'This script is not intended to have any outputs piped')]
  • Variables defined but never used
  • Functions which modify state not supporting ShouldProcess
  • Approved Verbs
    • These can probably be suppressed, but may want to check them anyways
  • Use Singular nouns
    • These can probably be suppressed, but may want to check them anyways
  • Empty catch blocks
  • Whitespace at end of line
  • Incorrect null comparison ($null should always be on the left side of equality comparisons)
  • Cmdlet aliases
PS D:\Git\winget-pkgs> Invoke-ScriptAnalyzer D:\Git\winget-pkgs\Tools\ManualValidationProfile.ps1

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseDeclaredVarsMoreThanAssignment Warning      ManualVali 15    The variable 'SharedFolder' is assigned but never used.
s                                                dationProf
                                                 ile.ps1
PSUseShouldProcessForStateChangingF Warning      ManualVali 31    Function 'Set-Status' has verb that could change system     
unctions                                         dationProf       state. Therefore, the function has to support
                                                 ile.ps1          'ShouldProcess'.
PSUseShouldProcessForStateChangingF Warning      ManualVali 65    Function 'Update-Stuff' has verb that could change system
unctions                                         dationProf       state. Therefore, the function has to support
                                                 ile.ps1          'ShouldProcess'.
PSUseApprovedVerbs                  Warning      ManualVali 41    The cmdlet 'Run-Validation' uses an unapproved verb.
                                                 dationProf
                                                 ile.ps1
PSAvoidUsingWriteHost               Warning      ManualVali 6     File 'ManualValidationProfile.ps1' uses Write-Host. Avoid   
                                                 dationProf       using Write-Host because it might not work in all hosts,
                                                 ile.ps1          does not work when there is no host, and (prior to PS 5.0)
                                                                  cannot be suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      ManualVali 27    File 'ManualValidationProfile.ps1' uses Write-Host. Avoid
                                                 dationProf       using Write-Host because it might not work in all hosts,
                                                 ile.ps1          does not work when there is no host, and (prior to PS 5.0)
                                                                  cannot be suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      ManualVali 36    File 'ManualValidationProfile.ps1' uses Write-Host. Avoid
                                                 dationProf       using Write-Host because it might not work in all hosts,
                                                 ile.ps1          does not work when there is no host, and (prior to PS 5.0)
                                                                  cannot be suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PS D:\Git\winget-pkgs> Invoke-ScriptAnalyzer D:\Git\winget-pkgs\Tools\PRWatcher.ps1

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      PRWatcher. 58    'where' is an alias of 'Where-Object'. Alias can introduce
                                                 ps1              possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.
PSAvoidUsingCmdletAliases           Warning      PRWatcher. 1225  'where' is an alias of 'Where-Object'. Alias can introduce
                                                 ps1              possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.
PSAvoidUsingCmdletAliases           Warning      PRWatcher. 1279  'where' is an alias of 'Where-Object'. Alias can introduce
                                                 ps1              possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.
PSAvoidUsingCmdletAliases           Warning      PRWatcher. 1312  'where' is an alias of 'Where-Object'. Alias can introduce
                                                 ps1              possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.
PSAvoidUsingCmdletAliases           Warning      PRWatcher. 1492  '%' is an alias of 'ForEach-Object'. Alias can introduce    
                                                 ps1              possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.
PSAvoidUsingCmdletAliases           Warning      PRWatcher. 1493  '%' is an alias of 'ForEach-Object'. Alias can introduce
                                                 ps1              possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.
PSAvoidUsingCmdletAliases           Warning      PRWatcher. 1507  'iwr' is an alias of 'Invoke-WebRequest'. Alias can
                                                 ps1              introduce possible problems and make scripts hard to
                                                                  maintain. Please consider changing alias to its full
                                                                  content.
PSUseDeclaredVarsMoreThanAssignment Warning      PRWatcher. 14    The variable 'appName' is assigned but never used.
s                                                ps1
PSUseDeclaredVarsMoreThanAssignment Warning      PRWatcher. 289   The variable 'nvalidColor' is assigned but never used.
s                                                ps1
PSUseDeclaredVarsMoreThanAssignment Warning      PRWatcher. 1285  The variable 'matchVar' is assigned but never used.
s                                                ps1
PSUseDeclaredVarsMoreThanAssignment Warning      PRWatcher. 1465  The variable 'i' is assigned but never used.
s                                                ps1
PSPossibleIncorrectComparisonWithNu Warning      PRWatcher. 1233  $null should be on the left side of equality comparisons.
ll                                               ps1
PSPossibleIncorrectComparisonWithNu Warning      PRWatcher. 1248  $null should be on the left side of equality comparisons.
ll                                               ps1
PSUseBOMForUnicodeEncodedFile       Warning      PRWatcher.       Missing BOM encoding for non-ASCII encoded file
                                                 ps1              'PRWatcher.ps1'
PSUseShouldProcessForStateChangingF Warning      PRWatcher. 1513  Function 'Set-PadRight' has verb that could change system
unctions                                         ps1              state. Therefore, the function has to support
                                                                  'ShouldProcess'.
PSUseApprovedVerbs                  Warning      PRWatcher. 1484  The cmdlet 'Create-Sandbox' uses an unapproved verb.
                                                 ps1
PSUseApprovedVerbs                  Warning      PRWatcher. 1499  The cmdlet 'Check-ForManifestEntries' uses an unapproved
                                                 ps1              verb.
PSUseSingularNouns                  Warning      PRWatcher. 16    The cmdlet 'Watch-PRTitles' uses a plural noun. A singular
                                                 ps1              noun should be used instead.
PSUseSingularNouns                  Warning      PRWatcher. 1499  The cmdlet 'Check-ForManifestEntries' uses a plural noun. A
                                                 ps1              singular noun should be used instead.
PSAvoidUsingWriteHost               Warning      PRWatcher. 33    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 35    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 37    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 41    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 43    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 45    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 46    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 47    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 83    File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1212  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1276  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1307  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1318  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1331  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1355  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1387  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1429  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1436  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1437  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingWriteHost               Warning      PRWatcher. 1446  File 'PRWatcher.ps1' uses Write-Host. Avoid using
                                                 ps1              Write-Host because it might not work in all hosts, does not
                                                                  work when there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.
PSAvoidUsingEmptyCatchBlock         Warning      PRWatcher. 1385  Empty catch block is used. Please use Write-Error or throw
                                                 ps1              statements in catch blocks.
PSAvoidUsingEmptyCatchBlock         Warning      PRWatcher. 1509  Empty catch block is used. Please use Write-Error or throw
                                                 ps1              statements in catch blocks.

Trenly avatar Jan 02 '24 15:01 Trenly

Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.

The problem with this error is that the alternatives are not equivalent. Write-Output has no option similar to Write-Host's -nonewline to suppress adding a newline at the end of output. This suggests that PowerShell shouldn't be used to write console applications such as these.

stephengillie avatar Jan 02 '24 20:01 stephengillie

Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.

The problem with this error is that the alternatives are not equivalent. Write-Output has no option similar to Write-Host's -nonewline to suppress adding a newline at the end of output. This suggests that PowerShell shouldn't be used to write console applications such as these.

Precisely why I provided the snippet for suppressing the Write-Output item

Trenly avatar Jan 02 '24 20:01 Trenly

For these,

Functions which modify state not supporting ShouldProcess Approved Verbs

To suppress the error I'm using the "antipattern of make everything start with Get-".

This one doesn't make sense to me - isn't null additive and commutative?

Incorrect null comparison ($null should always be on the left side of equality comparisons)

stephengillie avatar Jan 02 '24 20:01 stephengillie

This one doesn't make sense to me - isn't null additive and commutative?

Incorrect null comparison ($null should always be on the left side of equality comparisons)

https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/possibleincorrectcomparisonwithnull?view=ps-modules

Trenly avatar Jan 02 '24 20:01 Trenly

Precisely why I provided the snippet for suppressing the Write-Output item

My local client doesn't enjoy the snippet:

PowerShell 7.4.0
Manual Validation build: 510
ParserError: C:\repos\winget-pkgs\Tools\PRWatcher.ps1:46
Line |
  46 |  [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWrite …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unexpected attribute 'Diagnostics.CodeAnalysis.SuppressMessageAttribute'.
PS C:\ManVal>

Edit: it only errors if present in both files. Will validation need it in both, or will one be sufficient?

stephengillie avatar Jan 02 '24 21:01 stephengillie

Precisely why I provided the snippet for suppressing the Write-Output item

My local client doesn't enjoy the snippet:

PowerShell 7.4.0
Manual Validation build: 510
ParserError: C:\repos\winget-pkgs\Tools\PRWatcher.ps1:46
Line |
  46 |  [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWrite …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unexpected attribute 'Diagnostics.CodeAnalysis.SuppressMessageAttribute'.
PS C:\ManVal>

Edit: it only errors if present in both files. Will validation need it in both, or will one be sufficient?

@stephengillie - Can you try the PR that I raised into your fork?

Trenly avatar Jan 02 '24 22:01 Trenly

@ stephengillie - Can you try the PR that I raised into your fork?

I'm not sure how to do this. I don't see a PR in my tree. Am I looking in the wrong place?

stephengillie avatar Jan 03 '24 00:01 stephengillie

@ stephengillie - Can you try the PR that I raised into your fork?

I'm not sure how to do this. I don't see a PR in my tree. Am I looking in the wrong place?

https://github.com/stephengillie/winget-pkgs/pulls

Looks like I have some merge conflicts now that I'll need to resolve

Trenly avatar Jan 03 '24 00:01 Trenly

I updated these earlier today, but wanted to have a full round of validations and approvals to catch most of the errors.

stephengillie avatar Jan 03 '24 00:01 stephengillie

@microsoft-github-policy-service agree company="Microsoft"

stephengillie avatar Apr 03 '24 18:04 stephengillie