Skip to content

Fix PSAvoidLongLines violations blocking CI in New-Jwt, Test-Jwt, and ConvertTo-Base64UrlString #24

@MariusStorhaug

Description

The CI pipeline fails on every platform (Linux, macOS, Windows) for both Lint-SourceCode and Lint-Module jobs due to PSAvoidLongLines violations detected by PSScriptAnalyzer. The default maximum line length enforced by the rule is 120 characters.

Request

What happens

Running the Process-PSModule workflow on PR #18 produces lint failures across all three platforms:

❌ Some [1] tests failed.
[-] Avoid long lines (PSAvoidLongLines) 63ms (61ms|2ms)

The same failure is reproduced on the built module artifact during Lint-Module, confirming the violations originate in source rather than being introduced by the build step. The Get-TestResults job then aggregates these failures and exits with a non-zero code, blocking the rest of the pipeline.

Reproduction steps

  1. Check out the init branch of this repository
  2. Run PSScriptAnalyzer against src/functions/public/:
Invoke-ScriptAnalyzer -Path ./src/functions/public/ -IncludeRule PSAvoidLongLines
  1. Observe violations reported in New-Jwt.ps1, Test-Jwt.ps1, and ConvertTo-Base64UrlString.ps1

What is expected

All source files pass PSAvoidLongLines with no violations so that the Lint-SourceCode and Lint-Module CI jobs succeed and the pipeline can continue through to publish.

Environment

  • Module version: unreleased (init branch, Actions run 25694258038)
  • PSScriptAnalyzer rule: PSAvoidLongLines (max 120 characters)
  • Platforms affected: Linux, macOS, Windows (all three matrix legs)

Regression

This has been present since the init branch was first pushed. Not a regression from a previously passing state.

Workaround

None. The CI gate cannot be bypassed without skipping the linter.

Acceptance criteria

  • All files under src/functions/public/ pass PSAvoidLongLines with no violations
  • No functional behavior of New-Jwt, Test-Jwt, or ConvertTo-Base64UrlString changes as a result of the reformatting
  • Lint-SourceCode and Lint-Module CI jobs pass on all three platforms

Technical decisions

Affected files and line counts: The violations are isolated to three files — New-Jwt.ps1 (7 lines), Test-Jwt.ps1 (6 lines), and ConvertTo-Base64UrlString.ps1 (2 lines — one in the .NOTES comment block, one in the throw statement). All exceed 120 characters.

Fix strategy: Each long line falls into one of three categories:

  1. Long throw message strings — extract the message into a $message variable on a preceding line, then throw using that variable.
  2. Long inline conditionals (if ($Secret -is [byte[]]) { $Secret } else { ... }) — split across multiple lines using PowerShell's implicit line continuation inside grouping expressions.
  3. Long .NOTES comment text — wrap the sentence at a natural word boundary within 120 characters.

Scope: Pure formatting change. No logic, parameter names, error types, or test assertions are altered.


Implementation plan

Source fixes

  • In New-Jwt.ps1, extract long throw message strings into $message variables (lines 80, 90, 101, 106, 128, 144)
  • In New-Jwt.ps1, split the long $hmacsha256.Key = if (...) {...} else {...} assignment across multiple lines (line 132)
  • In Test-Jwt.ps1, extract long throw message strings into $message variables (lines 78, 88, 103, 121, 154)
  • In Test-Jwt.ps1, split the long $hmacsha256.Key = if (...) {...} else {...} assignment across multiple lines (line 125)
  • In ConvertTo-Base64UrlString.ps1, wrap the .NOTES comment line at a word boundary under 120 characters (line 24)
  • In ConvertTo-Base64UrlString.ps1, extract the long throw message string into a $message variable (line 51)

Validation

  • Confirm Invoke-ScriptAnalyzer -Path ./src/functions/public/ -IncludeRule PSAvoidLongLines returns no results
  • Confirm all existing Pester tests in tests/Jwt.Tests.ps1 still pass after reformatting

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPatchSmall fixes or improvements

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions