Skip to content

Error when using Settings have ExcludeRules = @() #1063

Closed
@felixfbecker

Description

@felixfbecker

If I pass it a string path to a PSScriptAnalyzerSettings.psd1 file, I get

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings.GetHashtableFromHashTableAst(HashtableAst hashTableAst)
   at Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings.parseSettingsFile(String settingsFilePath)
   at Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings.Create(Object settingsObj, String cwd, IOutputWriter outputWriter, GetResolvedProviderPathFromPSPath`3 getResolvedProviderPathFromPSPathDelegate)
   at Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand.BeginProcessing()

If I pass it the parsed settings file with Import-PowerShellDataFile, I get

Invoke-Formatter : Cannot parse settings. Will abort the invocation.

Here's my settings file:

@{
    ExcludeRules = @()
    Rules = @{
        PSPlaceOpenBrace = @{
            Enable = $true
            OnSameLine = $true
            NewLineAfter = $true
            IgnoreOneLineBlock = $true
        }

        PSPlaceCloseBrace = @{
            Enable = $true
            NewLineAfter = $false
            IgnoreOneLineBlock = $true
            NoEmptyLineBefore = $true
        }

        PSUseConsistentIndentation = @{
            Enable = $true
            Kind = 'space'
            IndentationSize = 4
        }

        PSUseConsistentWhitespace = @{
            Enable = $true
            CheckOpenBrace = $true
            CheckOpenParen = $true
            CheckOperator = $true
            CheckSeparator = $true
        }

        PSAlignAssignmentStatement = @{
            Enable = $false
        }

        PSUseShouldProcessForStateChangingFunctions = @{
            Enable = $true
        }
    }
}

The same happens with Invoke-ScriptAnalyzer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions