Skip to content

PSScriptAnalyzer not running when no settings file present #2489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rjmholt opened this issue Feb 24, 2020 · 11 comments · Fixed by PowerShell/PowerShellEditorServices#1206
Closed
Labels
Milestone

Comments

@rjmholt
Copy link
Contributor

rjmholt commented Feb 24, 2020

From #2484.

Currently under investigation

@rjmholt rjmholt added this to the 2.0.0 milestone Feb 24, 2020
@rjmholt
Copy link
Contributor Author

rjmholt commented Feb 24, 2020

Looking into this, I've tried to reproduce the issue but I get the default experience.

In the logs I have the following entry:

2020-02-24 11:35:05.143 -08:00 [INF] PSScriptAnalyzer settings file not found. Falling back to default rules

@bergmeister would you be able to provide more information about the repro steps for this issue?

@bergmeister
Copy link
Contributor

bergmeister commented Feb 24, 2020

@rjmholt I tried to clean everything: did a 'git clean -dfx' on the the vs-code and PSES repo and made sure I had the latest changes on master. Using pwsh 7-rc2 (waiting for chocolatey to update to rc3...). Usually I also use the latest master version of pssa, I deleted that one and now use the out of box version of pssa as well. However, PSSA still does not work. OS is Windows 1909. Building using RTM version of code. NPM version is 6.3.14. I just build it the usual way by doing an invoke-build build in pses and then press F5 in the vscode repo and do something like typing gci to see a PSSA warning on it, either in a file or an unsaved in-memory file and I don't see any PSSA warnings or squiggles..
Let me try supply some logs

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Feb 24, 2020
@rjmholt
Copy link
Contributor Author

rjmholt commented Feb 24, 2020

Let me try supply some logs

Yeah I'm hoping some info will be in there. Rewriting the analysis service I added extra logging, so we should know what's going on there

@bergmeister
Copy link
Contributor

bergmeister commented Feb 24, 2020

EditorServices.log
StartEditorServices.log
vscode-powershell.log

In there is see (I set the choco git repo as an example root folder because it does not have a settings file):

2020-02-24 22:44:26.519 +00:00 [ERR] Cannot find the path 'c:\Users\christoph.bergmeiste\git\choco\PSScriptAnalyzerSettings.psd1'.

Tomorrow, I can also try on a 2nd machine or would it be more useful if I give you my local build? Here is the vsix (which I just renamed to .zip so that Github allows me to upload it)
PowerShell-insiders.zip

@rjmholt
Copy link
Contributor Author

rjmholt commented Feb 24, 2020

Interesting. This also contains the line:

2020-02-24 22:44:22.265 +00:00 [INF] Configuring PSScriptAnalyzer with rules at 'c:\Users\christoph.bergmeiste\git\choco\PSScriptAnalyzerSettings.psd1

@bergmeister
Copy link
Contributor

The repo in question is a 6 month old version of https://github.com/chocolatey/choco
But I tried different folders, so it is not a problem specific to this repo and as I said I tried both physical files or in-memory files. Could it be because you guys run your dev env mostly on Unix systems and not Windows?

@rjmholt
Copy link
Contributor Author

rjmholt commented Feb 24, 2020

Is it possible you're starting PSES with a settings file present on the file system, but later removing it?

@bergmeister
Copy link
Contributor

bergmeister commented Feb 24, 2020

I don't think so, I've even tried to re-open a new folder. Since I know how to build PSES, etc myself, I'll have a look at the new code that you guys recently added (which looks exciting and amazing overall btw) and attach the debugger

@rjmholt
Copy link
Contributor Author

rjmholt commented Feb 25, 2020

Could it be because you guys run your dev env mostly on Unix systems and not Windows?

I'm almost always on Windows, both in the office and at home. My daily driver in the office is Windows 10.0.19535 (right now, I'm sure I'll get another update in the week).

I'm still not quite sure what's going on here, but if you're able to debug it you might be able to find the source of that error log (it's not one of our messages). If it's coming from a caught error, it might be somewhere where we need to include a stack trace and don't currently.

@bergmeister
Copy link
Contributor

Ok.
The situation in the debugger is quite clear, especially when reading the code as well: Due to the default setting being PSScriptAnalyzerSettings.psd1, the used setting path in the TryFindSettingsFile method already has the value of combining the workspace root with PSScriptAnalyzerSettings.psd1
https://github.com/PowerShell/PowerShellEditorServices/blob/c99aae37481462b3423e77852e832a9bcae96051/src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs#L287
A few lines later, the ResolveWorkspacePath only resolves the path without checking for its existence and therefore makes PSES use a file that does not exist.
Even looking at earlier stages where settings are being set in the internal ScriptAnalysisSettings class, there is no checking against whether the path actually exists and it just sets it if it resolves to a valid path
https://github.com/PowerShell/PowerShellEditorServices/blob/65bcbb17653d2e2c33bde1f0c14e9a5eff3e7c72/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs#L103

Therefore, it escapes me how it works on your environements, you must have either a user or workspace setting defined. Let me know if that info helps, happy to do a screen share session as well in case you still cannot repro.

@rjmholt
Copy link
Contributor Author

rjmholt commented Feb 25, 2020

I agree with that analysis; thanks for looking into that.

Therefore, it escapes me how it works on your environements, you must have either a user or workspace setting defined.

Yeah I'm not sure either. Very explicitly cleared my settings.

Testing out a fix now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants