PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

Settings file needs to have a exclude / ignore mechanism

Open jhoneill opened this issue 6 years ago • 5 comments

**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

jhoneill avatar May 01 '19 10:05 jhoneill

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

msftrncs avatar May 07 '19 03:05 msftrncs

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

jhoneill avatar May 07 '19 07:05 jhoneill

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.

jayvdb avatar Jun 21 '19 02:06 jayvdb

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.

wekempf avatar Apr 08 '22 10:04 wekempf

This issue seems like a duplicate of https://github.com/PowerShell/PSScriptAnalyzer/issues/561

mikaello avatar Nov 21 '22 13:11 mikaello