Add analyzer to check Guard clauses used for non-arguments

オープン
#1,106 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp
領域
devtools

調査の方向性

ファイル、テスト、エントリーポイントは指定されていません。まずツールキットにある既存の Guard clauses と analyzer projects を特定し、次に analyzer がメソッド引数を他の式とどのように区別するかを定義します。完了の条件は、提供された C# の例が警告を生成し、有効な引数チェックには警告が付かないことです。

索引モデルが issue の本文から書いたものです。

説明

feature request :mailbox_with_mail:
Overview

I've found guard clauses being abused and used to validate non-arguments. It would be great to have an analyzer that checks for incorrect usage where one of the Guard clauses is used for something that is not an argument to a method, property, etc.

Here is an example of something that I would like the analyzer to catch:

class C
{
    string P { get; }

    void M(string s)
    {
        Guard.IsNotNull(P); // <-- P is not an argument!
    }
}
API breakdown

N/A for an analyzer.

Usage example
class C
{
    string P { get; }

    void M(string s)
    {
        Guard.IsNotNull(P); // <-- The analyzer should report a warning, squiggle, etc.
    }
}
Breaking change?

No

Alternatives

Anyone could write an analyzer to do this outside of the toolkit, but it would obviously be best and most natural to have it included as part of the toolkit itself.

Additional context

This is predicated on my understanding that the Guard clauses provided by the toolkit are specifically intended for arguments.

Help us help you

No, just wanted to propose this

主要言語
C#
スター
3.8k
フォーク
402
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CommunityToolkit/dotnet のほかの issue

CommunityToolkit/dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。