-
Notifications
You must be signed in to change notification settings - Fork 511
Script analysis should default to a minimal set of rules which can be configured #28
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
Comments
Theres really a few options here Dont use VSCode with the PowerShell extension We shouldnt really be suggesting to take a step back in terms of getting best (better/good - all debatable) practices embaked in the development experience as this will only serve to further discourage more adoption. Or the other possibility (and I kid when I say this) write better code. We are getting a better overall ecosystem but it will much more time to do so to the point where there is a majority in agreement about rules etc but at least we have a beginning framework Just my 2 pennies worth |
In the 0.2.0 release I added a new setting (see #11) to turn off script analysis entirely. Instead of disabling it by default, I'd like to work out a good set of default rules that will be helpful to people but not overly noisy or wrong/misleading. Part of the reason for introducing the What do you think? |
Also, to reinforce one of @kilasuit's points, at some point soon I'm going to try to tune some of the Script Analyzer rules so that they don't mark whole functions unnecessarily. Only the most minimally relevant section of the script should be marked for any diagnostic that is returned. |
So, I will admit I was being provocative here. (Which is why I tweeted it, rather than just filling it) I would love to have PSScriptAnalyzer be like visual studio code analysis, where every time it yells at me I correct my code, or feel a sense of shame when I disable the rule... Currently, that's just not the case. My argument to the team in charge of PSScriptAnalyzer has always been that the default rules need to be important, and always right. But on top of that, it needs to be like Visual Studio code analysis.
That last bit is where you come in. However, having said all that... Is there any other language or dev tool that ships with code analysis on? Visual Studio definitely doesn't turn it on by default in my C# projects. Why would you turn it on by default? |
So my argument here is that having it on by default includes the following points |
I'm pretty sure Visual Studio has code analysis on for C# by default, otherwise you wouldn't see warnings about uninitialized variables, etc (which I do). But I agree, we need to default to a standard, minimal ruleset which can be configured on a per-project basis. I'll work on this for the next release! |
@Jaykul is right. There's a difference between CS (compiler) and CA (code analysis) warnings and errors. I've always had to explicitly turn on code analysis in my C# projects. |
Didn't realize there was a separate code analysis setting in VS. My intent with having analysis on by default is to get that basic level language intelligence which can't be given by the parser alone. Obviously that's now the way it is now, but ultimately I'd like to be able to give some level of helpful hints by default. How about this: before I make any changes, I'll send out a list of my proposed default rules and you guys can tell me whether you think they make sense. |
A "minimum" rule set or profile from the PSScriptAnalyzer team would be a good thing to have. It is useful to see those things that have a high probability of causing failure. However whether I use That's the sort of the problem with tools like this, the rules aren't always so cut and dry. Heck the "community" has had a hard time agreeing on what the rules should be. Check out the issues list on the PSScriptAnalyzer project. :-) |
I'm about to make this change and wanted to double-check with folks on what a good basis would be for now (until the new Script Analyzer rule sets get rolled out). I've seen comments from @Jaykul and @rkeithhill on the PSScriptAnalyzer repo about which things they think shouldn't be there by default. Here is the list of rules I intend to include at this point:
What do you think? Anything I should add or remove? |
Check out the pull request here: |
I would consider adding:
|
I'm don't like Does PSUseSingularNouns work, or does it just flag things that end in "s" or "es" or something? ;) |
I think I've seen a bug on PSScriptAnalyzer recently stating that For |
I think a rule that warns you when you're writing a cmdlet that does something irreversible and tells you to put ShouldProcess on it is a great feature. I think a rule that says "since you're using 'Remove' you should use ShouldProcess" is dumb. 😧 |
Ok, I'll take it out for now until that rule gets improved. |
Since the primary work for this was completed some time ago I'll go ahead and close this issue. Keith has created a new issue (#122) to track the requirement for allowing the user to configure their desired PSScriptAnalyzer ruleset. |
It's wrong far more often than it's right on my code, and the annoyance of the warnings is really starting to get to me.
The text was updated successfully, but these errors were encountered: