Vscode-powershell: Set the powerShell.scriptAnalysis.settingsFilePath setting to a default for auto-discoverability

Created on 19 Sep 2019  路  9Comments  路  Source: PowerShell/vscode-powershell

Summary of the new feature

Most linter tools automatically pick up the config file from the root of your workspace. We should do the same.

I'd like to set the default value for powerShell.scriptAnalysis.settingsFilePath to PSScriptAnalyzerSettings.psd1 which means that if there is a PSScriptAnalyzerSettings.psd1 in the root of the workspace, we will automatically use it.

If a user doesn't want this, they can opt out via:

"powerShell.scriptAnalysis.settingsFilePath":""

but PSSA integration is one of our flagship features so we should streamline the experience.

Also, the user can still set it to something else if they so choose.

Proposed technical implementation details (optional)

Setting the default value for powerShell.scriptAnalysis.settingsFilePath to PSScriptAnalyzerSettings.psd1. Making sure our code is resilient if the file doesn't exist.

I need to hear what @bergmeister has to say about this. Among anyone else :)

Area-Script Analysis Issue-Enhancement

Most helpful comment

@bgelens your issue was fixed in https://github.com/PowerShell/PowerShellEditorServices/pull/1161 - a fix I made a few days after the last release... so it's pending a release. Sorry about that. [System.Uri] is a nightmare in a cross-plat world lol

All 9 comments

This also aligns with Invoke-ScriptAnalyzer's behaviour, which is to search for the same file in a project root by default.

Good idea, never thought of it but totally makes sense. You already said that we'll have to check for existence of the file first, I don't anticipate any issues with the rest.

What would be nice as well is to tell the user if there was an error because starting with PSSA 1.18.3 error messages due to invalid syntax in the setting files are actually useful/actionable.

I've looked into trying to auto-discover the default PSSA settings file a few weeks ago but the straightforward implementation somehow did not work end to end as I expected so it seems to be more complex than I originally thought it would be, therefore I've parked it for the moment

It might be worth waiting for https://github.com/PowerShell/PowerShellEditorServices/pull/1078 as that's deleting a _ton_ of code.

I have an issue with relative path with version 2020.1.0 preview extension on mac with PSv7rc2

I can only use the full path. Relative won't work. I tried both ./PSScriptAnalyzerSettings.psd1 and PSScriptAnalyzerSettings.psd1. The file is in the root of the folder I opened.

From pses output:

[Error - 8:20:05 PM] Cannot find the path '/Users/bengelens/OneDrive/Documenten/Projecten/demo/file:/Users/bengelens/OneDrive/Documenten/Projecten/demo/PSScriptAnalyzerSettings.psd1'.

Note file: in the middle

When specifying the full path, it works correctly.

@bgelens Your scenario should definitely work (at least I know that it does on Windows). I vaguely remember there was a temporary issue with it at the end of the year 2019 but that should've been fixed now. Is it working for you at least with the 'stable' extension or a previous version of the preview extension? Also, can you try to do this on a normal folder and not OneDrive, maybe that's the cullprit.

@bergmeister

Normal folder preview extension:

 Cannot find the path '/Users/bengelens/Desktop/demo/file:/Users/bengelens/Desktop/demo/PSScriptAnalyzerSettings.psd1'.

When switching to the stable extension, it works fine. So the issue is with preview only

@bgelens your issue was fixed in https://github.com/PowerShell/PowerShellEditorServices/pull/1161 - a fix I made a few days after the last release... so it's pending a release. Sorry about that. [System.Uri] is a nightmare in a cross-plat world lol

Was this page helpful?
0 / 5 - 0 ratings