Skip to content

Commit a798b2e

Browse files
committed
Finishing up fix PowerShell#122
Use empty string now to get the default (built-in) settings for script analysis. Tweaked the build script to fix some problems and to exclude the script analysis settings file. Also changed encoding the SampleModule.psd1 file to UTF8.
1 parent 2bba53c commit a798b2e

File tree

7 files changed

+20
-43
lines changed

7 files changed

+20
-43
lines changed

.vscode/tasks.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// we run the custom script "compile" as defined in package.json
3232
"args": ["run", "compile"],
3333

34-
// use the standard tsc problem matcher to find compile problems in the output.
34+
// use the standard tsc problem matcher to find compile problems in the output.
3535
"problemMatcher": "$tsc"
3636
},
3737
{
@@ -47,7 +47,7 @@
4747
// The tsc compiler is started in watching mode
4848
"isWatching": true,
4949

50-
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
50+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
5151
"problemMatcher": "$tsc-watch"
5252
}
5353
]

examples/.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
// Use a custom PowerShell Script Analyzer settings file for this workspace.
3+
// Relative paths for this setting are always relative to the workspace root dir.
4+
"powershell.scriptAnalysis.settingsPath": "./PSScriptAnalyzerSettings.psd1"
5+
}

examples/Build.ps1

+11-8
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,30 @@
6565
###############################################################################
6666
Properties {
6767
# The name of your module should match the basename of the PSD1 file.
68-
$ModuleName = (Get-Item $PSScriptRoot\*.psd1)[0].BaseName
68+
$ModuleName = (Get-Item $PSScriptRoot\*.psd1 |
69+
Foreach-Object {$null = Test-ModuleManifest -Path $_ -ErrorAction SilentlyContinue; if ($?) {$_}})[0].BaseName
6970

7071
# Path to the release notes file. Set to $null if the release notes reside in the manifest file.
7172
$ReleaseNotesPath = "$PSScriptRoot\ReleaseNotes.md"
7273

7374
# The directory used to publish the module from. If you are using Git, the
74-
# $PublishDir should be ignored if it is under the workspace directory.
75-
$PublishDir = "$PSScriptRoot\Release\$ModuleName"
75+
# $PublishRootDir should be ignored if it is under the workspace directory.
76+
$PublishRootDir = "$PSScriptRoot\Release"
77+
$PublishDir = "$PublishRootDir\$ModuleName"
7678

7779
# The following items will not be copied to the $PublishDir.
7880
# Add items that should not be published with the module.
7981
$Exclude = @(
82+
(Split-Path $PSCommandPath -Leaf),
8083
'Release',
8184
'Tests',
8285
'.git*',
8386
'.vscode',
84-
# The next three files are unique to this examples dir.
87+
# These files are unique to this examples dir.
8588
'DebugTest.ps1',
86-
'Stop*.ps1',
89+
'PSScriptAnalyzerSettings.psd1',
8790
'Readme.md',
88-
(Split-Path $PSCommandPath -Leaf)
91+
'Stop*.ps1'
8992
)
9093

9194
# Name of the repository you wish to publish to. Default repo is the PSGallery.
@@ -170,8 +173,8 @@ Task Clean -depends Init -requiredVariables PublishDir {
170173
# Sanity check the dir we are about to "clean". If $PublishDir were to
171174
# inadvertently get set to $null, the Remove-Item commmand removes the
172175
# contents of \*. That's a bad day. Ask me how I know? :-(
173-
if ($PublishDir.Contains($PSScriptRoot)) {
174-
Remove-Item $PublishDir\* -Recurse -Force
176+
if ($PublishRootDir.Contains($PSScriptRoot)) {
177+
Remove-Item $PublishRootDir\* -Recurse -Force
175178
}
176179
}
177180

examples/SampleModule.psd1

-3.87 KB
Binary file not shown.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@
247247
},
248248
"powershell.scriptAnalysis.settingsPath": {
249249
"type": "string",
250-
"default": "./PSScriptAnalyzerSettings.psd1",
251-
"description": "Specifies the path to the PowerShell Script Analyzer settings file. The settings file can be used to customize which rules to include or exclude as well as what severity levels to report."
250+
"default": "",
251+
"description": "Specifies the path to a PowerShell Script Analyzer settings file. Use either an absolute path (to override the default settings for all projects) or use a path relative to your workspace."
252252
},
253253
"powershell.developer.editorServicesHostPath": {
254254
"type": "string",

src/main.ts

-31
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ export function activate(context: vscode.ExtensionContext): void {
8686

8787
try
8888
{
89-
settings.scriptAnalysis.settingsPath = resolveScriptAnalysisSettingsPath(settings);
90-
9189
let serverPath = resolveLanguageServerPath(settings);
9290
let serverOptions = {
9391
run: {
@@ -180,35 +178,6 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings): string
180178
return editorServicesHostPath;
181179
}
182180

183-
function resolveScriptAnalysisSettingsPath(settings: settingsManager.ISettings): string {
184-
var scriptAnalysisSettingsPath = settings.scriptAnalysis.settingsPath;
185-
186-
if (scriptAnalysisSettingsPath) {
187-
console.log("Found scriptAnalysis.settingsPath from config: " + scriptAnalysisSettingsPath);
188-
189-
// Make the path absolute if it's not
190-
scriptAnalysisSettingsPath =
191-
path.resolve(
192-
__dirname,
193-
'..',
194-
scriptAnalysisSettingsPath);
195-
196-
console.log(" Resolved path to: " + scriptAnalysisSettingsPath);
197-
}
198-
else {
199-
// Use the default path in the extension's 'root' folder
200-
scriptAnalysisSettingsPath =
201-
path.join(
202-
__dirname,
203-
'..',
204-
'PSScriptAnalyzerSettings.psd1');
205-
206-
console.log("Using default scriptAnalysis.settingsPath: " + scriptAnalysisSettingsPath);
207-
}
208-
209-
return scriptAnalysisSettingsPath;
210-
}
211-
212181
function getHostExeName(useX86Host: boolean): string {
213182
// The useX86Host setting is only relevant on 64-bit OS
214183
var is64BitOS = process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');

0 commit comments

Comments
 (0)