Skip to content

Enable further analyzer rules for better code styling control and more (OSOE-501) #16

@BenedekFarkas

Description

@BenedekFarkas

Review https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/readme and out of the ones that aren't enabled by default, select the appropriate ones. Repositories to check: OSOCE, Infrastructure Scripts, Utility Scripts.

Complete list:

  1. PSAlignAssignmentStatement: The authors recommend this for readability (I like it better too) and it's easy to fix and maintain in VS Code with just one setting. Moved to Enable PSAlignAssignmentStatement analyzer rule (OSOE-538) #21.
  2. PSAvoidLongLines: For C#, we have guidelines (vertical ruler) for 120 and 140 characters and have a hard limit at 150, so 150 here would be nice. We have 72 violations overall at the 150 limit. Moved to Enable PSAvoidLongLines analyzer rule (OSOE-540) #23.
  3. ✔️PSAvoidSemicolonsAsLineTerminators: This is super simple but requires update to 1.21.0 (doesn't seem to be any breaking changes so far).
  4. ✔️PSAvoidUsingDoubleQuotesForConstantString: Consistency! VS Code could auto-fix this if powerShell.codeFormatting.useConstantStrings is enabled. We're currently only surfacing Warnings and Errors (but not Information entries). This rule has Information severity, but the docs is outdated on that, so I created an issue and PR: Documentation is outdated on the AvoidUsingDoubleQuotesForConstantString rule's Severity and Configurability MicrosoftDocs/PowerShell-Docs-Modules#128
    We can lower the threshold (I'd actually rather move it to the settings file from Invoke-Analyzers.ps1) to Information and then disable the rules that we don't care about but enabled by default (there are only 2 such possible rules).
  5. ✔️PSPlaceCloseBrace
  6. ✔️PSPlaceOpenBrace
  7. PSUseCompatibleCommands: Skip (at least I don't see its usefulness at the moment).
  8. PSUseCompatibleSyntax: I don't think we need this, because we run analysis on both the latest Windows PowerShell and PowerShell Core, so incompatible syntax is already surfaced by runtime errors.
  9. PSUseCompatibleTypes: Probably not interesting now.
  10. ✔️PSUseConsistentIndentation: Definitely useful!
  11. ✔️UseConsistentWhitespace: Definitely useful!
  12. ✔️PSUseCorrectCasing: Also great for consistency. Not yet enabled because of Enabling PSUseCorrectCasing causes error while processing code that doesn't violate it PowerShell/PSScriptAnalyzer#1881. Moved to (blocked) Enable PSUseCorrectCasing analyzer rule (OSOE-539) #22.

Jira issue

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions