-
File an issue describing your proposed rule prior to working on a PR. This will ensure that the rule gets triaged and there is no duplicate work involved from an existing rule OR another contributor working on a similar rule.
-
Newly proposed rule would be tagged with Needs-Review label. An Approved-Rule label indicates that the proposal has been reviewed and a PR to implement the rule would be accepted.
-
Follow the below steps to choose the appropriate rule ID for the new rule:
- Choose the applicable 'category' for the new rule. See DiagnosticCategoryAndIdRanges.txt for current diagnostic categories, and the CA IDs currently in use for each category.
- Choose the next available CA ID for the chosen 'category' from DiagnosticCategoryAndIdRanges.txt.
For example, while adding a new rule in the
Performance
category, ifCA1800-CA1829
represents the current CA ID range inDiagnosticCategoryAndIdRanges.txt
, then:- Choose
CA1830
as the rule ID for your rule. - Update the range for
Performance
in DiagnosticCategoryAndIdRanges.txt toCA1800-CA1830
- Choose
You can refer to the official documentation for all released CA rules by rule category.
-
Follow the below guidelines to choose the appropriate analyzer package for the new rule:
- Read the README section here to get an idea of the content of the analyzer packages in the repo.
- For majority of cases, you would be contributing to either Microsoft.CodeQuality.Analyzers or Microsoft.NetCoreAnalyzers. Analyzers related to pure code quality improvements, which are not specific to any API should go into
Microsoft.CodeQuality.Analyzers
. Analyzers specific to usage of a specific .NetCore/.NetStandard API should go intoMicrosoft.NetCore.Analyzers
package. - A good rule of thumb is that if your analyzer needs to invoke
GetTypeByMetadataName
, then most likely it is an API specific analyzer and belongs toMicrosoft.NetCore.Analyzers
.
-
Documentation requirements:
- New CA rule must be documented: Each rule ID
CAxxxx
is automatically assigned the help link https://docs.microsoft.com/visualstudio/code-quality/caxxxx. The documentation for this page is populated fromcaxxxx.md
file at https://github.com/MicrosoftDocs/visualstudio-docs/tree/master/docs/code-quality. For example,CA1000
is documented at ca1000.md file. Documenting a new rule is primarily ensuring a PR is sent toMicrosoftDocs
repo to addcaxxxx.md
file for the new rule. Detailed steps are given below. - Documentation PR must be submitted within ONE WEEK of the rule implementation being merged. Note that we will communicate this requirement on each PR contributing a new CA rule. We reserve the right to revert the rule implementation PR if this documentation requirement is not met.
Steps for creating documentation PR:
-
Documentation PR must be submitted to the following repo:
- External contributors: https://github.com/MicrosoftDocs/visualstudio-docs
- Internal contributors: https://github.com/MicrosoftDocs/visualstudio-docs-pr
Please review CONTRIBUTING.md for guidelines.
-
Documentation PR for a new CA rule must have following changes:
-
New
caxxxx.md
file under/docs/code-quality
sub-folder with rule documentation.TIP:
Clone an existingcaxxxx.md
file inside/docs/code-quality
sub-folder in the repo, rename it and update the contents for the new rule. -
Update the following tables in the repo for supported CA rule IDs:
- Add entry in
/docs/code-quality/toc.yml
under appropriate category. - Add entry in
/docs/code-quality/code-analysis-warnings-for-managed-code-by-checkid.md
- Add entry in the documentation file
/docs/code-quality/<%category%>-warnings.md
for rule'sCategory
. For example:- For a new rule with category
Design
, add an entry to/docs/code-quality/design-warnings.md
. - For a new rule with category
Performance
, add an entry to/docs/code-quality/performance-warnings.md
, and so on.
- For a new rule with category
- Add entry in
-
If for some exceptional reason you are unable to submit a PR, please file a documentation issue to add documentation for the rule in future. Please include all relevant information in the issue to allow the documentation experts to easily author the documentation. For example, see this issue.
- New CA rule must be documented: Each rule ID