Skip to content

Commit

Permalink
enhanced Find-Todos pwsh script
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
silverqx committed Jun 24, 2022
1 parent 735eee5 commit 83f933e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tools/Find-Todos.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,32 @@ Param(
HelpMessage = 'Specifies subfolders to search. The pattern value is treated ' +
'as a regular expression, eg. (include|src|tests).')]
[AllowEmptyString()]
[string] $InSubFoldersPattern = '(include|src|tests)'
[string] $InSubFoldersPattern = '(include|src|tests|tom)',

[Parameter(HelpMessage = 'Todo keywords regex pattern.')]
[ValidateNotNullOrEmpty()]
[string] $TodoKeywordsPattern = ' (TODO|NOTE|FIXME|BUG|WARNING|CUR|FEATURE|TEST|FUTURE|CUR1|TMP|SEC) '
)

Set-StrictMode -Version 3.0

$Script:TodoKeywordsPattern = ' (TODO|NOTE|FIXME|BUG|WARNING|CUR|FEATURE|TEST|FUTURE|CUR1|TMP|SEC) '

# If empty search all subfolders
if ($InSubFoldersPattern.Length -eq 0) {
$Script:InFolders = @($(Get-Location).Path, '?.*') -join [IO.Path]::DirectorySeparatorChar
$Script:InFolders = @($Path.TrimEnd('\*'), '?.*') -join [IO.Path]::DirectorySeparatorChar
}
else {
$Script:InFolders = `
(@($(Get-Location).Path, $InSubFoldersPattern) -join [IO.Path]::DirectorySeparatorChar) + `
(@($Path.TrimEnd('\*'), $InSubFoldersPattern) -join [IO.Path]::DirectorySeparatorChar) + `
[IO.Path]::DirectorySeparatorChar
}

if ($PSVersionTable.Platform -eq 'Win32NT') {
$Script:InFolders = $Script:InFolders -replace '\\', '\\'
}

Get-ChildItem -Path $Path -Include $Include -Recurse
Get-ChildItem -Path $Path -Include $Include -Recurse -File
| Where-Object DirectoryName -Match "^$Script:InFolders"
| Select-String -Pattern $Script:TodoKeywordsPattern -CaseSensitive
| Select-String -Pattern $TodoKeywordsPattern.toUpper() -CaseSensitive
| Select-Object -Property `
@{
Name = 'Line'
Expand Down

0 comments on commit 83f933e

Please sign in to comment.