2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#で静的分析ツール(StyleCop.Analyzers)を使用する

Posted at

1. はじめに

  • C#のソースコードの記述をある程度統一したいため、制的分析ツールを使用したい
  • StyleCop.Analyzersで不要なルールを除外して運用したい

2. 開発環境

  • C#
  • .NET 6
  • Visual Studio 2022
  • Widows 11
  • StyleCop.Analyzers (NuGet)

3. StyleCop.Analyzersのインストール

  • ソリューションエクスプローラーの依存関係を右クリックして、NuGet パッケージの管理を選択する
    image.png

  • StyleCop.Analyzersをインストールする
    image.png

  • OKボタンをクリックする
    image.png

  • インストールが完了すると、エラー一覧で警告が表示される
    image.png

image.png

3. 不要なルールの非公開にする手順

3.1. Code Analysis 規則セットの追加

  • ソリューションエクスプローラーのプロジェクトを右クリックして、追加 > 追加を選択する

image.png

  • Code Analysis 規則セットを選択する
    image.png

  • Code Analysis 規則セットが追加される
    image.png

3.2. Code Analysis 規則セットの設定

  • 下記ルールについては英語圏のルール等のため非表示にする
No コード タイプ名 タイプ名
1 SA1101 PrefixLocalCallsWithThis ローカルクラスまたは基本クラスのインスタンスメンバーへの呼び出しには、C#コードファイル内で接頭辞「this.」が付いていません
2 SA1200 UsingDirectivesMustBePlacedCorrectly AC#usingディレクティブは、名前空間要素の外部に配置されます。
3 SA1309 FieldNamesMustNotBeginWithUnderscore C#のフィールド名は、アンダースコアで始まっています。
4 SA1629 DocumentationTextMustEndWithAPeriod C#要素のXmlヘッダードキュメントのセクションは、ピリオドで終わっていません。
5 SA1633 SA1633FileMustHaveHeader C#コードファイルに標準のファイルヘッダーがありません。

image.png

image.png

image.png

image.png

image.png

4. 参考文献

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?