Skip to content
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

PSScriptAnalyser misreporting #1432

Closed
ghost opened this issue Jul 12, 2018 · 3 comments
Closed

PSScriptAnalyser misreporting #1432

ghost opened this issue Jul 12, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 12, 2018

Issue Type: Bug

If statements comparing with $null aren't evaluated properly

if($Credential.UserName -ne $null) labelled as null on wrong side of operator

Several instances of "trailing whitespace' yet none exists

Extension version: 1.8.1
VS Code version: Code 1.25.0 (0f080e5267e829de46638128001aeb7ca2d6d50e, 2018-07-05T13:11:11.248Z)
OS version: Windows_NT ia32 10.0.14393

System Info
Item Value
CPUs Intel(R) Xeon(R) CPU E5-2643 0 @ 3.30GHz (2 x 3292)
GPU Status 2d_canvas: unavailable_software
flash_3d: unavailable_software
flash_stage3d: unavailable_software
flash_stage3d_baseline: unavailable_software
gpu_compositing: unavailable_software
multiple_raster_threads: disabled_off
native_gpu_memory_buffers: disabled_software
rasterization: unavailable_software
video_decode: unavailable_software
video_encode: unavailable_software
vpx_decode: unavailable_software
webgl: unavailable_off
webgl2: unavailable_off
Memory (System) 4.00GB (1.23GB free)
Process Argv C:\Program Files (x86)\Microsoft VS Code\Code.exe D:\github\At-A-Glance
Screen Reader no
VM 0%
@rkeithhill
Copy link
Contributor

rkeithhill commented Jul 12, 2018

I believe the "trailing whitespace" issue is a problem PSSA needs to fix. The $null warnings are probably correct - see https://github.com/PowerShell/PSScriptAnalyzer/blob/development/RuleDocumentation/PossibleIncorrectComparisonWithNull.md

However, you can exclude both of these rules by adding a PSScriptAnalyzerSettings.psd1 file to your workspace. Then add a workspace settings file to ${workspaceRoot}/.vscode/workspace.json with this file content (setting):

{
    // Use a custom PowerShell Script Analyzer settings file for this workspace.
    // Relative paths for this setting are always relative to the workspace root dir.
    "powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1"
}

Then in the PSScriptAnalyzerSettings.psd1 file, add this content:

# Use the PowerShell extension setting `powershell.scriptAnalysis.settingsPath` to get the current workspace
# to use this PSScriptAnalyzerSettings.psd1 file to configure code analysis in Visual Studio Code.
# This setting is configured in the workspace's `.vscode\settings.json`.
#
# For more information on PSScriptAnalyzer settings see:
# https://github.com/PowerShell/PSScriptAnalyzer/blob/master/README.md#settings-support-in-scriptanalyzer
#
# You can see the predefined PSScriptAnalyzer settings here:
# https://github.com/PowerShell/PSScriptAnalyzer/tree/master/Engine/Settings
@{
    # Only diagnostic records of the specified severity will be generated.
    # Uncomment the following line if you only want Errors and Warnings but
    # not Information diagnostic records.
    #Severity = @('Error','Warning')

    # Analyze **only** the following rules. Use IncludeRules when you want
    # to invoke only a small subset of the default rules.
    #IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
    #                 'PSMisleadingBacktick',
    #                 'PSMissingModuleManifestField',
    #                 'PSReservedCmdletChar',
    #                 'PSReservedParams',
    #                 'PSShouldProcess',
    #                 'PSUseApprovedVerbs',
    #                 'PSAvoidUsingCmdletAliases',
    #                 'PSUseDeclaredVarsMoreThanAssignments')

    # Do not analyze the following rules. Use ExcludeRules when you have
    # commented out the IncludeRules settings above and want to include all
    # the default rules except for those you exclude below.
    # Note: if a rule is in both IncludeRules and ExcludeRules, the rule
    # will be excluded.
    ExcludeRules = @('PSAvoidTrailingWhitespace', 'PSPossibleIncorrectComparisonWithNull', )

    # You can use rule configuration to configure rules that support it:
    #Rules = @{
    #    PSAvoidUsingCmdletAliases = @{
    #        Whitelist = @("cd")
    #    }
    #}
}

In general, PSSA the default rules are going to rub some set of folks the wrong way. That's why I recommend folks use this settings file to configure PSSA with the rules they find valuable.

@rjmholt
Copy link
Contributor

rjmholt commented Jul 12, 2018

For any issues with PSScriptAnalyzer, you should report them here

@rjmholt
Copy link
Contributor

rjmholt commented Jul 12, 2018

Going to close this issue in favour of #1429.

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

No branches or pull requests

2 participants