GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refactor rules methods by Haimasker · Pull Request #2182 · PowerShell/PSScriptAnalyzer

Conversation

@Haimasker

@Haimasker Denis Melnikov (Haimasker) commented May 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Refactor methods into one-liners using lambda operator.
  • Unify methods style across all rules.
  • Add automatic code style check into build process.

PR Summary

Motivation:
I consider these changes useful, because such refactoring allows to reduce the total amount of code in the rules, thereby the developer will be more focused on the logic of the rule itself. In the future, it is planned to complete refactoring with other code style rules.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Haimasker
Denis Melnikov (Haimasker) requested review from a team and Christoph Bergmeister (bergmeister) as code owners May 4, 2026 15:41
Copilot AI review requested due to automatic review settings May 4, 2026 15:41
Copilot started reviewing on behalf of Denis Melnikov (Haimasker) May 4, 2026 15:43
View session
Copilot started reviewing on behalf of Denis Melnikov (Haimasker) May 4, 2026 15:43
View session
Copilot AI reviewed May 4, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors rule metadata to expose SourceType as a property rather than a GetSourceType() method, and renames the enum backing that metadata to RuleSourceType, updating the engine and built-in rules to match. The goal is to reduce boilerplate and standardize how built-in rules report their origin.

Changes:

  • Replace GetSourceType() implementations across built-in rules (and the rule template) with a SourceType property.
  • Rename SourceType enum to RuleSourceType and update IRule/RuleInfo/command plumbing accordingly.
  • Apply minor whitespace/formatting cleanups in touched rule files.

Reviewed changes

Copilot reviewed 83 out of 83 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Utils/RuleMaker.psm1 Updates the rule-generation template to emit the new SourceType property.
Rules/UseVerboseMessageInDSCResource.cs Replaces GetSourceType() with SourceType property.
Rules/UseUTF8EncodingForHelpFile.cs Replaces GetSourceType() with SourceType property.
Rules/UseUsingScopeModifierInNewRunspaces.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/UseToExportFieldsInManifest.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/UseSupportsShouldProcess.cs Replaces GetSourceType() with SourceType property.
Rules/UseStandardDSCFunctionsInResource.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/UseSingularNouns.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/UseSingleValueFromPipelineParameter.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/UseShouldProcessForStateChangingFunctions.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/UseShouldProcessCorrectly.cs Replaces GetSourceType() with SourceType property.
Rules/UsePSCredentialType.cs Replaces GetSourceType() with SourceType property.
Rules/UseProcessBlockForPipelineCommand.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/UseOutputTypeCorrectly.cs Replaces GetSourceType() with SourceType property.
Rules/UseLiteralInitializerForHashtable.cs Replaces GetSourceType() with SourceType property.
Rules/UseIdenticalParametersDSC.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/UseIdenticalMandatoryParametersDSC.cs Replaces GetSourceType() with SourceType property.
Rules/UseDeclaredVarsMoreThanAssignments.cs Replaces GetSourceType() with SourceType property.
Rules/UseCorrectCasing.cs Replaces GetSourceType() override with SourceType override.
Rules/UseConstrainedLanguageMode.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/UseConsistentWhitespace.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/UseConsistentParametersKind.cs Replaces GetSourceType() override with SourceType override.
Rules/UseConsistentParameterSetName.cs Replaces GetSourceType() override with SourceType override.
Rules/UseConsistentIndentation.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/UseCompatibleCmdlets.cs Replaces GetSourceType() with SourceType property.
Rules/UseCmdletCorrectly.cs Replaces GetSourceType() with SourceType property.
Rules/UseBOMForUnicodeEncodedFile.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/UseApprovedVerbs.cs Replaces GetSourceType() with SourceType property.
Rules/ReviewUnusedParameter.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/ReturnCorrectTypesForDSCFunctions.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/ProvideCommentHelp.cs Replaces GetSourceType() override with SourceType override.
Rules/PossibleIncorrectUsageOfRedirectionOperator.cs Replaces GetSourceType() with SourceType property.
Rules/PossibleIncorrectUsageOfAssignmentOperator.cs Replaces GetSourceType() with SourceType property.
Rules/PossibleIncorrectComparisonWithNull.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/PlaceOpenBrace.cs Replaces GetSourceType() override with SourceType override.
Rules/PlaceCloseBrace.cs Replaces GetSourceType() override with SourceType override.
Rules/MissingModuleManifestField.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/MisleadingBacktick.cs Replaces GetSourceType() with SourceType property.
Rules/DscTestsPresent.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/DscExamplesPresent.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/CompatibilityRules/UseCompatibleSyntax.cs Replaces GetSourceType() override with SourceType override.
Rules/CompatibilityRules/CompatibilityRule.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidUsingWriteHost.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidUsingWMICmdlet.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidUsingPlainTextForPassword.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidUsingInvokeExpression.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidUsingDoubleQuotesForConstantString.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/AvoidUsingDeprecatedManifestFields.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidUsingConvertToSecureStringWithPlainText.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidUsingComputerNameHardcoded.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidUsingBrokenHashAlgorithms.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidUsingAllowUnencryptedAuthentication.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidUserNameAndPasswordParams.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidTrailingWhitespace.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidShouldContinueWithoutForce.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidSemicolonsAsLineTerminators.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidReservedWordsAsFunctionNames.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidReservedParams.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidReservedCharInCmdlet.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidPositionalParameters.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/AvoidOverwritingBuiltInCmdlets.cs Replaces GetSourceType() override with SourceType override.
Rules/AvoidNullOrEmptyHelpMessageAttribute.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidMultipleTypeAttributes.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidLongLines.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/AvoidInvokingEmptyMembers.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidGlobalVars.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidGlobalFunctions.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidGlobalAliases.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidExclaimOperator.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Rules/AvoidEmptyCatchBlock.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidDefaultValueForMandatoryParameter.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AvoidDefaultTrueValueSwitchParameter.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidAssignmentToAutomaticVariable.cs Replaces GetSourceType() with SourceType property.
Rules/AvoidAlias.cs Replaces GetSourceType() with SourceType property; whitespace cleanup.
Rules/AlignAssignmentStatement.cs Replaces GetSourceType() override with SourceType override; whitespace cleanup.
Engine/Generic/RuleSourceType.cs Renames the enum type from SourceType to RuleSourceType; updates doc comment.
Engine/Generic/RuleInfo.cs Updates RuleInfo.SourceType and constructors to use RuleSourceType.
Engine/Generic/IRule.cs Changes the rule contract from GetSourceType() to a SourceType property.
Engine/Generic/ExternalRule.cs Updates external rule implementation to SourceType property.
Engine/Generic/ConfigurableRule.cs Replaces abstract GetSourceType() with abstract SourceType property.
Engine/Generic/AvoidParameterGeneric.cs Replaces abstract GetSourceType() with abstract SourceType property.
Engine/Generic/AvoidCmdletGeneric.cs Replaces abstract GetSourceType() with abstract SourceType property.
Engine/Commands/GetScriptAnalyzerRuleCommand.cs Switches to reading rule.SourceType when producing RuleInfo.
Comments suppressed due to low confidence (1)

Engine/Generic/RuleSourceType.cs:10

  • Renaming the public enum SourceType to RuleSourceType (and changing the rule contract from GetSourceType() to a SourceType property) is a breaking API change for any external rule implementations or consumers compiled against previous versions. If maintaining compatibility is required, consider keeping SourceType (or providing an [Obsolete] shim) and adding the new property/mapping without removing the old symbols until a major version bump.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Engine/Generic/IRule.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Haimasker Denis Melnikov (Haimasker) changed the title Refactor GetSourceType method WIP: Refactor GetSourceType method May 4, 2026
@Haimasker
Denis Melnikov (Haimasker) force-pushed the replace-getter-method-with-property branch from dd25a91 to 23c7f9e Compare May 5, 2026 19:36
@Haimasker Denis Melnikov (Haimasker) changed the title WIP: Refactor GetSourceType method Refactor GetSourceType method May 5, 2026
@bergmeister
Christoph Bergmeister (bergmeister) requested a review from Copilot May 7, 2026 21:10
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) May 7, 2026 21:11
View session
Copilot AI reviewed May 7, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 77 out of 79 changed files in this pull request and generated 4 comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Utils/RuleMaker.psm1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Generic/ConfigurableRule.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Generic/AvoidCmdletGeneric.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Generic/AvoidParameterGeneric.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

bergmeister
Christoph Bergmeister (bergmeister) reviewed May 7, 2026
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the only value of this is to reduce number of lines of code and there are still many others methods left, it leaves state after this PR inconsistent. I think we have to make a decision first whether we want to go through this or not Andy Jordan (@andyleejordan) and if so we need to do it all in one go

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andyleejordan

Andy Jordan (andyleejordan) commented May 15, 2026

Copy link
Copy Markdown
Member

since the only value of this is to reduce number of lines of code and there are still many others methods left, it leaves state after this PR inconsistent. I think we have to make a decision first whether we want to go through this or not Andy Jordan (@andyleejordan) and if so we need to do it all in one go

This seems like something that could all be done in go by Opus 4.7 pretty easily. Let's not piecemeal it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Haimasker

Denis Melnikov (Haimasker) commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

Let's not piecemeal it.

Sure. I am marking request as "wip", will finish it soon.

andyleejordan and bergmeister reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Haimasker Denis Melnikov (Haimasker) changed the title Refactor GetSourceType method wip: Refactor GetSourceType method May 17, 2026
@Haimasker
Denis Melnikov (Haimasker) force-pushed the replace-getter-method-with-property branch from 23c7f9e to 1632c12 Compare June 20, 2026 17:10
@Haimasker
Refactor rules methods
8358c0c
* Refactor methods into one-liners using lambda operator.
* Add automatic code style check into build process.
@Haimasker
Denis Melnikov (Haimasker) force-pushed the replace-getter-method-with-property branch from 1632c12 to 8358c0c Compare June 20, 2026 18:07
@Haimasker Denis Melnikov (Haimasker) changed the title wip: Refactor GetSourceType method Refactor rules methods Jun 20, 2026
@Haimasker
Denis Melnikov (Haimasker) requested review from Christoph Bergmeister (bergmeister) and Copilot June 20, 2026 18:15
Copilot started reviewing on behalf of Denis Melnikov (Haimasker) June 20, 2026 18:16
View session
Copilot AI reviewed Jun 20, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 83 out of 85 changed files in this pull request and generated 1 comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread build.psm1
Comment on lines +84 to +100
function Test-CodeStyle
{
if ( -not $script:DotnetExe ) {
$script:DotnetExe = Get-DotnetExe
}
$dotnetArgs = "format",
"--verify-no-changes",
"style"
$formatOutput = & $script:DotnetExe $dotnetArgs 2>&1
if ( $LASTEXITCODE -ne 0 ) {
Write-Verbose -Verbose -Message "dotnet is $(${script:DotnetExe}.Source)"
$dotnetArgs | Foreach-Object {"dotnetArg: $_"} | Write-Verbose -Verbose
Get-PSCallStack | Write-Verbose -Verbose
Write-Verbose -Verbose -Message "$formatOutput"
throw "Please, fix code style via running 'dotnet format style' command."
}
}

@bergmeister Christoph Bergmeister (bergmeister) Sep 14, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Denis Melnikov (@Haimasker) Can you test please whether this suggestions makes sense and works?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bergmeister
Merge branch 'main' into replace-getter-method-with-property
4aab147
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot September 14, 2026 19:57
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) September 14, 2026 19:58
View session
Copilot AI reviewed Sep 14, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The style check depends on the caller’s working directory instead of explicitly targeting the repository solution.

Review details

Suppressed comments (1)

build.psm1:92

  • dotnet format is invoked without a solution path before the function changes to $projectRoot, so it searches the caller's current directory. Unlike the rest of this build function, invoking build.ps1 by absolute path from outside the repository will now fail even though PSScriptAnalyzer.sln is available via $projectRoot. Pass the solution explicitly so the build remains independent of the caller's working directory.
  • Files reviewed: 83/85 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@0x000NULL Ethan Aldrich (0x000NULL) mentioned this pull request Oct 19, 2026
Flag unused variables in multiple assignments in UseDeclaredVarsMoreThanAssignments #2227
Open
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@bergmeister Christoph Bergmeister (bergmeister) Awaiting requested review from bergmeister bergmeister is a code owner

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Haimasker @andyleejordan @bergmeister
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.