0

I am having a strange issue with custom rules for PSScriptAnalyzer in VS Code. VS Code: 1.78.2 PSScriptAnalyzer: 1.21.0 My PSScriptAnalyzer settings are unchanged by when I add second Measure- function to the Custom rules .psm1 file all Problems stop being shown in VSCode.

It works fine with one rule. Also works fine when I Invoke-ScriptAnalyzer manually: Invoke-ScriptAnalyzer -Path .\Test-File.ps1 -Settings ..vscode\PSScriptAnalyzerSettings.psd1

The structure of my repo and files:

Test-file
.\.vscode\settings.json
.\.vscode\PSScriptAnalyzerSettings.psd1
.\.vscode\CustomPSScriptAnalyzerRules.psm1
.\.vscode\CustomPSScriptAnalyzerRules-OneRule.psm1

settings.json

{
"powershell.scriptAnalysis.settingsPath": "./.vscode/PSScriptAnalyzerSettings.psd1"
}

PSScriptAnalyzerSettings.psd1

@{
    CustomRulePath = '.\.vscode\CustomPSScriptAnalyzerRules.psm1'           #this one would not work
    #CustomRulePath = '.\.vscode\CustomPSScriptAnalyzerRules-OneRule.psm1'  #this one would work
    IncludeDefaultRules = $true
    Rules = @{
        PSAvoidLongLines  = @{
            Enable     = $true
            MaximumLineLength = 115
        }
        PSAvoidSemicolonsAsLineTerminators  = @{
            Enable     = $true
        }
        PSPlaceCloseBrace = @{
            Enable = $true
            NoEmptyLineBefore = $false
            IgnoreOneLineBlock = $true
            NewLineAfter = $true
        }
        PSPlaceOpenBrace = @{
            Enable = $true
            OnSameLine = $true
            NewLineAfter = $true
            IgnoreOneLineBlock = $true
        }
        PSUseConsistentWhitespace  = @{
            Enable                          = $true
            CheckInnerBrace                 = $true
            CheckOpenBrace                  = $true
            CheckOpenParen                  = $true
            CheckOperator                   = $true
            CheckPipe                       = $true
            CheckPipeForRedundantWhitespace = $false
            CheckSeparator                  = $true
            CheckParameter                  = $false
            IgnoreAssignmentOperatorInsideHashTable = $false
        }
        PSUseConsistentIndentation = @{
            Enable = $true
            IndentationSize = 4
            PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
            Kind = 'space'
        }
    }
    ExcludeRules = @(
    )
}

Tried running Invoke-PSScriptAnalyzer with my settings manually - it works. Tried custom rules with with one function and with two functions - only the one with one function works

0 Answers0