Skip to content

refactor(helpers): move the helpers of three analyzer rules out - #103

Open
fadwen wants to merge 4 commits into
refactor/helpers-filterfrom
refactor/helpers-rules
Open

fadwen wants to merge 4 commits into
refactor/helpers-filterfrom
refactor/helpers-rules

Conversation

@fadwen

@fadwen fadwen commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

The fourth part of #65. The seven helpers nested in three analyzer rules, Find-IslInteractiveCall, Find-IslExitCodeIssue and Find-IslModuleDependency, are handled: six are private functions in files of their own, each an advanced function with full help and an output type, and the seventh, which built a finding, is folded into its rule. Behaviour does not change, and docs/Rules.md comes out byte for byte the same.

Stacked on #102, #101 and #100.

Changes

Was Now Notes
Get-CredentialArgument in Find-IslInteractiveCall Get-IslCredentialArgument -Command typed CommandAst
Get-CredentialSource Get-IslCredentialSource the PSCredential type pattern moved with it
Get-VariableCredentialSource Get-IslVariableCredentialSource the script's tree as -Ast, where it read $ast from the rule
Get-ReturnReplacement in Find-IslExitCodeIssue Get-IslReturnReplacement
Test-ExitFollowsReturn Test-IslExitFollowsReturn
Test-InBox in Find-IslModuleDependency Test-IslInboxModuleName the in-box list as -InboxModule
Write-Missing in Find-IslModuleDependency kept in the rule see below
  • Write-Missing stays in the rule as a loop. Build/Build-RuleReference.ps1 reads the finding tables of each rule from the files under Private/Rules. A finding built in a helper under Private would have dropped out of docs/Rules.md. The rule now collects each module that is not in-box, with what named it and where, and one loop at the end builds the finding with the same table and the same variable names in its message. ./Build/Build-RuleReference.ps1 regenerates docs/Rules.md with no change, and Tests/Unit/RuleReference.Tests.ps1 passes.
  • The six functions were cut from the rules mechanically, so their bodies are the lines they had, moved four spaces left. That carries over four layout findings of the standards' check (STY-01 for three continuation lines and STY-02 for an elseif on its own line) in Get-IslCredentialSource and Get-IslVariableCredentialSource; they are left for Source layout does not follow the standards and CI does not check it (STY-01, STY-02, STY-04, STY-07) #73 with the rest of the module's layout.
  • Tests: a file for each of the six functions, each parsing small scripts: the ways Get-Credential is handed a credential and the ones that prompt; every way an expression builds a credential and some that do not; a variable built two ways, through a typed parameter and a scope prefix, and one with an assignment that could be anything; the return edits; where an exit falls relative to a return; and in-box names, paths and patterns. The rules' own tests are unchanged and pass.
  • The CHANGELOG entry of refactor(helpers): move four nested helpers into their own files #100 names the three rules.

Verification

Notes

  • Left for the parts that follow: ConvertFrom-IslFilterRule, Invoke-IntuneWin32AppTest, Get-IntuneScriptHealth, Test-IntuneDeployedScript and Compare-IntuneDeployedScript, and the split of the files that hold several functions.

The fourth part of #65. Six functions nested in Find-IslInteractiveCall,
Find-IslExitCodeIssue and Find-IslModuleDependency are private
functions in files of their own, advanced functions with full help and
output types, cut from the rules with their bodies unchanged:

- Get-CredentialArgument -> Get-IslCredentialArgument
- Get-CredentialSource -> Get-IslCredentialSource
- Get-VariableCredentialSource -> Get-IslVariableCredentialSource,
  with the script's tree as -Ast
- Get-ReturnReplacement -> Get-IslReturnReplacement
- Test-ExitFollowsReturn -> Test-IslExitFollowsReturn
- Test-InBox -> Test-IslInboxModuleName, with the list as -InboxModule

Write-Missing built a finding, and Build-RuleReference.ps1 reads the
finding tables from the rule files only, so it stays in the rule as a
loop over the modules the rule collected. docs/Rules.md regenerates
unchanged. Each new function has a test file of its own; the rules'
tests are unchanged.

Refs #65.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant