Skip to content

Commit 0e3f887

Browse files
committed
General linting (PSSharper) cleanup
1 parent 8170966 commit 0e3f887

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

Source/Convert-HelpToHtmlTree.ps1

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ function Convert-HelpToHtmlTree
309309
Write-Host "Target dir: $TargetDir"
310310
Write-Host "Source dir: $moduleRoot"
311311

312-
$Namespaces = GlobExpandNamespaceArgument $Namespaces
312+
$Namespaces = Get-GlobExpandNamespaceArgument $Namespaces
313313

314314
if (!$Namespaces) {
315-
[void](Handle-MissingValue "No namespaces found");
315+
[void](Handle-MissingValue "No namespaces found")
316316
}
317317
else {
318318
$namespaceSummary = @{}
@@ -329,7 +329,7 @@ function Convert-HelpToHtmlTree
329329
$emptyNamespaces = $modules.Keys | Where { !$modules[$_] }
330330
if ($emptyNamespaces) {
331331
[void](Handle-MissingValue ("No modules found for these namespaces: $emptyNamespaces`n"+
332-
" (typically indicates your module directories are not within a namespace directory)"));
332+
' (typically indicates your module directories are not within a namespace directory)'))
333333
}
334334

335335
$title = ""
@@ -341,7 +341,7 @@ function Convert-HelpToHtmlTree
341341
Generate-HomePage $namespaceSummary $moduleRoot $title
342342
Generate-ContentsPage $title
343343

344-
"Done: {0} namespace(s), {1} module(s), {2} function(s), {3} file(s) processed." `
344+
'Done: {0} namespace(s), {1} module(s), {2} function(s), {3} file(s) processed.' `
345345
-f $Namespaces.Count, $moduleCount, $functionCount, $fileCount
346346
}
347347

@@ -350,21 +350,21 @@ function Convert-HelpToHtmlTree
350350

351351
########################### Support #############################
352352

353-
function GlobExpandNamespaceArgument($nsArgument)
353+
function Get-GlobExpandNamespaceArgument($nsArgument)
354354
{
355355
$nsArgument |
356356
% {
357357
Get-ChildItem -Path $moduleRoot -Filter $_ |
358-
select -ExpandProperty Name
358+
Select -ExpandProperty Name
359359
}
360360
}
361361

362362
function Import-AllModules($namespace)
363363
{
364364
$namespaceDir = Join-Path $moduleRoot $namespace
365365
$modules = @(Get-ChildItem $namespaceDir |
366-
where { $_.PsIsContainer } |
367-
select -ExpandProperty Name)
366+
Where { $_.PsIsContainer } |
367+
Select -ExpandProperty Name)
368368
$validModules = @()
369369
$modules |
370370
% {
@@ -391,8 +391,8 @@ function Remove-AllModules($namespace, $nsModules)
391391
function Get-CmdletDocLinks($referenceWebPage, $topicRegex)
392392
{
393393
# Adapted from http://powershell.com/cs/blogs/tips/archive/2010/10/06/scraping-information-from-web-pages.aspx
394-
$cmdletReferenceWebPage = "http://technet.microsoft.com/en-us/library/dd347701.aspx"
395-
$aboutReferenceWebPage = "http://technet.microsoft.com/en-us/library/dd347616.aspx"
394+
$cmdletReferenceWebPage = 'http://technet.microsoft.com/en-us/library/dd347701.aspx'
395+
$aboutReferenceWebPage = 'http://technet.microsoft.com/en-us/library/dd347616.aspx'
396396
$cmdletRegex = [RegEx]'<p>\s*<a\s+href="(http.*?)">(\w+-\w+)</a>'
397397
$aboutRegex = [RegEx]'<p>\s*<a\s+href="(http.*?)">(about_\w+)</a>'
398398

@@ -438,14 +438,14 @@ function Process-Namespace($namespace, $nsModules)
438438
$nsModules | % { Process-Module $namespace $_ $title}
439439
}
440440

441-
Add-ItemToContentsList $namespace "namespace" -itemUrl "index.html"
441+
Add-ItemToContentsList $namespace "namespace" -itemUrl $home_page_filename
442442
return $moduleSummary
443443
}
444444

445445
function Process-Module($namespace, $moduleName, $parentTitle)
446446
{
447447
Write-Host " Module: $moduleName"
448-
$script:moduleCount++;
448+
$script:moduleCount++
449449

450450
if (!$parentTitle) { $parentTitle = "{0} Namespace" -f $namespace }
451451
$moduleDocPath = Join-Path $TargetDir (Join-Path $namespace $moduleName)
@@ -475,22 +475,22 @@ function Generate-FunctionPages($moduleName, $moduleDocPath, $parentTitle, $help
475475
Filter-ThisModule $moduleName)
476476
if (!$functions) {
477477
[void](Handle-MissingValue ("No functions found in $moduleName;`n"+
478-
" (typically this means your functions or cmdlets are not exported)"));
478+
' (typically this means your functions or cmdlets are not exported)'))
479479
return
480480
}
481481
$functions |
482482
% {
483483
$function = $_.Name
484484
Write-Host (" {0}: {1}" -f $_.CommandType, $function)
485-
$script:functionCount++;
485+
$script:functionCount++
486486
$helpHash[$function] = Microsoft.PowerShell.Core\Get-Help $function -Full -ErrorAction SilentlyContinue
487487
# convert to string array;
488488
# must specify a wide width otherwise lines break at 80 characters!
489489
$helpText = @($helpHash[$function] | Out-String -Stream -Width 16384)
490490
# If no doc-comments are attached to function, Get-Help returns a single line
491491
# enumerating syntax.
492492
if ($helpText.Count -eq 1) {
493-
Handle-MissingValue "Cannot find Help for $function" | Out-Null
493+
[void](Handle-MissingValue "Cannot find Help for $function")
494494
# Shows a blank entry for this function on the module summary page.
495495
$helpHash[$function].Synopsis = ""
496496
}
@@ -499,8 +499,8 @@ function Generate-FunctionPages($moduleName, $moduleDocPath, $parentTitle, $help
499499

500500
$targetFile = join-path $moduleDocPath ($function+".html")
501501
$breadcrumbs = Get-HtmlBreadCrumbs `
502-
(Get-HtmlLink (Join-HtmlPath "..", "..", "index.html") $namespace),
503-
(Get-HtmlLink "index.html" $moduleName),
502+
(Get-HtmlLink (Join-HtmlPath "..", "..", $home_page_filename) $namespace),
503+
(Get-HtmlLink $home_page_filename $moduleName),
504504
$function
505505
Fill-Template $template $targetFile $PAGE_FUNCTION `
506506
-title $function `
@@ -512,7 +512,7 @@ function Generate-FunctionPages($moduleName, $moduleDocPath, $parentTitle, $help
512512
-moduleDetails $moduleDetails
513513
Add-ItemToContentsList $function $_.CommandType `
514514
-itemUrl (Join-HtmlPath $namespace, $moduleName, ($function+".html")) `
515-
-parentUrl (Join-HtmlPath $namespace, $moduleName, "index.html") `
515+
-parentUrl (Join-HtmlPath $namespace, $moduleName, $home_page_filename) `
516516
-parentName $moduleName
517517
}
518518
}
@@ -522,7 +522,7 @@ function Generate-ModulePage($namespace, $moduleName, $moduleDocPath, $parentTit
522522
$indexTableRows =
523523
Get-Command -Module $moduleName |
524524
Filter-ThisModule $moduleName |
525-
sort -Property Name |
525+
Sort -Property Name |
526526
% {
527527
if ($_.CommandType -in $CMDLET_TYPES) {
528528
Get-HtmlRow (Get-HtmlLink ($_.Name+".html") $_.Name), (HtmlEncode $helpHash[$_.Name].Synopsis)
@@ -535,10 +535,10 @@ function Generate-ModulePage($namespace, $moduleName, $moduleDocPath, $parentTit
535535
}
536536
}
537537

538-
$targetFile = join-path $moduleDocPath "index.html"
538+
$targetFile = join-path $moduleDocPath $home_page_filename
539539
$namespaceDir = Join-Path $moduleRoot $namespace
540540
$breadcrumbs = Get-HtmlBreadCrumbs `
541-
(Get-HtmlLink (Join-HtmlPath "..", "..", "index.html") $namespace),
541+
(Get-HtmlLink (Join-HtmlPath "..", "..", $home_page_filename) $namespace),
542542
$moduleName
543543
Fill-Template $template $targetFile $PAGE_MODULE `
544544
-title $moduleName `
@@ -550,14 +550,14 @@ function Generate-ModulePage($namespace, $moduleName, $moduleDocPath, $parentTit
550550
-revDate $RevisionDate `
551551
-moduleDetails $moduleDetails
552552
Add-ItemToContentsList $moduleName "module" `
553-
-itemUrl (Join-HtmlPath $namespace, $moduleName, "index.html") `
553+
-itemUrl (Join-HtmlPath $namespace, $moduleName, $home_page_filename) `
554554
-parentName $namespace `
555-
-parentUrl "index.html"
555+
-parentUrl $home_page_filename
556556
}
557557

558558
function Generate-HomePage($namespaceSummary, $path, $title)
559559
{
560-
Write-Host "Generating home page..."
560+
Write-Host 'Generating home page...'
561561
$body = $namespaceSummary.Keys | Sort | % {
562562
$namespace = $_
563563
$headLevel = 2
@@ -567,12 +567,12 @@ function Generate-HomePage($namespaceSummary, $path, $title)
567567
Get-HtmlTable (
568568
$moduleItems.Keys | Sort |
569569
%{
570-
Get-HtmlRow (Get-HtmlLink (Join-HtmlPath $namespace, $_, "index.html") $_),
570+
Get-HtmlRow (Get-HtmlLink (Join-HtmlPath $namespace, $_, $home_page_filename) $_),
571571
$moduleItems[$_]
572572
}
573573
)
574574
}
575-
$targetFile = join-path $TargetDir "index.html"
575+
$targetFile = join-path $TargetDir $home_page_filename
576576
Fill-Template $template $targetFile $PAGE_HOME `
577577
-title $title `
578578
-body $body `
@@ -582,7 +582,7 @@ function Generate-HomePage($namespaceSummary, $path, $title)
582582

583583
function Generate-ContentsPage($title)
584584
{
585-
Write-Host "Generating contents page..."
585+
Write-Host 'Generating contents page...'
586586
$body = $itemList |
587587
Group -Property { $_.itemName.Substring(0,1).ToUpper() } |
588588
Sort -Property Name |
@@ -601,7 +601,7 @@ function Generate-ContentsPage($title)
601601
}
602602
}
603603
}
604-
$targetFile = join-path $TargetDir "contents.html"
604+
$targetFile = join-path $TargetDir $contents_page_filename
605605
Fill-Template $template $targetFile $PAGE_CONTENTS `
606606
-title $title `
607607
-body $body `
@@ -719,7 +719,7 @@ function Get-OverviewContent([string]$overviewPath)
719719
}
720720
return $html.body.InnerXml
721721
}
722-
catch [Exception] {
722+
catch {
723723
[void](Handle-MissingValue $_.Exception.Message)
724724
}
725725
}
@@ -794,13 +794,13 @@ function Get-Sections($text)
794794
# The normal help text has section headers (NAME, SYNOPSIS, SYNTAX, DESCRIPTION, etc.)
795795
# at the start of a line and everything else indented.
796796
# Thus, this signals a new section:
797-
if ($_ -match "^[A-Z]") {
797+
if ($_ -match '^[A-Z]') {
798798
Add-HelpSection $sectionName $text ([ref]$sectionHash) ([ref]$sectionOrder)# output prior section
799799
$sectionName = $_
800800
$lowBound = $rowNum + 1
801801
}
802802
# Add separate section title for examples (which standard help lacks).
803-
elseif ($_ -match "----\s+EXAMPLE 1\s+----") {
803+
elseif ($_ -match '----\s+EXAMPLE 1\s+----') {
804804
Add-HelpSection $sectionName $text ([ref]$sectionHash) ([ref]$sectionOrder)# output prior section
805805
$sectionName = $EXAMPLES_SECTION
806806
$lowBound = $rowNum
@@ -871,7 +871,7 @@ function Add-Links($currentModuleName, $text)
871871
$GRANDPARENT_INDEX = -3
872872
$text -split "`n" | % {
873873
$item = $_.Trim() # default to "as is" entry
874-
if ($_ -match "^\s*(\w+-\w+)\s*$") { # cmdlet format: "verb-noun"
874+
if ($_ -match '^\s*(\w+-\w+)\s*$') { # cmdlet format: "verb-noun"
875875
$thisCmdName = $Matches[1]
876876
if ($msdnIndex[$thisCmdName]) {
877877
$item = Get-HtmlLink $msdnIndex[$thisCmdName] $thisCmdName # generate link to MSDN
@@ -886,23 +886,23 @@ function Add-Links($currentModuleName, $text)
886886
$thisNamespace = ($cmd.Module.Path -split '\\')[$GRANDPARENT_INDEX]
887887
if ($thisModName -eq $currentModuleName) { $path = $thisCmdName }
888888
else { $path = "..","..",$thisNamespace,$thisModName,$thisCmdName -join "/" }
889-
$item = Get-HtmlLink ("{0}.html" -f $path) $thisCmdName
889+
$item = Get-HtmlLink ('{0}.html' -f $path) $thisCmdName
890890
}
891891
else {
892892
[void](Handle-MissingValue "Related link '$thisCmdName' not loaded")
893893
$item = $thisCmdName
894894
}
895895
}
896896
}
897-
elseif ($_ -match "^\s*(about_[\w_]+)\s*$") { # topic format: "about_topic"
897+
elseif ($_ -match '^\s*(about_[\w_]+)\s*$') { # topic format: "about_topic"
898898
if ($msdnIndex[$Matches[1]]) {
899899
$item = Get-HtmlLink $msdnIndex[$Matches[1]] $Matches[1] # generate link to MSDN
900900
}
901901
}
902-
elseif ($_ -match "^\s*\[\s*([^]]+?)\s*\]\s*\(\s*([^)]+?)\s*\)\s*$") { # text link format: "[label] (URL)"
902+
elseif ($_ -match '^\s*\[\s*([^]]+?)\s*\]\s*\(\s*([^)]+?)\s*\)\s*$') { # text link format: "[label] (URL)"
903903
$item = Get-HtmlLink $Matches[2] $Matches[1] # generate link from URL and label provided
904904
}
905-
elseif ($_ -match "^\s*(https?:\S+)\s*$") { # URL format: "http:..." or "https:..."
905+
elseif ($_ -match '^\s*(https?:\S+)\s*$') { # URL format: "http:..." or "https:..."
906906
$item = Get-HtmlLink $Matches[1] $Matches[1] # generate link from URL provided
907907
}
908908
if ($item) { Get-HtmlListItem $item } # emit only if non-empty

Source/Initialize.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function Init-Variables()
2020

2121
$script:CMDLET_TYPES ='Function','Filter','Cmdlet'
2222

23+
$script:home_page_filename = "index.html"
24+
$script:contents_page_filename = "contents.html"
2325
$script:namespace_overview_filename = "namespace_overview.html"
2426
$script:module_overview_filename = "module_overview.html"
2527
$script:default_template = "$PSScriptRoot\..\Templates\psdoc_template.html"

0 commit comments

Comments
 (0)