Skip to content

Commit 8233edd

Browse files
committed
fixes MicrosoftDocs/visualstudio-docs#1908
1 parent 9e98000 commit 8233edd

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

docs/code-quality/in-source-suppression-overview.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ The properties of the attribute include:
8686
8787
- **Target** - An identifier that is used to specify the target on which the warning is being suppressed. It must contain a fully qualified item name.
8888
89+
To see examples of using `SuppressMessage`, use Visual Studio to [add a suppression to the global suppression file](../code-quality/use-roslyn-analyzers.md#suppress-violations) for warnings that you see in the code editor. The suppression attribute appears in a preview window.
90+
8991
## SuppressMessage usage
9092
9193
Code Analysis warnings are suppressed at the level to which the <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute> attribute is applied. For example, the attribute can be applied at the assembly, module, type, member, or parameter level. The purpose of this is to tightly couple the suppression information to the code where the violation occurs.
@@ -141,15 +143,6 @@ public class Animal
141143
}
142144
```
143145

144-
## Generated code
145-
146-
Managed code compilers and some third-party tools generate code to facilitate rapid code development. Compiler-generated code that appears in source files is usually marked with the `GeneratedCodeAttribute` attribute.
147-
148-
You can choose whether to suppress code analysis warnings and errors for generated code. For information about how to suppress such warnings and errors, see [How to: Suppress Warnings for Generated Code](../code-quality/how-to-suppress-code-analysis-warnings-for-generated-code.md).
149-
150-
> [!NOTE]
151-
> Code analysis ignores `GeneratedCodeAttribute` when it is applied to either an entire assembly or a single parameter.
152-
153146
## Global-level suppressions
154147

155148
The managed code analysis tool examines `SuppressMessage` attributes that are applied at the assembly, module, type, member, or parameter level. It also fires violations against resources and namespaces. These violations must be applied at the global level and are scoped and targeted. For example, the following message suppresses a namespace violation:
@@ -180,6 +173,22 @@ For example, the following attribute in your _GlobalSuppressions_ project file w
180173

181174
`[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "ASP.NET Core doesn't use thread context to store request context.", Scope = "module")]`
182175

176+
## Generated code
177+
178+
Managed code compilers and some third-party tools generate code to facilitate rapid code development. Compiler-generated code that appears in source files is usually marked with the `GeneratedCodeAttribute` attribute.
179+
180+
For source code analysis (FxCop analyzers), you can suppress messages in generated code using the [.editorconfig](../code-quality/configure-fxcop-analyzers.md) file in the root of your project or solution. Use a file pattern to match the generated code. For example, to exclude CS1591 warnings in *.designer.cs* files, use this in the configuration file.
181+
182+
``` cmd
183+
[*.designer.cs]
184+
dotnet_diagnostic.CS1591.severity = none
185+
```
186+
187+
For legacy code analysis, you can choose whether to suppress code analysis warnings and errors for generated code. For information about how to suppress such warnings and errors, see [How to: Suppress Warnings for Generated Code](../code-quality/how-to-suppress-code-analysis-warnings-for-generated-code.md).
188+
189+
> [!NOTE]
190+
> Code analysis ignores `GeneratedCodeAttribute` when it is applied to either an entire assembly or a single parameter.
191+
183192
## See also
184193

185194
- <xref:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute.Scope>

0 commit comments

Comments
 (0)