PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.87k stars 378 forks source link

Switch to elevate warning to errors #1534

Open TylerLeonhardt opened 4 years ago

TylerLeonhardt commented 4 years ago

Summary of the new feature

As a user, I want a single switch to elevate warnings to errors so that my repos can have error-less, warning-less code. In CI scenarios, like @justinGrote's Super-Duper-Linter I need the task to fail when there are only warnings.

Proposed technical implementation details (optional)

@rjmholt mentioned the -NoExit param but I'm not sure if that will exit on warnings as well...

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

1.19

TylerLeonhardt commented 4 years ago

msbuild already has this ability via the csproj

JustinGrote commented 4 years ago

@TylerLeonhardt fyi the linter will be able to set a fail level (info, warning, error) based on the diagnostic record output so it won't be explicitly needed for the linter but still a nice-to-have.

bergmeister commented 4 years ago

The -EnableExit switch returns an exit code equivalent to the number of diagnostic records, no matter the severity. There is also a Severity parameter to run only rules of one or more severities. Even after that one could still easily write some logic to return a different exit code based on analysis of the returned DiagnosticRecords. Therefore I don't understand the ask here. Maybe you could explain your example in more detail please?

ghost commented 4 years ago

Closing due to inactivity

rjmholt commented 4 years ago

I've thought about this some more, and I think it's at least worth continuing to track. My thinking here:

clcaldwell commented 4 years ago

@rjmholt For your last issue above - I 100% agree that rule severity should be configurable. Looks like #1515 is already tracking this.

I might be misunderstanding, but it looks like OP just wants to essentially do:

If ($Results = (Invoke-ScriptAnalyzer).Where{$_.Severity -eq 'Warning'}) {
    Exit $Results.count
}

It doesn't really seem like the type of thing that needs it's own param, IMO. And in situations where you are using -EnableExit instead of parsing the report, it would make sense to just only include the rules that you explicitly want the build to fail for.