{"id":17524,"date":"2019-03-22T11:17:16","date_gmt":"2019-03-22T19:17:16","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/powershell\/?p=17524"},"modified":"2022-05-23T09:43:29","modified_gmt":"2022-05-23T17:43:29","slug":"powershell-scriptanalyzer-version-1-18-0-released","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/powershell-scriptanalyzer-version-1-18-0-released\/","title":{"rendered":"PowerShell ScriptAnalyzer Version 1.18.0 Released"},"content":{"rendered":"<p><code>PSScriptAnalyzer<\/code>\u00a0(<code>PSSA<\/code>)\u00a0<code>1.18.0<\/code>\u00a0is now available on the\u00a0<a href=\"https:\/\/www.powershellgallery.com\/packages\/PSScriptAnalyzer\/1.18.0\" rel=\"nofollow\">PSGallery<\/a>\u00a0and brings a lot of improvements in the following areas:<\/p>\n<ul>\n<li>Better compatibility analysis of commands, types and syntax across different platforms and versions of PowerShell<\/li>\n<li>Better formatting and customization. New capabilities are:\n<ul>\n<li>Multi-line pipeline indentation styles<\/li>\n<li>Cmdlet casing for better consistency and readability<\/li>\n<li>Consistent whitespace inside braces and pipes<\/li>\n<\/ul>\n<\/li>\n<li>Custom rules can now be suppressed and preserve the\u00a0<code>RuleSuppressionID<\/code><\/li>\n<li>Better DSC support by being able to understand different syntaxes of\u00a0<code>Import-DscResource<\/code><\/li>\n<li>Better user experience by being able to pipe to\u00a0<code>Invoke-ScriptAnalyzer<\/code>\u00a0and added tab completion of the returned objects that are piped to the next pipeline<\/li>\n<li>Better handling of parsing errors by emitting them as a diagnostic record with a new\u00a0<code>Severity<\/code>\u00a0type<\/li>\n<li>Improved Performance: Expect it to be about twice as fast in most cases and even more when re-analyzing a file. More on this\u00a0<a href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#Engine-Improvements\">below<\/a><\/li>\n<li>Fixes and enhancements to the engine, rules, and documentation<\/li>\n<\/ul>\n<p>There are some minor breaking changes such as e.g. requiring the minimum version of PowerShell Core to 6.1 as 6.0 has reached the end of its support lifecycle. With this, it was possible to update the used version of\u00a0<code>Newtonsoft.Json<\/code>\u00a0to\u00a0<code>11.0.2<\/code>. On Windows PowerShell, the minimum required runtime was upped from<code>4.5.0<\/code>\u00a0to<code>4.5.2<\/code>, which is the lowest version that is still supported by Microsoft but Windows update will have taken care of upgrading the to this patched version anyway, therefore no disruption is expected. We have also replaced old command data files of PowerShell 6.0 with a newer version for the<code>UseCompatibleCmdlets<\/code>rule.<\/p>\n<h2><a id=\"user-content-formatting\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#formatting\" aria-hidden=\"true\"><\/a>Formatting<\/h2>\n<p>New rules and new features\/customization of existing rules were added and in an upcoming release of the\u00a0<a href=\"https:\/\/code.visualstudio.com\/docs\/languages\/powershell\" rel=\"nofollow\">PowerShell vscode extension<\/a>, those new features will also be configurable from within the extension in an upcoming update.<\/p>\n<h3><a id=\"user-content-new-psuseconsistentwhitespace-options\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#new-psuseconsistentwhitespace-options\" aria-hidden=\"true\"><\/a>New PSUseConsistentWhitespace options<\/h3>\n<p>The\u00a0<a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/RuleDocumentation\/UseConsistentWhitespace.md\">PSUseConsistentWhitespace<\/a>\u00a0rule has 2 new configuration options that are both enabled by default:<\/p>\n<ul>\n<li>CheckInnerBrace: Checks if there is a space after the opening brace and a space before the closing brace. E.g.\u00a0<code>if ($true) { foo }<\/code>\u00a0instead of\u00a0<code>if ($true) {bar}<\/code>.<\/li>\n<li>CheckPipe: Checks if a pipe is surrounded on both sides by a space. E.g.\u00a0<code>foo | bar<\/code>\u00a0instead of<code>foo|bar<\/code>.<\/li>\n<\/ul>\n<p>In an upcoming update of the\u00a0<a href=\"https:\/\/code.visualstudio.com\/docs\/languages\/powershell\" rel=\"nofollow\">PowerShell vscode extension<\/a>, this feature will be configurable in the editor via the\u00a0settings\u00a0<code>powershell.WhitespaceInsideBrace<\/code>\u00a0and\u00a0<code>powershell.WhitespaceAroundPipe<\/code>.<\/p>\n<h3><a id=\"user-content-new-pipelineindentation-option-for-psuseconsistentindentation\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#new-pipelineindentation-option-for-psuseconsistentindentation\" aria-hidden=\"true\"><\/a>New PipelineIndentation option for PSUseConsistentIndentation<\/h3>\n<p>The\u00a0<a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/RuleDocumentation\/UseConsistentIndentation.md\">PSUseConsistentIndentation<\/a>\u00a0rule was fixed to handle multi-line pipeline (before, the behavior was a bit ill-defined) and as part of that we decided to expose 3 options for a new configuration option called<code>PipelineIndentation<\/code>. This allows PSSA to cater to different tastes of the user whether to increase indentation after a pipeline for multi-line statements. The settings are:<\/p>\n<ul>\n<li>IncreaseIndentationForFirstPipeline (default): Indent once after the first pipeline and keep this indentation. Example:<\/li>\n<\/ul>\n<div class=\"highlight highlight-source-powershell\">\n<pre class=\"lang:default decode:true\">foo |\r\n    bar |\r\n    baz<\/pre>\n<\/div>\n<ul>\n<li>IncreaseIndentationAfterEveryPipeline: Indent more after the first pipeline and keep this indentation. Example:<\/li>\n<\/ul>\n<div class=\"highlight highlight-source-powershell\">\n<pre class=\"lang:default decode:true\">foo |\r\n    bar |\r\n        baz<\/pre>\n<\/div>\n<ul>\n<li>NoIndentation: Do not increase indentation. Example:<\/li>\n<\/ul>\n<div class=\"highlight highlight-source-powershell\">\n<pre class=\"lang:default decode:true\">foo |\r\nbar |\r\nbaz<\/pre>\n<\/div>\n<p>In an upcoming update of the PowerShell vscode extension, this feature will be configurable in the editor via the setting\u00a0<code>powershell.codeFormatting<\/code>.<\/p>\n<h3><a id=\"user-content-new-psuseconsistentcasing-rule\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#new-psuseconsistentcasing-rule\" aria-hidden=\"true\"><\/a>New PSUseConsistentCasing rule<\/h3>\n<p>By popular request, this rule can correct the casing of cmdlet names. This can correct e.g.\u00a0<code>get-azadapplicaTION<\/code>\u00a0to\u00a0<code>Get-AzADApplication<\/code>. This not only makes code more consistent but can improve readability in most cases. In an upcoming update of the PowerShell vscode extension, this feature will be configurable in the editor via the setting<code>powershell.useCorrectCasingsettings<\/code>.<\/p>\n<h2><a id=\"user-content-compatibility-analysis\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#compatibility-analysis\" aria-hidden=\"true\"><\/a>Compatibility Analysis<\/h2>\n<p>The\u00a0<a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/RuleDocumentation\/UseCompatibleCmdlets.md\">UseCompatibleCmdlets<\/a>\u00a0rule requires JSON files in the\u00a0<code>Settings<\/code>\u00a0folder of PSSA&#8217;s installation and their file name is mapped to directly the\u00a0<code>compatibility<\/code>\u00a0configuration. In the new version we have replaced the JSON files for PowerShell 6.0 with files for 6.1 and also added new files for e.g. ARM on Linux (Raspian) and also PowerShell 2.0 that is still being used by some despite it being deprecated. If desired, one can always add custom JSON files to the\u00a0<code>Settings<\/code>\u00a0folder and it will just work by using the filename without the need to re-compile. To generate your custom JSON file for your environment, you can use the\u00a0<a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/Utils\/New-CommandDataFile.ps1\">New-CommandDataFile.ps1<\/a>\u00a0script.<\/p>\n<p>To further add more analysis, 3 more rules were being added:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/RuleDocumentation\/UseCompatibleSyntax.md\">UseCompatibleSyntax<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/RuleDocumentation\/UseCompatibleTypes.md\">UseCompatibleTypes<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/RuleDocumentation\/UseCompatibleCommands.md\">UseCompatibleCommands<\/a><\/li>\n<\/ul>\n<p>These rules do not follow the definition style of the\u00a0<code>UseCompatibleCmdlets<\/code>\u00a0rule. For usage and examples please refer to the rule documentation links of the 3 new rules above, there will be a more detailed blog post about them in the future.<\/p>\n<h2><a id=\"user-content-better-dsc-support\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#better-dsc-support\" aria-hidden=\"true\"><\/a>Better DSC Support<\/h2>\n<p><code>Invoke-ScriptAnalyzer<\/code>\u00a0has a\u00a0<code>-SaveDscDependency<\/code>\u00a0switch that will download the required module from the\u00a0<code>PSGallery<\/code>to allow for parsing of the DSC files. In order to do that is has to parse calls to\u00a0<code>Import-DscResource<\/code>\u00a0correctly. Previously it could neither take the version into account or parse the hashtable syntax (<code>Import-DscResource -ModuleName (@{ModuleName=\"SomeDscModule1\";ModuleVersion=\"1.2.3.4\"})<\/code>). We added support for both of them. But because there could be different variations of the first one (different parameter name order or not using named paramters, etc.), please use it in the form\u00a0<code>Import-DscResource -ModuleName MyModuleName -ModuleVersion 1.2.3.4<\/code>.<\/p>\n<h2><a id=\"user-content-custom-rules\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#custom-rules\" aria-hidden=\"true\"><\/a>Custom Rules<\/h2>\n<p>We added the capability of being able to suppress violations from custom rules the same way how you can already\u00a0<a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer#suppressing-rules\">suppress<\/a>\u00a0rules from the built-in rules. It is worth noting though that the rulename of custom rules has to be of the format\u00a0<code>CustomRuleModuleFileName\\CustomRuleName<\/code>, this is to uniquely identify the rule as it could be possible that 2 custom rule modules emit a rule of the same name.<\/p>\n<p>When a custom rule emits a\u00a0<code>DiagnosticRecord<\/code>, then the engine has to translate all properties of the object as it has to be re-created when emitting it via\u00a0<code>Invoke-ScriptAnalyzer<\/code>. We added the translation of the\u00a0<code>SuggestedCorrections<\/code>property already in the last release (1.17.1) to allow for auto-correction in the editor or via the\u00a0<code>-Fix<\/code>\u00a0switch. However, we also found that customers want to also use the\u00a0<code>RuleSuppressionID<\/code>\u00a0property in their custom rules, so we added translation for this as well.<\/p>\n<h2><a id=\"user-content-engine-improvements\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#engine-improvements\" aria-hidden=\"true\"><\/a>Engine Improvements<\/h2>\n<p>PSScriptAnalyzer is highly multi-threaded by executing each rule (excluding custom or DSC rules) in parallel in each own thread. But there are some global resources such as e.g. a\u00a0<code>CommandInfo<\/code>\u00a0cache that needs to be accessed using a lock. Caching and lock granularity has been improved and are therefore reducing congestion which leads to much better performance. You can expect PSScriptAnalyzer to be about twice as fast for &#8216;cold runs&#8217; (where\u00a0<code>Invoke-ScriptAnalyzer<\/code>has not been called before) and magnitudes faster when re-analyzing the same file. To you as a user, this will mean that you will see the squiggles faster when opening a new file in VS-Code and you will get faster updates when editing a file whilst reducing the CPU consumption in the background. We have more optimizations planned in this area, you can expect further improvements of similar scale in future versions and we hope to release future versions more frequent as well.<\/p>\n<h2><a id=\"user-content-miscellaneous-fixes\" class=\"anchor\" href=\"https:\/\/github.com\/PowerShell\/PowerShell-Blog\/blob\/7425df291a0424a816d62f8394904236297b87cf\/Posts\/2019-03-22-ScriptAnalyzer-1-18-0.md#miscellaneous-fixes\" aria-hidden=\"true\"><\/a>Miscellaneous Fixes<\/h2>\n<p>We received reports of some functionality not working when using Turkish culture and made a fix for and as part reviewed some culture critical points and made sure they work better across all cultures. The bug was very specific to Turkish culture, therefore we are confident that PSSA should work with any other cultures as well.<\/p>\n<p>The\u00a0<a href=\"https:\/\/github.com\/PowerShell\/PSScriptAnalyzer\/blob\/development\/CHANGELOG.MD\">Changelog<\/a>\u00a0has more details on the various fixes that were made to other rules.<\/p>\n<p>On behalf of the Script Analyzer team,<\/p>\n<p>Chris Bergmeister, Project Maintainer\nJim Truher, Senior Software Engineer, Microsoft<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PSScriptAnalyzer\u00a0(PSSA)\u00a01.18.0\u00a0is now available on the\u00a0PSGallery\u00a0and brings a lot of improvements in the following areas: Better compatibility analysis of commands, types and syntax across different platforms and versions of PowerShell Better formatting and customization. New capabilities are: Multi-line pipeline indentation styles Cmdlet casing for better consistency and readability Consistent whitespace inside braces and pipes Custom rules [&hellip;]<\/p>\n","protected":false},"author":2413,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3182],"class_list":["post-17524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-psscriptanalyzer"],"acf":[],"blog_post_summary":"<p>PSScriptAnalyzer\u00a0(PSSA)\u00a01.18.0\u00a0is now available on the\u00a0PSGallery\u00a0and brings a lot of improvements in the following areas: Better compatibility analysis of commands, types and syntax across different platforms and versions of PowerShell Better formatting and customization. New capabilities are: Multi-line pipeline indentation styles Cmdlet casing for better consistency and readability Consistent whitespace inside braces and pipes Custom rules [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/17524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/2413"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=17524"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/17524\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=17524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=17524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=17524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}