Skip to content

Commit c774534

Browse files
🚀[Feature]: Use local PSScriptAnalyzer files (#228)
The workflow now uses [Invoke-ScriptAnalyzer@v4](https://github.com/PSModule/Invoke-ScriptAnalyzer), enabling automatic discovery of local PSScriptAnalyzer configuration files. This allows projects to maintain custom linting rules in their repository without requiring centralized settings management. The upgrade also streamlines workflow configuration by removing deprecated parameters and improving checkout efficiency. ## Updated to PSScriptAnalyzer v4 Upgraded the `PSModule/Invoke-ScriptAnalyzer` action from v3 to v4 in linting workflows (`Lint-SourceCode.yml` and `Test-Module.yml`). This version automatically discovers and uses local `.powershell-psscriptanalyzer.psd1` configuration files from the `.github/linters/` directory, providing better support for repository-specific linting rules. ## Removed Deprecated Settings Parameter The `Settings` parameter has been removed from both `Lint-SourceCode` and `Lint-Module` workflow steps. PSScriptAnalyzer now automatically discovers local configuration files, eliminating the need to explicitly specify settings profiles. ## Workflow Configuration Improvements - Added a `Checkout repository` step to the `Lint-Module` job to ensure the codebase (including local configuration files) is available before linting - Removed `fetch-depth: 0` from checkout steps to use shallow clones, reducing workflow execution time - Removed unused `Name` parameter from test workflow ## Custom Linting Configuration Support Added a `.powershell-psscriptanalyzer.psd1` configuration file in the test repository (`tests/srcWithManifestTestRepo/.github/linters/`) demonstrating how projects can define custom code style rules, including formatting preferences, line length limits, and rule exclusions.
1 parent 6090b7e commit c774534

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

.github/workflows/Lint-SourceCode.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,15 @@ jobs:
5353
uses: actions/checkout@v5
5454
with:
5555
persist-credentials: false
56-
fetch-depth: 0
5756

5857
- name: Lint-SourceCode
59-
uses: PSModule/Invoke-ScriptAnalyzer@v3
58+
uses: PSModule/Invoke-ScriptAnalyzer@v4
6059
with:
6160
Debug: ${{ inputs.Debug }}
6261
Prerelease: ${{ inputs.Prerelease }}
6362
Verbose: ${{ inputs.Verbose }}
6463
Version: ${{ inputs.Version }}
6564
Path: src
66-
Settings: SourceCode
6765
WorkingDirectory: ${{ inputs.WorkingDirectory }}
6866
TestResult_Enabled: true
6967
TestResult_TestSuiteName: PSModuleLint-SourceCode-${{ runner.os }}

.github/workflows/Test-Module.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ jobs:
8484
uses: actions/checkout@v5
8585
with:
8686
persist-credentials: false
87-
fetch-depth: 0
8887

8988
- name: Download module artifact
9089
uses: actions/download-artifact@v5
@@ -107,21 +106,25 @@ jobs:
107106
name: Lint-Module (${{ inputs.RunsOn }})
108107
runs-on: ${{ inputs.RunsOn }}
109108
steps:
109+
- name: Checkout repository
110+
uses: actions/checkout@v5
111+
with:
112+
persist-credentials: false
113+
110114
- name: Download module artifact
111115
uses: actions/download-artifact@v5
112116
with:
113117
name: module
114118
path: ${{ inputs.WorkingDirectory }}/outputs/module
115119

116120
- name: Lint-Module
117-
uses: PSModule/Invoke-ScriptAnalyzer@v3
121+
uses: PSModule/Invoke-ScriptAnalyzer@v4
118122
with:
119123
Path: outputs/module
120124
Debug: ${{ inputs.Debug }}
121125
Prerelease: ${{ inputs.Prerelease }}
122126
Verbose: ${{ inputs.Verbose }}
123127
Version: ${{ inputs.Version }}
124128
WorkingDirectory: ${{ inputs.WorkingDirectory }}
125-
Settings: Module
126129
TestResult_Enabled: true
127130
TestResult_TestSuiteName: PSModuleLint-Module-${{ runner.os }}

.github/workflows/Workflow-Test-WithManifest.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ jobs:
2525
secrets: inherit
2626
with:
2727
WorkingDirectory: tests/srcWithManifestTestRepo
28-
Name: PSModuleTest2
2928
SettingsPath: .github/PSModule.yml
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@{
2+
Rules = @{
3+
PSAlignAssignmentStatement = @{
4+
Enable = $true
5+
CheckHashtable = $true
6+
}
7+
PSAvoidLongLines = @{
8+
Enable = $true
9+
MaximumLineLength = 150
10+
}
11+
PSAvoidSemicolonsAsLineTerminators = @{
12+
Enable = $true
13+
}
14+
PSPlaceCloseBrace = @{
15+
Enable = $true
16+
NewLineAfter = $false
17+
IgnoreOneLineBlock = $true
18+
NoEmptyLineBefore = $false
19+
}
20+
PSPlaceOpenBrace = @{
21+
Enable = $true
22+
OnSameLine = $true
23+
NewLineAfter = $true
24+
IgnoreOneLineBlock = $true
25+
}
26+
PSProvideCommentHelp = @{
27+
Enable = $true
28+
ExportedOnly = $false
29+
BlockComment = $true
30+
VSCodeSnippetCorrection = $false
31+
Placement = 'begin'
32+
}
33+
PSUseConsistentIndentation = @{
34+
Enable = $true
35+
IndentationSize = 4
36+
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
37+
Kind = 'space'
38+
}
39+
PSUseConsistentWhitespace = @{
40+
Enable = $true
41+
CheckInnerBrace = $true
42+
CheckOpenBrace = $true
43+
CheckOpenParen = $true
44+
CheckOperator = $true
45+
CheckPipe = $true
46+
CheckPipeForRedundantWhitespace = $true
47+
CheckSeparator = $true
48+
CheckParameter = $true
49+
IgnoreAssignmentOperatorInsideHashTable = $true
50+
}
51+
}
52+
ExcludeRules = @(
53+
'PSMissingModuleManifestField', # This rule is not applicable until the module is built.
54+
'PSUseToExportFieldsInManifest'
55+
)
56+
}

0 commit comments

Comments
 (0)