GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add Parameter to include/exclude certain files/folders when using -Path parameter set · Issue #561 · PowerShell/PSScriptAnalyzer

Add Parameter to include/exclude certain files/folders when using -Path parameter set #561

New issue
Copy link
New issue
Copy link
Open
Open
Add Parameter to include/exclude certain files/folders when using -Path parameter set#561
Copy link
Labels
Issue - Discussion

Description

@jdhitsolutions
Jeff Hicks (jdhitsolutions)
opened on Jun 8, 2016
Issue body actions

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.

Reacted by Giovanni Bassi, mikaello, xtqqczze, John Vandenberg, Gabriel Majeri, Brian Scholer, Kenichi Kamiya, Alex Angas, Kolja Salewski, Martin Zarate and 2 more

Activity

  1. Kapil Borle (kapilmb)
    added
    Issue - Discussion
    on Jun 8, 2016
  2. jdhitsolutions commented on Jun 8, 2016

    @jdhitsolutions
    Jeff Hicks (jdhitsolutions)
    on Jun 8, 2016
    Author
    More actions

    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.

  3. kapilmb commented on Jun 8, 2016

    @kapilmb
    Kapil Borle (kapilmb)
    on Jun 8, 2016
    More actions

    cc Joey Aiello (@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.

    Reacted by Jake Morrison, Brian Scholer and Lukas Neubert
  4. jdhitsolutions commented on Jun 8, 2016

    @jdhitsolutions
    Jeff Hicks (jdhitsolutions)
    on Jun 8, 2016
    Author
    More actions

    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.

  5. kjacobsen commented on Aug 7, 2016

    @kjacobsen
    Kieran Jacobsen (kjacobsen)
    on Aug 7, 2016
    Contributor
    More actions

    What about having a -ExcludeTestFiles parameter?

    Except with a better name.

  6. RobFaie commented on Aug 16, 2016

    @RobFaie
    Robert McLeod (RobFaie)
    on Aug 16, 2016
    More actions

    Why should your tests be held to lower standards than the rest of your code?

    Reacted by Nicholas M. Getchell, Christoph Bergmeister, Daniel Kühl, Aliaksei, Mario Panighetti, lovetheguitar and Taylor Buchanan
    Reacted by Gleb Boushev, Peter Vandivier, John Vandenberg, Craig E. Shea, Jacob Romano, Patrick Evans, Martin Zarate, Shobhit Vaish and RiverHeart
  7. 4c74356b41 commented on May 3, 2017

    @4c74356b41
    Gleb Boushev (4c74356b41)
    on May 3, 2017
    More actions

    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?

    Reacted by John Vandenberg
  8. kjacobsen commented on May 7, 2017

    @kjacobsen
    Kieran Jacobsen (kjacobsen)
    on May 7, 2017
    Contributor
    More actions

    Good point Robert McLeod (@RobFaie), only issue is that some times Pester syntax can trigger false positives.

    Reacted by Daniel Brennand
  9. gaelcolas commented on Nov 8, 2019

    @gaelcolas
    gaelcolas (gaelcolas)
    on Nov 8, 2019
    More actions

    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.

    "As a vscode extension user, I need a way in the Analyzer Settings file to exclude some folders, such as my "output/RequiredModules" folder, my "tests" folder as requested by Jeff Hicks (@jdhitsolutions) or anything that might be present in my folder without being part of the source of the current project".

    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 Christoph Bergmeister (@bergmeister) as we discussed that on slack
    Please rename this issue as it's not just pester tests but exclude any file and folder in PSSA config.
    I know the vscode extension may be using -ScriptDefinition and not -Script, but having an exclude in settings would open the door to the same behaviour within and outside the vscode PowerShell extension.

    Reacted by Paul Shamus, Johan Ljunggren, Chris Gardner and Stéphane
  10. bergmeister commented on Nov 8, 2019

    @bergmeister
    Christoph Bergmeister (bergmeister)
    on Nov 8, 2019
    Collaborator
    More actions

    gaelcolas (@gaelcolas) For settings support, there is issue #1230
    The way the extension works, I'd still say it is something to be implemented in the extension for your use case. Because people edit their code without always saving the file, the extension needs to use the -ScriptDefinition parameter set to analyse the current in memory text. Do you agree TylerLeonhardt ?
    This and the other issue is for cmdlet/setting files options, which is a different use case.

  11. Christoph Bergmeister (bergmeister)
    changed the title [-]Ignore Pester Tests[/-] [+]Add Parameter to include/exclude certain files/folders when using -Path parameter set[/+] on Nov 8, 2019
  12. TylerLeonhardt commented on Nov 10, 2019

    @TylerLeonhardt
    TylerLeonhardt
    on Nov 10, 2019
    Member
    More actions

    Yeah. The extension would need an exclusion list. Feel free to open an issue in https://github.com/PowerShell/vscode-powershell

  13. mikaello commented on Nov 21, 2022

    @mikaello
    mikaello
    on Nov 21, 2022
    More actions

    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

    A downside of this workaround is that when combined with -EnableExit, only the exit code of the last file is considered (i.e., if the 10 first files have violations, and the last file analysed have none, the final exit code will be 0), this makes it impossible to use in a CI/CD context.

    If Invoke-ScriptAnalyzer would support a comma separated list of files as input, a workaround for this problem could have been:

    (Get-ChildItem -Path <targetPath> -Exclude "*.tests.ps1") -join "," | Invoke-ScriptAnalyzer -EnableExit

    But I couldn't get that to work.

    Reacted by Gabriel Majeri, Craig E. Shea, Brian Scholer, Alex Angas and Dan Aprahamian
    Reacted by John Vandenberg and Brian Scholer
  14. fourpastmidnight commented on Aug 28, 2023

    @fourpastmidnight
    Craig E. Shea (fourpastmidnight)
    on Aug 28, 2023
    More actions

    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 -Path parameter value would be fantastic. It would save time, and, let's say I was including a true external module dependency in source form in my output folder--I don't own that source, and so I wouldn't want my lint report to contain errors/warnings for something I don't own. This is even more important when the PSScriptAnalyzer settings are "treat warnings as errors".

    Reacted by Brian Scholer and Martin Zarate
  15. Kenichi Kamiya (kachick)
    added a commit that references this issue on Mar 2, 2024

    Extract tool dirs

    d79a03b
  16. Pxtl commented on Nov 1, 2024

    @Pxtl
    Martin Zarate (Pxtl)
    on Nov 1, 2024
    More actions

    Yeah. The extension would need an exclusion list. Feel free to open an issue in https://github.com/PowerShell/vscode-powershell

    They said to open an issue here.

    PowerShell/vscode-powershell#3048 (comment)

  17. JustinGrote commented on Nov 1, 2024

    @JustinGrote
    Justin Grote (JustinGrote)
    on Nov 1, 2024
    More actions

    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 ScriptDefinition to do static analysis in-flight for unsaved editors today, but we also know the original path of the file.

    In an ideal world (for us), includes/excludes could be defined as part of the -Settings parameter (either supplied directly or via .psd1) and merged with whatever is specified in -Path (with excludes taking precedence), and then there would be either a -DryRun, a .NET method on the analysis engine, or something that would list what files would be analyzed quickly without performing an actual analysis yet. If we had that, then we could build logic around that to only analyze files that show up in the dry-run list. This way our logic of what constitutes an include/exclude does not conflict with whatever engine is used to determine that inside ScriptAnalyzer

    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).

    Christoph Bergmeister (@bergmeister) your thoughts?
    CC Andy Jordan (@andyleejordan) for thoughts/ideas as well

    Reacted by Andy Jordan and Refael Ackermann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - Discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.