Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Finding TODOs and Reporting in PowerShell
#full details now available: http://tiredblogger.wordpress.com/2011/12/28/finding-todos-and-reporting-in-powershell/
param(
#this is appalling; there has to be a better way to get the raw name of "this" directory.
[string]$DirectoryMask = (get-location),
[array]$Include =
@("*.spark","*.cs","*.js","*.coffee","*.rb"),
[array]$Exclude =
@("fubu-content","packages","build","release"),
[switch]$Html,
[string]$FileName = "todoList.html")
$originalFiles =
gci -Recurse -Include $Include -Exclude $Exclude -Path $DirectoryMask;
$withoutExcludes = $originalFiles | ? {
if ($Exclude.count -gt 0) {
#need moar regex
[regex] $ex =
# 1: case insensitive and start of string
# 2: join our array, using RegEx to escape special characters
# the * allow wildcards so directory names filter out
# and not just exact paths.
# 3: end of string
# 1 2 3
'(?i)^(.*'+(($Exclude|%{[regex]::escape($_)}) -join ".*|.*")+'.*)$'
$_ -notmatch $ex
}
else {
$_
}
}
$todos = $withoutExcludes |
% { select-string $_ -pattern "TODO:" } |
select-object LineNumber, FileName, Line;
$todoReplacer = '(#|//).TODO:.'
$formattedOutput = $todos | select-object `
@{Name='LineNumber'; Expression={$_.LineNumber}}, `
@{Name='FileName'; Expression={$_.FileName}}, `
@{Name='TODO'; Expression={[regex]::replace($_.Line.Trim(),$todoReplacer,'')}}
if ($Html) {
$head = @'
<style>
body{ font-family:Segoe UI; background-color:white;}
table{ border-width: 1px;border-style: solid;
border-color: black;border-collapse: collapse;width:100%;}
th{ font-family:Segoe Print;font-size:1.0em; border-width: 1px;
padding: 2px;border-style: solid;border-color:black;
background-color:lightblue;}
td{ border-width: 1px;padding: 2px;border-style: solid;
border-color: black;background-color:white;}
</style>
'@
$solutionName =
(Get-Location).ToString().Split("\")[(Get-Location).ToString().Split("\").Count-1];
$header = "<h1>"+$solutionName +" TODO List</h1><p>Generated on "+ [DateTime]::Now +".</p>"
$title = $solutionName +" TODO List"
$formattedOutput |
ConvertTo-HTML -head $head -body $header -title $title |
Out-File $FileName
}
else {
$formattedOutput
}
@drlongnecker

This comment has been minimized.

Copy link
Owner Author

drlongnecker commented Dec 27, 2011

Using the ? (where) -notmatch because -Excludes is full of fail in PowerShell 2.0 still. =/

@andyedinborough

This comment has been minimized.

Copy link

andyedinborough commented Dec 27, 2011

o_0 ... must learn moar powershell

@drlongnecker

This comment has been minimized.

Copy link
Owner Author

drlongnecker commented Jan 22, 2012

Updated the TODO replacement finder to handle '# TODO: ' for ruby and coffeescript files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.