Skip to content

Adding documentation about suppressing rule violations. #274

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

Merged
merged 2 commits into from
Jul 17, 2015

Conversation

splatteredbits
Copy link
Contributor

No description provided.

@msftclas
Copy link

Hi @splatteredbits, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

@msftclas
Copy link

@splatteredbits, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, MSBOT;

)


You can also suppress a rule for an entire class using `Class` as the value of the `Scope` property:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually do this by simply decorating the class with the SuppressMessageAttribute (the scope is unnecessary in this case). A case where the use of scope is more meaningful is if you want to suppress a rule for all the classes within a script, then you can decorate the script with a SuppressMessageAttribute with the Scope as Class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the scope reflects the kind of objects in the scope where the suppress
attribute is? So a scope of "function" would apply to all functions in the
scope of the attribute?

On Mon, Jul 13, 2015 at 3:40 PM, Quoc Truong [email protected]
wrote:

In README.md
#274 (comment)
:

  • {
  •    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "b")]
    
  •    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "a")]
    
  •    param([string]$a, [int]$b)
    
  •    {
    
  •    }
    
  • }

+To suppress a rule for an entire function/script, decorate the param block of the script/function and set the SuppressMessageAttribute's Scope property to Function:
+

  • [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideCommentHelp", "", Scope="Function")]
  • param(
  • )

+You can also suppress a rule for an entire class using Class as the value of the Scope property:

You can actually do this by simply decorating the class with the
SuppressMessageAttribute (the scope is unnecessary in this case). A case
where the use of scope is more meaningful is if you want to suppress a rule
for all the classes within a script, then you can decorate the script with
a SuppressMessageAttribute with the Scope as Class.


Reply to this email directly or view it on GitHub
https://github.com/PowerShell/PSScriptAnalyzer/pull/274/files#r34520293.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

On Mon, Jul 13, 2015 at 3:45 PM, Quoc Truong [email protected]
wrote:

In README.md
#274 (comment)
:

  • {
  •    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "b")]
    
  •    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "a")]
    
  •    param([string]$a, [int]$b)
    
  •    {
    
  •    }
    
  • }

+To suppress a rule for an entire function/script, decorate the param block of the script/function and set the SuppressMessageAttribute's Scope property to Function:
+

  • [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideCommentHelp", "", Scope="Function")]
  • param(
  • )

+You can also suppress a rule for an entire class using Class as the value of the Scope property:

Yes that is correct.


Reply to this email directly or view it on GitHub
https://github.com/PowerShell/PSScriptAnalyzer/pull/274/files#r34520695.


[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideCommentHelp", "", Scope="Function")]
param(
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This param is not attached to any function or script. You can look at https://github.com/PowerShell/PSScriptAnalyzer/blob/master/Tests/Engine/RuleSuppression.ps1 for an example of a param block of a function, script or class. Thanks!

@raghushantha
Copy link
Member

Merging the PR. Changes look good.Thanks Aaron.

raghushantha added a commit that referenced this pull request Jul 17, 2015
Adding documentation about suppressing rule violations.
@raghushantha raghushantha merged commit a2f92d3 into PowerShell:master Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants