-
Notifications
You must be signed in to change notification settings - Fork 394
formatting partial / dot sourced ps1 dsc scripts #1081
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
Comments
@chrisshearing The behaviour that you describe is because the default of the VS Code setting |
Hi @bergmeister , I was just wondering how you came to that conclusion, when I realised that when transferring the bug report from vscode-powershell, I managed to reverse the expected and actual behaviour code snippets! (I've corrected them in the original post now) Sorry about that, powershell.codeFormatting.alignPropertyValuePairs is set to true, but it is failing to align the key / value pairs when the dsc resource is alone in an included powershell file, which is what I would have expected to happen |
@chrisshearing The |
@bergmeister I have not changed the setting from the default true ever - it works correctly in all other circumstances I'm using it in, except this one, I've just downloaded the latest release of psscriptanalyzer and verified it's still an issue on the command line I am not using any settings that override the settings are you using exactly this code and nothing else in the .ps1 file or directly using the invoke-formatter command to test? Registry DisableLocalMachineRunOnce {
Ensure = "Present"
Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
Force = $true
ValueName = "DisableLocalMachineRunOnce"
ValueType = "DWord"
ValueData = "1"
} I do not have access to my work environment on a saturday night - but as I mentioned the behaviour is exactly the same with the command line usage of invoke-formatter, Here is a reproduction of the issue, you can see with the configuration statement the formatter works, without it, it doesn't and below is the output of the commands you requested. PS D:\test> Invoke-Formatter {configuration test {
>> Registry DisableLocalMachineRunOnce {
>> Ensure = "Present"
>> Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
>> Force = $true
>> ValueName = "DisableLocalMachineRunOnce"
>> ValueType = "DWord"
>> ValueData = "1"
>> }
>> }}
configuration test {
Registry DisableLocalMachineRunOnce {
Ensure = "Present"
Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
Force = $true
ValueName = "DisableLocalMachineRunOnce"
ValueType = "DWord"
ValueData = "1"
}
}
PS D:\test>
PS D:\test> Invoke-Formatter { Registry DisableLocalMachineRunOnce {
>> Ensure = "Present"
>> Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
>> Force = $true
>> ValueName = "DisableLocalMachineRunOnce"
>> ValueType = "DWord"
>> ValueData = "1"
>> }}
Registry DisableLocalMachineRunOnce {
Ensure = "Present"
Key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
Force = $true
ValueName = "DisableLocalMachineRunOnce"
ValueType = "DWord"
ValueData = "1"
}
PS D:\test>
PS D:\test> Invoke-ScriptAnalyzer -scriptdefinition foo -Verbose
VERBOSE: Settings object could not be resolved.
VERBOSE: Analyzing Script Definition.
PS D:\test> Invoke-Formatter -ScriptDefinition foo -Verbose
VERBOSE: Using settings file at C:\Program
Files\WindowsPowerShell\Modules\PSScriptAnalyzer\1.17.1\Settings\CodeFormatting.psd1.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSPlaceCloseBrace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSPlaceOpenBrace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentWhitespace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentIndentation rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSAlignAssignmentStatement rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
foo |
Thanks for the detailed response. I will look into this, this week is a bit busy but I hope to do it at least by the end of the month |
Hi @bergmeister , Did you manage to reproduce the issue? |
@chrisshearing I believe this is due to #769 which I hope to fix in PSSA 1.18 or at least 1.19 in the next months |
Uh oh!
There was an error while loading. Please reload this page.
Steps to reproduce
I originally opened this on the vscode-powershell#1583 project, but I've been directed to open an issue here directly.
I'm currently creating DSC Resource modules to apply settings in our environment, I'm breaking down the actual settings to individual files to make managing the settings easier and to have an easy structure of those settings.
The issue is that the formatter is not performing the align dsc resource / hash table function on the files to import.
It's not really relevant but i'm using the following code in my policy.schema.psm1 file
each individual file then looks like this:
DisableLocalMachineRunOnce.ps1
most of the formatting works, but not the alignment, if I add a configuration section around the code it works, but that would break my import.
I can provide a bit more information when I'm back in the office tomorrow if any is needed, but I wanted to make sure I'd opened the issue since I was aware.
Expected behavior
Actual behavior
Environment data
I'm using PSScriptAnalyzer as part of vscode-powershell using the current version.
The text was updated successfully, but these errors were encountered: