Skip to content

Commit 20e53ac

Browse files
authored
Merge pull request #34 from jfaurskov/codereview
Add linting and link testing
2 parents 2b853e7 + 8f906ad commit 20e53ac

15 files changed

Lines changed: 230 additions & 123 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
dirs:
3+
- ./
4+
#baseUrl: https://example.com
5+
# ignorePatterns:
6+
# - pattern: '^https://example.com/skip/.*$'
7+
# - pattern: "^(ftp)://[^\\s/$?#]*\\.[^\\s]*$"
8+
# replacementPatterns:
9+
# - pattern: "(https?://example.com)/(\\w+)/(\\d+)"
10+
# replacement: '$1/id/$3'
11+
# - pattern: "\\[([^\\]]+)\\]\\((https?://example.com)/file\\)"
12+
# replacement: '<a href="$2/file">$1</a>'
13+
aliveStatusCodes:
14+
- 200
15+
- 201
16+
- 204
17+
useGitIgnore: true
18+
modifiedFilesOnly: false

.github/linters/.markdown-lint.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
###########################
3+
###########################
4+
## Markdown Linter rules ##
5+
###########################
6+
###########################
7+
8+
# Linter rules doc:
9+
# - https://github.com/DavidAnson/markdownlint
10+
#
11+
# Note:
12+
# To comment out a single error:
13+
# <!-- markdownlint-disable -->
14+
# any violations you want
15+
# <!-- markdownlint-restore -->
16+
#
17+
18+
###############
19+
# Rules by id #
20+
###############
21+
MD004: false # Unordered list style
22+
MD007:
23+
indent: 2 # Unordered list indentation
24+
MD013:
25+
line_length: 900 # Line length 80 is far too short
26+
MD026:
27+
punctuation: ".,;:!。,;:" # List of not allowed
28+
MD029: false # Ordered list item prefix
29+
MD033: false # Allow inline HTML
30+
MD036: false # Emphasis used instead of a heading
31+
32+
#################
33+
# Rules by tags #
34+
#################
35+
blank_lines: false # Disable rules related to blank lines

.github/linters/.yaml-lint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
rules:
3+
line-length:
4+
max: 900
5+
allow-non-breakable-words: true
6+
allow-non-breakable-inline-mappings: false
7+
truthy: disable
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@{
2+
3+
# Disable specific rules by name
4+
ExcludeRules = @(
5+
'PSUseShouldProcessForStateChangingFunctions'
6+
)
7+
}

.github/workflows/code-review.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
name: Code Review - Linting & Link Checks
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
lint:
12+
name: Lint code base
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Run github/super-linter
22+
uses: super-linter/super-linter@v7.3.0
23+
env:
24+
# Lint all code - disabled in as part of #262
25+
VALIDATE_ALL_CODEBASE: false
26+
# Need to define main branch as default is set to master in super-linter
27+
DEFAULT_BRANCH: main
28+
# Enable setting the status of each individual linter run in the Checks section of a pull request
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
# The following linter types will be enabled:
31+
VALIDATE_JSON: true
32+
VALIDATE_MARKDOWN: true
33+
VALIDATE_POWERSHELL: true
34+
VALIDATE_YAML: true
35+
POWERSHELL_CONFIG_FILE: PSScriptAnalyzerSettings.psd1
36+
#VALIDATE_EDITORCONFIG: true
37+
# Disable errors to only generate a report
38+
#DISABLE_ERRORS: true
39+
40+
markdown-link-check:
41+
name: Markdown Link Check
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Run linkspector
51+
uses: umbrelladocs/action-linkspector@v1.3.4
52+
with:
53+
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
reporter: github-pr-review
55+
fail_on_error: true
56+
config_file: ".github/actions-config/.linkspector.yml"

1-Collect/Get-AzureServices.Tests.ps1

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
11
BeforeAll {
22
$scriptPath = "$PSScriptRoot\Get-AzureServices.ps1"
3+
$script:scriptContent = Get-Content $scriptPath -Raw
34
}
45

56
Describe "Get-AzureServices.ps1 Tests" {
67
Context "Parameter Validation" {
78
It "Should accept valid scopeType values" {
89
$validScopes = @('singleSubscription', 'resourceGroup', 'multiSubscription')
9-
10-
# Parse the script to check parameter validation
11-
$scriptContent = Get-Content $scriptPath -Raw
12-
$scriptContent | Should -Match 'ValidateSet.*singleSubscription.*resourceGroup.*multiSubscription'
10+
11+
# Verify each scope is present in the script's ValidateSet
12+
foreach ($scope in $validScopes) {
13+
$script:scriptContent | Should -Match $scope
14+
}
1315
}
1416

1517
It "Should have required parameters defined" {
1618
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($scriptPath, [ref]$null, [ref]$null)
1719
$params = $scriptAst.FindAll({$args[0] -is [System.Management.Automation.Language.ParameterAst]}, $true)
18-
1920
$paramNames = $params | ForEach-Object { $_.Name.VariablePath.UserPath }
2021
$paramNames | Should -Contain 'scopeType'
2122
$paramNames | Should -Contain 'fullOutputFile'
2223
$paramNames | Should -Contain 'summaryOutputFile'
2324
}
2425

2526
It "Should have default values for output files" {
26-
$scriptContent = Get-Content $scriptPath -Raw
27-
$scriptContent | Should -Match 'fullOutputFile.*=.*"resources.json"'
28-
$scriptContent | Should -Match 'summaryOutputFile.*=.*"summary.json"'
27+
$script:scriptContent | Should -Match 'fullOutputFile.*=.*"resources.json"'
28+
$script:scriptContent | Should -Match 'summaryOutputFile.*=.*"summary.json"'
2929
}
3030
}
3131

3232
Context "Function Definitions" {
3333
It "Should define Get-Property function" {
34-
$scriptContent = Get-Content $scriptPath -Raw
35-
$scriptContent | Should -Match 'Function Get-Property'
34+
$script:scriptContent | Should -Match 'Function Get-Property'
3635
}
3736

3837
It "Should define Get-SingleData function" {
39-
$scriptContent = Get-Content $scriptPath -Raw
40-
$scriptContent | Should -Match 'Function Get-SingleData'
38+
$script:scriptContent | Should -Match 'Function Get-SingleData'
4139
}
4240

4341
It "Should define Get-Method function" {
44-
$scriptContent = Get-Content $scriptPath -Raw
45-
$scriptContent | Should -Match 'Function Get-Method'
42+
$script:scriptContent | Should -Match 'Function Get-Method'
4643
}
4744
}
4845

1-Collect/Get-RessourcesFromAM.Tests.ps1

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
BeforeAll {
22
$scriptPath = "$PSScriptRoot\Get-RessourcesFromAM.ps1"
3+
$script:scriptContent = Get-Content $scriptPath -Raw
34
}
45

56
Describe "Get-RessourcesFromAM.ps1 Tests" {
67
Context "Parameter Validation" {
78
It "Should require filePath parameter" {
89
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($scriptPath, [ref]$null, [ref]$null)
9-
$params = $scriptAst.FindAll({$args[0] -is [System.Management.Automation.Language.ParameterAst]}, $true)
10-
10+
$params = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParameterAst] }, $true)
1111
$filePathParam = $params | Where-Object { $_.Name.VariablePath.UserPath -eq 'filePath' }
1212
$filePathParam | Should -Not -BeNullOrEmpty
13-
13+
1414
# Check if parameter is mandatory
15-
$isMandatory = $filePathParam.Attributes | Where-Object {
16-
$_.TypeName.Name -eq 'Parameter' -and
15+
$isMandatory = $filePathParam.Attributes | Where-Object {
16+
$_.TypeName.Name -eq 'Parameter' -and
1717
$_.NamedArguments.ArgumentName -contains 'Mandatory'
1818
}
1919
$isMandatory | Should -Not -BeNullOrEmpty
2020
}
21-
2221
It "Should have default output file" {
23-
$scriptContent = Get-Content $scriptPath -Raw
2422
$scriptContent | Should -Match 'outputFile.*=.*".*summary\.json"'
2523
}
2624
}
2725

2826
Context "Excel File Processing" {
2927
It "Should check for Excel file existence" {
3028
Mock Test-Path { return $false }
31-
29+
3230
# Test would validate file existence check
31+
3332
$true | Should -Be $true
3433
}
3534

@@ -44,31 +43,31 @@ Describe "Get-RessourcesFromAM.ps1 Tests" {
4443
It "Should convert Premium disk SKU correctly" {
4544
$testSku = "Premium SSD P30"
4645
$expected = "Premium_LRS"
47-
46+
4847
$result = switch -Wildcard ($testSku) {
49-
"PremiumV2*" { "PremiumV2_LRS"; break }
50-
"Premium*" { "Premium_LRS"; break }
51-
"StandardSSD*" { "StandardSSD_LRS"; break }
52-
"Standard*" { "Standard_LRS"; break }
53-
"Ultra*" { "UltraSSD_LRS"; break }
54-
default { "Unknown" }
48+
"PremiumV2*" { "PremiumV2_LRS"; break }
49+
"Premium*" { "Premium_LRS"; break }
50+
"StandardSSD*" { "StandardSSD_LRS"; break }
51+
"Standard*" { "Standard_LRS"; break }
52+
"Ultra*" { "UltraSSD_LRS"; break }
53+
default { "Unknown" }
5554
}
56-
55+
5756
$result | Should -Be $expected
5857
}
5958

6059
It "Should convert StandardSSD disk SKU correctly" {
6160
$testSku = "StandardSSD E10"
62-
61+
6362
$result = switch -Wildcard ($testSku) {
64-
"PremiumV2*" { "PremiumV2_LRS"; break }
65-
"Premium*" { "Premium_LRS"; break }
66-
"StandardSSD*" { "StandardSSD_LRS"; break }
67-
"Standard*" { "Standard_LRS"; break }
68-
"Ultra*" { "UltraSSD_LRS"; break }
69-
default { "Unknown" }
63+
"PremiumV2*" { "PremiumV2_LRS"; break }
64+
"Premium*" { "Premium_LRS"; break }
65+
"StandardSSD*" { "StandardSSD_LRS"; break }
66+
"Standard*" { "Standard_LRS"; break }
67+
"Ultra*" { "UltraSSD_LRS"; break }
68+
default { "Unknown" }
7069
}
71-
70+
7271
$result | Should -Be "StandardSSD_LRS"
7372
}
7473
}

2-AvailabilityCheck/Get-AvailabilityInformation.Tests.ps1

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,41 @@
11
BeforeAll {
22
$scriptPath = "$PSScriptRoot\Get-AvailabilityInformation.ps1"
3+
$script:scriptContent = Get-Content $scriptPath -Raw
34
}
45

56
Describe "Get-AvailabilityInformation.ps1 Tests" {
67
Context "Function Definitions" {
78
It "Should define Out-JSONFile function" {
8-
$scriptContent = Get-Content $scriptPath -Raw
99
$scriptContent | Should -Match 'function Out-JSONFile'
1010
}
1111

1212
It "Should define Convert-LocationsToRegionCodes function" {
13-
$scriptContent = Get-Content $scriptPath -Raw
14-
$scriptContent | Should -Match 'Function Convert-LocationsToRegionCodes'
13+
$scriptContent | Should -Match 'Function Convert-LocationsToRegionCode'
1514
}
1615

1716
It "Should define Import-Provider function" {
18-
$scriptContent = Get-Content $scriptPath -Raw
1917
$scriptContent | Should -Match 'Function Import-Provider'
2018
}
2119

2220
It "Should define Import-Region function" {
23-
$scriptContent = Get-Content $scriptPath -Raw
2421
$scriptContent | Should -Match 'function Import-Region'
2522
}
2623

2724
It "Should define Get-Property function" {
28-
$scriptContent = Get-Content $scriptPath -Raw
2925
$scriptContent | Should -Match 'Function Get-Property'
3026
}
3127

3228
It "Should define Expand-NestedCollection function" {
33-
$scriptContent = Get-Content $scriptPath -Raw
3429
$scriptContent | Should -Match 'Function Expand-NestedCollection'
3530
}
3631
}
3732

3833
Context "Logic Validation" {
3934
It "Should have region map creation logic" {
40-
$scriptContent = Get-Content $scriptPath -Raw
4135
$scriptContent | Should -Match 'RegionMap'
4236
}
4337

4438
It "Should have SKU availability checking logic" {
45-
$scriptContent = Get-Content $scriptPath -Raw
4639
$scriptContent | Should -Match 'available'
4740
}
4841
}

0 commit comments

Comments
 (0)