PowerShell / PowerShell/PSScriptAnalyzer

Check whether a module references itself in 'NestedModules' field in the .psd1 file

Open
#997 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue - Enhancement Issue - New Rule
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

This feature ask is per discussion in https://github.com/PowerShell/PowerShell/pull/6843#discussion_r187123774.

Importing a ill-structured module could result in a circular nested module. For example, for the following code, you will see 'True' as the output.

$testdir = Join-Path $env:TEMP test
$testpsm1 = Join-Path $testdir test.psm1
$testpsd1 = Join-Path $testdir test.psd1
mkdir $testdir > $null
Set-Content $testpsm1 -Value "function bar {}"
Set-Content $testpsd1 -Value "@{ ModuleVersion = '0.0.1'; RootModule = 'test'; NestedModules = @('test') }"

$m = Import-Module $testpsd1 -Pass
$m -eq $m.NestedModules[0]
> True

So maybe a rule can be written to check the bold part of test.psd1 "@{ ModuleVersion = '0.0.1'; RootModule = 'test'; NestedModules = @('test') }", to make sure the author is warned when a module like test.psd1 has itself as a nested module.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the circular nested-module example with the shown .psd1 content and inspect how PSScriptAnalyzer discovers and reports module issues. The change is done when a module whose NestedModules field references itself produces a warning, while valid nested-module declarations remain unaffected; the payload names no implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.