Skip to content

Nested helper functions have no CmdletBinding, help or parameter types (FUN-01, DOC-01, FUN-20, MOD-01) #65

Open

Description

@fadwen

Summary

Seventy helper functions are defined inside other functions of the module. None has [CmdletBinding()] or help, most have untyped parameters, and none is in a file of its own. ai-powershell-standards 2.0.0 asks for every function to be an advanced function with help (FUN-01, DOC-01), with typed parameters and a declared output type (FUN-20, FUN-10), in its own file named after it (MOD-01).

Findings

Counts are from the standards' compliance check (FUN-01, DOC-01) and from a parse of each file (FUN-20, FUN-10).

File Nested helpers
Public/Compare-IntuneDeployedScript.ps1 16
Public/Test-IntuneDeployedScript.ps1 10
Public/Get-IntuneScriptHealth.ps1 5
Public/Export-IntuneAgentDiagnostic.ps1 4
Public/Invoke-IntuneWin32AppTest.ps1 4
Public/Test-IntuneAssignmentFilter.ps1 4
Public/Export-IntuneFindingSarif.ps1 1
Public/Test-IntuneScript.ps1 1
Public/Test-IntuneWin32Requirement.ps1 1
Private/ConvertFrom-IslFilterRule.ps1 11
Private/Rules/Find-IslInteractiveCall.ps1 3
Private/Rules/Find-IslExitCodeIssue.ps1 2
Private/Rules/Find-IslModuleDependency.ps1 2
Private/Get-IslAgentLogEvent.ps1 2
Private/Invoke-IslGraphRequest.ps1 2
Private/Get-IslSetting.ps1 1
  • FUN-01 and DOC-01: all 69 nested helpers, and the top-level Test-IslPesterAssertionSupport in Public/Assert-IntuneResult.ps1, have no [CmdletBinding()] and no help.
  • FUN-20: 47 parameters of nested helpers have no type, and 4 are [bool] where the rule asks for [switch].
  • FUN-10: none of the 69 declares [OutputType()].
  • MOD-01: two files hold several top-level functions. Public/Assert-IntuneResult.ps1 holds the seven exported Assert-* functions and one helper, and Private/Find-IslAstNode.ps1 holds seven functions. Private/Resolve-IslAccount.ps1 holds two.
  • Three public commands each define their own Test-Wanted and Get-WantedPolicy. The copies differ, and the names say nothing about which command they belong to.

The nested helpers also read the variables of the function around them. FUN-06 covers the one case that has already gone wrong here, $PSBoundParameters inside a nested helper being the helper's own.

Proposed change

Move each helper to its own file under Private, as an advanced function with an Isl prefix, typed parameters, [OutputType()] and full comment-based help, and pass it what it reads from the outer function as parameters. Split Assert-IntuneResult.ps1 and Find-IslAstNode.ps1 into one file for each function. Where two commands share a helper that does the same work, keep one copy.

This is the largest change in the set and it changes no behaviour, so it can be done one public command at a time, each with the command's existing tests as the check, plus InModuleScope tests for helpers that carry logic of their own.

Decision needed

The standards have no rule that forbids a nested function as such. If the owner prefers to keep small closures nested, FUN-01, DOC-01, FUN-20 and FUN-10 still apply to them in place, and each helper kept nested needs [CmdletBinding()], a param() block with types, an output type and help where it stands. Moving them out is the smaller amount of text for each function and the only form that also meets MOD-01.

Discovered and written up with Claude Code.

Activity

  1. added
    enhancement
    on Nov 22, 2026
  2. fadwen commented on Nov 24, 2026

    @fadwen
    OwnerAuthor

    Decision by the owner: move the helpers out. Each nested helper becomes its own file under Private, an advanced function with an Isl prefix, typed parameters, [OutputType()] and full comment-based help, and it takes what it read from the outer function as parameters. Copies that do the same work in several commands, such as Test-Wanted and Get-WantedPolicy, become one. Assert-IntuneResult.ps1, Find-IslAstNode.ps1 and Resolve-IslAccount.ps1 are split into one file for each function (MOD-01).

    The work goes one command, or one group of small helpers, at a time, each as its own pull request stacked on the one before, with the command's existing tests as the check and InModuleScope tests for a helper that carries logic of its own. The first takes the four commands with one helper each (Test-IntuneScript, Test-IntuneWin32Requirement, Export-IntuneFindingSarif, Get-IslSetting).

    The last two throw statements of the module are in nested helpers (Get-IslSetting and Invoke-IslGraphRequest); once those helpers are advanced functions they end with $PSCmdlet.ThrowTerminatingError(), and Tests/Unit/Module.ErrorFlow.Tests.ps1 keeps the calls guarded.

    Discovered and written up with Claude Code.

  3. fadwen commented on Nov 24, 2026

    @fadwen
    OwnerAuthor

    Progress, as a stack of pull requests that merge in this order:

    1. refactor(helpers): move four nested helpers into their own files #100: Test-IntuneScript, Test-IntuneWin32Requirement, Export-IntuneFindingSarif, Get-IslSetting (4 helpers). Based on main; CI passed.
    2. refactor(helpers): move the log, diagnostic and Graph helpers out #101: Get-IslAgentLogEvent, Export-IntuneAgentDiagnostic, Invoke-IslGraphRequest (8 helpers). CI passed. With it, no function of the module uses throw.
    3. refactor(helpers): move the assignment filter's evaluator out #102: Test-IntuneAssignmentFilter (4 helpers). CI passed.
    4. refactor(helpers): move the helpers of three analyzer rules out #103: the rules Find-IslInteractiveCall, Find-IslExitCodeIssue, Find-IslModuleDependency (7 helpers). The one helper that built a finding stays in its rule as a loop, because Build/Build-RuleReference.ps1 reads finding tables from the rule files only; docs/Rules.md regenerates unchanged.

    23 of the 69 nested helpers are done. Each moved helper is a private function in its own file with full help, typed parameters and an output type, and has a test file of its own. Left: ConvertFrom-IslFilterRule (11), Invoke-IntuneWin32AppTest (4), Get-IntuneScriptHealth (5), Test-IntuneDeployedScript (10), Compare-IntuneDeployedScript (16), and the split of Assert-IntuneResult.ps1, Find-IslAstNode.ps1 and Resolve-IslAccount.ps1.

    Two things learned on the way, for the parts left: a .DESCRIPTION line that starts with .NET is read as a help keyword and leaves the function with no help that Get-Help finds (the standards' check reports it as DOC-01), and a function that writes files declares SupportsShouldProcess and is called with @script:IslInternal, which Tests/Unit/Module.WhatIf.Tests.ps1 checks.

    Discovered and written up with Claude Code.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions