Skip to content

Instantly share code, notes, and snippets.

@johlju
Last active July 5, 2019 13:12
Show Gist options
  • Save johlju/7579549c9d43fe9595e267242a9aabfc to your computer and use it in GitHub Desktop.
Save johlju/7579549c9d43fe9595e267242a9aabfc to your computer and use it in GitHub Desktop.
Get script module files with a line length longer than 120 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