Last active
July 5, 2019 13:12
-
-
Save johlju/7579549c9d43fe9595e267242a9aabfc to your computer and use it in GitHub Desktop.
Get script module files with a line length longer than 120 characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scriptModulesFiles = Get-ChildItem -Path '.' -Recurse -Include '*.psm1' | |
$lines = [PSCustomObject] @() | |
$scriptModulesFiles | % { | |
$parseErrors = $null | |
$definitionAst = [System.Management.Automation.Language.Parser]::ParseFile($_.FullName, [ref] $null, [ref] $parseErrors) | |
if ($parseErrors) | |
{ | |
throw $parseErrors | |
} | |
$astFilter = { | |
$args[0] -is [System.Management.Automation.Language.CommandAst] ` | |
-and $args[0].Extent.EndColumnNumber -gt 120 | |
} | |
$commandAsts = $definitionAst.FindAll($astFilter, $true) | |
foreach ($commandAst in $commandAsts) | |
{ | |
$lines += [PSCustomObject] @{ | |
Script = $_.Name | |
Line = $commandAst.Extent.StartLineNumber | |
Length = $commandAst.Extent.EndColumnNumber | |
Text = $commandAst.Extent.EndScriptPosition.Line | |
} | |
} | |
} | |
$lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment