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

Set Code Formatting: settings based on existing PSScriptAnalyzerSettings.psd1 so autoformat stays in sync with ScriptAnalyzer #4993

Open
2 tasks done
daprahamian opened this issue May 20, 2024 · 2 comments
Labels
Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.

Comments

@daprahamian
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.

Summary

I need to have some PSScriptAnalyzer settings defined in a PSScriptAnalyzerSettings.psd1 so I can validate my code as part of CI. I also use VSCode, and keeping vscode settings and PSScriptAnalyzer settings in sync is a bit of a pain. Since PSScriptAnalyzer has a bunch of code formatting options supported, it would be great to be able to tell vscode to "format it the way Invoke-Formatter would.

Proposed Design

No response

@daprahamian daprahamian added Issue-Enhancement A feature request (enhancement). Needs: Triage Maintainer attention needed! labels May 20, 2024
@JustinGrote
Copy link
Collaborator

Is there a specific issue with this setting that is not reading your settings file?
image

@SydneyhSmith SydneyhSmith added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Triage Maintainer attention needed! labels May 22, 2024
@daprahamian
Copy link
Author

@JustinGrote here is an example:

# PSScriptAnalyzerSettings.psd1
@{
    Rules = @{
        PSAlignAssignmentStatement = @{
            Enable         = $false
            CheckHashtable = $false
        }
    }
}
# test_file.ps1
$dict = @{
    foo = "bar"
    basdasdasd = "zoom"
}

With the following setup, running Invoke-ScriptAnalyzer -Settings ./PSScriptAnalyzerSettings.psd1 -Path ./test_file.ps1 -Fix does not result in any changes to the file. But if I hit Ctrl+S inside of vscode, the file is auto-formatted as follows:

$dict = @{
    foo = "bar"
    basdasdasd = "zoom"
}

despite the fact that I have set

        PSAlignAssignmentStatement = @{
            Enable         = $false
            CheckHashtable = $false
        }

@github-actions github-actions bot added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels May 22, 2024
@JustinGrote JustinGrote added Up for Grabs Will shepherd PRs. and removed Needs: Maintainer Attention Maintainer attention needed! labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.
Projects
None yet
Development

No branches or pull requests

3 participants