-
Notifications
You must be signed in to change notification settings - Fork 389
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
Add support for suppressing custom rules #1140
Comments
Please give more detail what you are asking for. Are you saying it is not possible to suppress custom rules using attributes? |
Yes, that is what the readme says https://github.com/PowerShell/PSScriptAnalyzer#suppressing-rules |
Thanks. Hmm, I'll have to try and see, maybe this readme section is out of date. In general if you are sure about this we would definitely accept a PR for that. |
AFAICK, it never worked for custom rule. This can be a deal breaker for who enforces their organization coding standard using custom rules. There will definitely be legitimate use cases for suppressing custom rules IMO. |
Hi, yes, I can confirm that this feature has not been implemented yet and I definitely see the value of it. I am not familiar with the code that does the suppression, therefore I don't know how involved it is to get it to work. Currently, no one is working on it, this repo doesn't really have a feature pipeline. Although I might approach it at some point (which could mean several months or even longer considering that the change would also need to be released) but if you really want this feature I suggest you try open a PR. We want to release a new version in about 1-2 months, therefore getting it in before could be useful to you. I would be happy to help out if you have questions or need help to finish it off once you have a first working prototype. Even just pointers to code that would need to be modified can help reduce the work for maintainers. |
@bergmeister |
@bergmeister This is not a feature, actually this is broken. custom rule suppression is actually working. The rule name must be consistent with the rule function. Ideally, PSSA should handle this inconsistent rule name, but that is broken for some reason. |
@manigandan-jegannathan-developer It seems the rule name of a custom rule is |
So how should we suppress any rule now. I have been trying from the new version 1.18. Looks like #1145 broke the existing suppression mechanism also. With 1.17.1 I was able to at least suppress a rule using the function name like below. [Diagnostics.CodeAnalysis.SuppressMessageAttribute("Measure-VariableCase", '')] Now it is completely broken. |
Ugg! why did we do this ? Now we have to pass like below ? This is more uglier than the previous one.
Is there an alternate way to have it shorter ? You can always set rule info to anything you want in [DiagnosticRecord]. At least previously we can set the rule name as Measure-PSVariableCase (basically function name) in the [DiagnosticRecord]. But now we need to set SampleRule\Measure-PSVariableCase as a rule and use the full name SampleRule\Measure-PSVariableCase in the suppression attribute. In fact, I was expecting in the new PR, we will be able to suppress based on the rule name whatever we set the in [DiagnosticRecord] object. It does not have to rely on function name or anything else. Looks like that's not the case. I am thinking now whether should I go with 1.18 :/. |
This does not make any sense to me. I think we both agreed that in 1.17.1 it was not possible at all to suppress a custom rule? |
I think there was a miscommunication. If you look at my previous updates, I said that it is not broken. PSSA expects the rule name to match with the function name. That's something I expected to change. I'd not want to name my PSSA rule as Measure-PSAvoidFoo, I'd rather prefer it as PSAvoidFoo. But now the problem is, most of our code has suppressmessageattribute as Measure-PSAvoidFoo. with this new version, we have to change SampleRule\Measure-PSAvoidFoo. That is my concern. quoting it again,
|
@bergmeister I have couple of doubts with this,
I kind of feel my suppression is not working with new version. So checking with you, appreciate your help with this |
@manigandan-jegannathan-developer The test in my PR uses |
I have the similar set up, but suppression is not working for me. Am I missing anything ? @bergmeister |
I really doubt this. |
Have a look here for an example of a suppression of a simple custom rule (suppression is commented out to show warning first, just un-comment the suppression and you will see that it works: |
Thanks @bergmeister for all your help. I found the problem, I am not using $myinvocation.InvocationName in my custom rule. That's the ultimate problem which I have been telling from the beginning (see my previous comments.)
|
@bergmeister Just checking with you about my previous comment |
You're right, it seems to be the function name that is used and not the rule name for suppression, hence why it works when using |
Some more discussion is going on in #1237 about the inconsistency between |
Thanks @bergmeister. I hope I will find sometime to create a PR for this. This will be useful IMO. Thanks for all your work. Appreciate it :) |
Is this something in the feature pipeline ?
The text was updated successfully, but these errors were encountered: