Title: Settings file creation and validation by liamjpeters · Pull Request #2176 · PowerShell/PSScriptAnalyzer · GitHub
Open Graph Title: Settings file creation and validation by liamjpeters · Pull Request #2176 · PowerShell/PSScriptAnalyzer
X Title: Settings file creation and validation by liamjpeters · Pull Request #2176 · PowerShell/PSScriptAnalyzer
Description: PR Summary Extracted and built upon the settings discoverability of my PR #2134 (omitting all of the JSON file format bits and settings refactoring). Adds cmdlet New-ScriptAnalyzerSettingsFile, which generates complete settings files with everything set to it's default value. Adds cmdlet Test-ScriptAnalyzerSettingsFile, which validates a settings file (All rule names are valid, all settings valid etc). Updates cmdlet Get-ScriptAnalyzerRule to include an Options proprety for configurable rules, including default value. Fixes ProcessCustomRulePaths Engine Helper to ignore an empty array of CustomRulePaths. Motivation It's not easy or convenient to find out what all the rules and rule settings available are. Your options are really to look at this repo, copy a preset/existing settings file, or look through all of the rules pages on MSLearn. Many people do not even know about settings files. As a module developer, I want a way to discover what the available rules are and what options they have. I want an effortless way to add a settings file to my project that I can configure to my liking. New-ScriptAnalyzerSettingsFile By default this creates a ScriptAnalyzer settings file populated with all rule names and rule configuration (set to default values). The file has some comment help for each field. The file is always named PSScriptAnalyzerSettings.psd1 so that automatic settings discovery in Invoke-ScriptAnalyzer picks it up without any -Settings parameter needed. Any rule configuration that is an enum - we attempt to list the possible values as a comment after the default value. Example output of running New-ScriptAnalyzerSettingsFile in this gist You can optionally base the rule file on a preset. It takes the settings defined in the preset and normalises it all with the comments and all settings fields. Example output of running New-ScriptAnalyzerSettingsFile -BaseOnPreset CmdletDesign in this gist. Note: I'm sure some clever person could eventually plumb this into the VSCode extension, as a code action to create a new settings file perhaps. Test-ScriptAnalyzerSettingsFile This validates a settings file and tells you exactly what's wrong and where. It checks for: Parse errors Unknown rule names in IncludeRules, ExcludeRules, and Rules Rules in Rules that aren't configurable Unrecognised option names Option values that don't match the expected type (bool, int, string, arrays) Enum string values (e.g. Kind = 'banana' when the valid values are space and tab) Invalid severity values Each problem comes back as a DiagnosticRecord, unless -Quiet mode used - then just a boolean $true`$false` indicating whether the file is valid or not is returned. I debated for a while whether this should have just been a rule and after some chicken-or-egg thinking, decided it should be a separate cmdlet. Get-ScriptAnalyzerRule Added an Options property to the RuleInfo. I have not updated the format file, so it's not shown by default. I didn't know the implications of updating the format file. Running Get-ScriptAnalyzerRule -Name PSUseConsistentIndentation | select -expand Options gets you: Name OptionType DefaultValue PossibleValues ---- ---------- ------------ -------------- Enable System.Boolean False IndentationSize System.Int32 4 Kind System.String space {Space, Tab} PipelineIndentation System.String IncreaseIndentationForFirstPipeline {IncreaseIndentationForFirstPipeline, ... Successful test run in my fork. PR Checklist PR has a meaningful title Use the present tense and imperative mood when describing your changes Summarized changes Change is not breaking Make sure all .cs, .ps1 and .psm1 files have the correct copyright header Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation This PR is ready to merge and is not Work in Progress. If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
Open Graph Description: PR Summary Extracted and built upon the settings discoverability of my PR #2134 (omitting all of the JSON file format bits and settings refactoring). Adds cmdlet New-ScriptAnalyzerSettingsFile, wh...
X Description: PR Summary Extracted and built upon the settings discoverability of my PR #2134 (omitting all of the JSON file format bits and settings refactoring). Adds cmdlet New-ScriptAnalyzerSettingsFile, wh...
Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/pull/2176
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4b289756-7e70-0294-1df6-2f409a08f9f1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DFB2:37676C:14197D:1AD6C0:6AFD0F3E |
| html-safe-nonce | 258c4ea2695519d532d10e4d7cadcf1f042a0778d7009a66ed0e8a9076693ec2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkIyOjM3Njc2QzoxNDE5N0Q6MUFENkMwOjZBRkQwRjNFIiwidmlzaXRvcl9pZCI6IjExNjk1NDc1OTk2ODI1MzkzMjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4aea9fc050453194171548897b54780ee9b27b9301c7e9b117ad3db2d2eff4b7 |
| hovercard-subject-tag | pull_request:3562615174 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/PowerShell/PSScriptAnalyzer/pull/2176/files |
| twitter:image | https://avatars.githubusercontent.com/u/6566675?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/6566675?s=400&v=4 |
| og:image:alt | PR Summary Extracted and built upon the settings discoverability of my PR #2134 (omitting all of the JSON file format bits and settings refactoring). Adds cmdlet New-ScriptAnalyzerSettingsFile, wh... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b29de2abb97b6307b16270785efeb58b51a117d5a9b659acf00b77aa00e7043b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/PowerShell/PSScriptAnalyzer git https://github.com/PowerShell/PSScriptAnalyzer.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 33149177 |
| octolytics-dimension-repository_nwo | PowerShell/PSScriptAnalyzer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33149177 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PSScriptAnalyzer |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c9e619def6d670dc18a45d3b02cea938c1c7e47 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width