Skip to content
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

Settings file needs to have a exclude / ignore mechanism #1230

Open
jhoneill opened this issue May 1, 2019 · 5 comments
Open

Settings file needs to have a exclude / ignore mechanism #1230

jhoneill opened this issue May 1, 2019 · 5 comments

Comments

@jhoneill
Copy link

jhoneill commented May 1, 2019

**There needs to be an "exclude" option e.g. "exclude .tests.ps1" **

I have a module with ~ 200 pester tests attached. In VSCode if I attach a settings file the analyzer reports each pester command in each file is not found, by default, in each of the profiles where pester is not present. This reports so many false positives it is impossible to see the things which should be fixed. (VS code just says "> 1000 problems" and stops counting!)

Proposed technical implementation details (optional)

An option in the settings file (and perhaps on the command line) which said "exclude files which match this regular expression" would allow a subfolder, or certain names to be ignored. This is preferable to scanning those files, and trying to figure out which messages to hide, or having a mechanism for saying "Tell me if I'm using a module which isn't in V6 ... except don't tell me about Pester ... unless I've used it outside this folder" .

What is the latest version of PSScriptAnalyzer at the point of writing
1.18.0

@msftrncs
Copy link

msftrncs commented May 7, 2019

I think you need to see the section titled, Suppressing Rules. I think it would accomplish what you are looking for.

@jhoneill
Copy link
Author

jhoneill commented May 7, 2019

@msftrncs , I'm well aware of how to surpress a rule , going to a folder with many files and many subfolders and pasting lines for each every impacted rule into every file is the only way this works at the moment. But this is a very long way from optimal, and the issue was opened at the request of @JamesWTruher after we discussed how this could be done at the PowerShell Summit last week. There are multiple ways it might be done, but after our discussion we thought the one above was probably better than finding many issues and supressing the message.
A reg-ex is better than no-recurse switch because (for example) it would allow examples intended for quick command lines to be named in a way which allowed them to be excluded. Telling the analyzer not to scan files is also better than saying "OK you've reported 10 trailing white space messages in this file, don't report any more" - because as @JamesWTruher pointed out to me, having it find issues and decide not to report them is heading down a bad path.

@jayvdb
Copy link

jayvdb commented Jun 21, 2019

The current approach also doesnt work when copying files from another source into a repository -- I do not want to be changing those files; not to fix the lint, nor to decorate the lint. They are not my files - I want exact copies only - I sync them periodically.

I want the linter to exclude specific files I nominate. Almost every other linter implements this feature very early on.

@wekempf
Copy link

wekempf commented Apr 8, 2022

I'll go a step further. I'd like to control what rules are run, rather than just flat out suppressing. I'd propose something more like this.

@{
   FileRules = @{
      "*.tests.ps1" = @{ Exclude = @("*") }
      "build.ps1" = @{ Exclude = @("PSAvoidUsingCmdletAliases") }
   }
}

I know there are other ways to suppress, but there are reasons to want to do this via settings.

  1. Putting suppressions into files can be laborious when there are many files, such as the Pester test example.
  2. Putting suppressions into files can be unwanted if the files represent templates that are copied.
  3. In file suppressions still require PSScriptAnalyzer to analyze the file, where-as specifying file specific rule sets will let the analyzer optimize.

@mikaello
Copy link

This issue seems like a duplicate of #561

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

No branches or pull requests

6 participants