-
Notifications
You must be signed in to change notification settings - Fork 389
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
Add Parameter to include/exclude certain files/folders when using -Path parameter set #561
Comments
Could the script analyzer simply look for a comment like #NoAnalyze ? Or it should be simple enough to detect Pester commands like Describe and ignore the file. |
cc @joeyaiello Right now, Invoke-ScriptAnalyzer by itself doesn't have such a capability. However, a workaround would be to filter out the *.tests.ps1 files and pipe the remaining files to Invoke-ScriptAnalyzer. For example Get-ChildItem -Path <targetPath> -Exclude "*.tests.ps1" | Invoke-ScriptAnalyzer Having said that, I think this would be a good feature to have in the settings file. |
And it isn't merely Pester tests. I often use a scratch.ps1 file as a temporary dumping ground or a place to hold snippets of code I'm working on. It is a bit of a nuisance to have that file constantly checked for rules. |
What about having a -ExcludeTestFiles parameter? Except with a better name. |
Why should your tests be held to lower standards than the rest of your code? |
because they are tests, what kind of question is that, why don't you write tests for tests? why should you have lower standards for test than the rest of your code? |
Good point @RobFaie, only issue is that some times Pester syntax can trigger false positives. |
I'm having the same problem, especially with the PowerShell Extension (but it's not a PS Extension problem). I'd like to exclude some folders and files, that might be present in my workspace, but I don't want them to be analyzed.
Although it should not be automatic, you can think of most things in .gitignore to fall into that category, but it's for the user to chose and configure per-repo. /cc @bergmeister as we discussed that on slack |
@gaelcolas For settings support, there is issue #1230 |
Yeah. The extension would need an exclusion list. Feel free to open an issue in https://github.com/PowerShell/vscode-powershell |
A downside of this workaround is that when combined with If (Get-ChildItem -Path <targetPath> -Exclude "*.tests.ps1") -join "," | Invoke-ScriptAnalyzer -EnableExit But I couldn't get that to work. |
The idea of this issue is excellent. I have a use-case where I have another module that is a dependency of the module I'm writing and which I'm including in "source form" as part of the build output of the module under test. (I wrote both modules--and currently, I have a "distribution challenge" which is causing me to include this dependent module in "source form" within the build output.) The issue is that the "dependent module" is independently built/linted/tested itself, so I don't want or need to repeat analysis on this essentially "external dependency" that just happens to be in my project output as part of the "build" process. So the ability to ignore/exclude paths qualified by the |
They said to open an issue here. |
PowerShell Extension contributor (and more accurately PSES for this issue) here, @TylerLeonhardt has moved on to much bigger and better things since he wrote that 5 years ago :) The extension's philosophy is to do things downstream if possible and effectively just be a "UI" as much as possible, so that all editors can benefit and not just ones that use the LSP. We do use In an ideal world (for us), includes/excludes could be defined as part of the We could also implement all of this logic in PSES via settings, but it seems to make more sense to implement it first in core ScriptAnalyzer so non-PSES users can benefit (e.g. Github Actions and whatnot). @bergmeister your thoughts? |
Is there a way to ignore any ps1 file that happens to be a Pester test script? It is not uncommon to having to break a few rules when constructing tests, especially when mocking.
The text was updated successfully, but these errors were encountered: