コード スタイルの規則

.NET コード スタイル分析では、コードベースに一貫性のあるスタイルをメインすることを目的とするルールが提供されます。 これらのルールには、ルール ID に "IDE" というプレフィックスが付いています。

コード スタイルの規則は、次のサブカテゴリに分類されます。

  • 言語と不要なコード規則

    C# または Visual Basic 言語に関するルール。 たとえば、変数を定義するときの var の使用に関するルールや、式形式のメンバーを優先するかどうかを指定できます。 このカテゴリには、メソッド内の到達不能なコードや未使用のプライベート フィールド、プロパティ、メソッドなど、不要なコードを検索するルールも含まれます。

  • 書式設定規則

    コードを読みやすくするためのレイアウトや構造に関するルール。 たとえば、コントロール ブロック内のスペースを優先するかどうかを定義する書式設定オプションを指定できます。

  • 名前付け規則

    コード要素の名前付けに関するルール。 たとえば、async メソッド名に "Async" サフィックスが必要であることを指定できます。

  • その他の規則

    他のカテゴリに属さないルール。

インデックス

次の表に、ID と オプション (存在する場合) ごとにすべてのコード スタイル規則を示します。

ルール ID タイトル オプション
IDE0001 名前を簡略化する
IDE0002 メンバー アクセスを簡略化する
IDE0003 this または Me の修飾を削除する dotnet_style_qualification_for_field
dotnet_style_qualification_for_property
dotnet_style_qualification_for_method
dotnet_style_qualification_for_event
IDE0004 不要なキャストを削除する
IDE0005 不要なインポートを削除する
IDE0007 明示的な型の代わりに var を使用する csharp_style_var_for_built_in_types
csharp_style_var_when_type_is_apparent
csharp_style_var_elsewhere
IDE0008 var の代わりに明示的な型を使用する csharp_style_var_for_built_in_types
csharp_style_var_when_type_is_apparent
csharp_style_var_elsewhere
IDE0009 this または Me の修飾を追加する dotnet_style_qualification_for_field
dotnet_style_qualification_for_property
dotnet_style_qualification_for_method
dotnet_style_qualification_for_event
IDE0010 不足しているケースを switch ステートメントに追加する
IDE0011 中かっこを追加する csharp_prefer_braces
IDE0016 throw 式を使用する csharp_style_throw_expression
IDE0017 オブジェクト初期化子を使用する dotnet_style_object_initializer
IDE0018 インライン変数宣言 csharp_style_inlined_variable_declaration
IDE0019 パターン マッチングを使用して as の後に null チェックが発生しないようにする csharp_style_pattern_matching_over_as_with_null_check
IDE0020 パターン マッチングを使用して、is チェックの後にキャスト (変数を含む) が発生しないようにする csharp_style_pattern_matching_over_is_with_cast_check
IDE0021 コンストラクターに式本体を使用する csharp_style_expression_bodied_constructors
IDE0022 メソッドに式本体を使用する csharp_style_expression_bodied_methods
IDE0023 変換演算子に式本体を使用する csharp_style_expression_bodied_operators
IDE0024 演算子に式本体を使用する csharp_style_expression_bodied_operators
IDE0025 プロパティに式本体を使用する csharp_style_expression_bodied_properties
IDE0026 インデクサーに式本体を使用する csharp_style_expression_bodied_indexers
IDE0027 アクセサーに式本体を使用する csharp_style_expression_bodied_accessors
IDE0028 コレクション初期化子を使用する dotnet_style_collection_initializer
dotnet_style_prefer_collection_expression (C# のみ)
IDE0029 null チェックを簡略化できます dotnet_style_coalesce_expression
IDE0030 null チェックを簡略化できます dotnet_style_coalesce_expression
IDE0031 null 値の反映を使用する dotnet_style_null_propagation
IDE0032 自動プロパティを使用する dotnet_style_prefer_auto_properties
IDE0033 明示的に提供されたタプル名を使用する dotnet_style_explicit_tuple_names
IDE0034 default 式を簡略化する csharp_prefer_simple_default_expression
IDE0035 到達できないコードの削除
IDE0036 修飾子を順序付けする csharp_preferred_modifier_order
visual_basic_preferred_modifier_order
IDE0037 推定メンバーの名前を使用する dotnet_style_prefer_inferred_tuple_names
dotnet_style_prefer_inferred_anonymous_type_member_names
IDE0038 パターン マッチングを使用して、is チェックの後にキャスト (変数を含まない) が発生しないようにする csharp_style_pattern_matching_over_is_with_cast_check
IDE0039 ラムダの代わりにローカル関数を使用する csharp_style_prefer_local_over_anonymous_function
IDE0040 アクセシビリティ修飾子の追加 dotnet_style_require_accessibility_modifiers
IDE0041 is null チェックを使用する dotnet_style_prefer_is_null_check_over_reference_equality_method
IDE0042 変数宣言を分解する csharp_style_deconstructed_variable_declaration
IDE0044 読み取り専用修飾子を追加する dotnet_style_readonly_field
IDE0045 代入に条件式を使用する dotnet_style_prefer_conditional_expression_over_assignment
IDE0046 戻り値に条件式を使用する dotnet_style_prefer_conditional_expression_over_return
IDE0047 不要なかっこを削除する dotnet_style_parentheses_in_arithmetic_binary_operators
dotnet_style_parentheses_in_relational_binary_operators
dotnet_style_parentheses_in_other_binary_operators
dotnet_style_parentheses_in_other_operators
IDE0048 わかりやすくするためにかっこを追加する dotnet_style_parentheses_in_arithmetic_binary_operators
dotnet_style_parentheses_in_relational_binary_operators
dotnet_style_parentheses_in_other_binary_operators
dotnet_style_parentheses_in_other_operators
IDE0049 型参照のためのフレームワーク型名の代わりに言語キーワードを使用する dotnet_style_predefined_type_for_locals_parameters_members
dotnet_style_predefined_type_for_member_access
IDE0050 匿名型をタプルに変換する
IDE0051 使用されていない非公開メンバーを削除する
IDE0052 読み取られていない非公開メンバーを削除する
IDE0053 ラムダに式本体を使用する csharp_style_expression_bodied_lambdas
IDE0054 複合代入を使用する dotnet_style_prefer_compound_assignment
IDE0055 書式設定を修正する (ここに一覧表示するには多すぎます。.NET の書式設定オプションと C# の書式設定オプションを参照してください)。
IDE0056 インデックス演算子を使用する csharp_style_prefer_index_operator
IDE0057 範囲演算子を使用する csharp_style_prefer_range_operator
IDE0058 使用されていない式の値を削除する csharp_style_unused_value_expression_statement_preference
visual_basic_style_unused_value_expression_statement_preference
IDE0059 不要な値の代入を削除する csharp_style_unused_value_assignment_preference
visual_basic_style_unused_value_assignment_preference
IDE0060 使用されていないパラメーターを削除する dotnet_code_quality_unused_parameters
IDE0061 ローカル関数に式本体を使用する csharp_style_expression_bodied_local_functions
IDE0062 ローカル関数を静的にする csharp_prefer_static_local_function
IDE0063 単純な using ステートメントを使用する csharp_prefer_simple_using_statement
IDE0064 構造体のフィールドを書き込み可能にする
IDE0065 using ディレクティブの配置 csharp_using_directive_placement
IDE0066 switch 式を使用する csharp_style_prefer_switch_expression
IDE0070 System.HashCode.Combine を使用します
IDE0071 補間を簡略化する dotnet_style_prefer_simplified_interpolation
IDE0072 不足しているケースを switch 式に追加する
IDE0073 ファイル ヘッダーを使用する file_header_template
IDE0074 結合複合代入を使用する dotnet_style_prefer_compound_assignment
IDE0075 条件式を簡略化する dotnet_style_prefer_simplified_boolean_expressions
IDE0076 無効でグローバルな SuppressMessageAttribute を削除する
IDE0077 グローバルな SuppressMessageAttribute でレガシ形式のターゲットを回避する
IDE0078 パターン マッチングの使用 csharp_style_prefer_pattern_matching
IDE0079 不要な抑制を削除する dotnet_remove_unnecessary_suppression_exclusions
IDE0080 不要な抑制演算子を削除する
IDE0081 ByVal を削除します
IDE0082 typeofnameof に変換する
IDE0083 パターン マッチングを使用する (not 演算子) csharp_style_prefer_not_pattern
IDE0084 パターン マッチングを使用する (IsNot 演算子) visual_basic_style_prefer_isnot_expression
IDE0090 new 式を簡略化する csharp_style_implicit_object_creation_when_type_is_apparent
IDE0100 不要な等値演算子を削除する
IDE0110 [Remove unnecessary discard]\(不要な破棄を削除する\)
IDE0120 LINQ 式の簡略化
IDE0130 名前空間がフォルダー構造と一致しない dotnet_style_namespace_match_folder
IDE0140 オブジェクトの作成を簡略化する visual_basic_style_prefer_simplified_object_creation
IDE0150 型チェックより null チェックを優先します csharp_style_prefer_null_チェック_over_type_チェック
IDE0160 ブロック スコープの名前空間を使用する csharp_style_namespace_declarations
IDE0161 ファイル スコープの名前空間を使用する csharp_style_namespace_declarations
IDE0170 プロパティ パターンを簡略化する csharp_style_prefer_extended_property_pattern
IDE0180 タプルを使用して値を入れ替える csharp_style_prefer_tuple_swap
IDE0200 不要なラムダ式を削除する csharp_style_prefer_method_group_conversion
IDE0210 最上位レベルのステートメントに変換する csharp_style_prefer_top_level_statements
IDE0211 'Program.Main' スタイルのプログラムに変換する csharp_style_prefer_top_level_statements
IDE0220 foreach ループに明示的なキャストを追加する dotnet_style_prefer_foreach_explicit_cast_in_source
IDE0230 UTF-8 文字列リテラルを使用する csharp_style_prefer_utf8_string_literals
IDE0240 Null 許容ディレクティブが冗長です
IDE0241 Null 許容ディレクティブは不要です
IDE0250 '読み取り専用' にできる構造体 csharp_style_prefer_readonly_struct
IDE0251 '読み取り専用' にできるメンバー csharp_style_prefer_readonly_struct_member
IDE0260 パターン マッチングの使用 csharp_style_pattern_matching_over_as_with_null_check
IDE0270 null チェックを簡略化できます dotnet_style_coalesce_expression
IDE0280 nameof を使用します
IDE0290 プライマリ コンストラクターを使用する csharp_style_prefer_primary_constructors
IDE0300 配列にコレクション式を使用する dotnet_style_prefer_collection_expression
IDE0301 空の配列にコレクション式を使用する dotnet_style_prefer_collection_expression
IDE0302 stackalloc にコレクション式を使用する dotnet_style_prefer_collection_expression
IDE0303 コレクション式を使用する Create() dotnet_style_prefer_collection_expression
IDE0304 ビルダーにコレクション式を使用する dotnet_style_prefer_collection_expression
IDE0305 fluent にコレクション式を使用する dotnet_style_prefer_collection_expression
IDE1005 条件付き代理呼び出しを使用する csharp_style_conditional_delegate_call
IDE1006 命名スタイル

Note

Visual Studio IDE にのみ表示されるいくつかの規則があり、これらは JSON と正規表現パターン文字列に関連します。 詳細については、「JSON001、JSON002、RE0001」を参照してください

凡例

次の表は、リファレンス ドキュメントの各ルールに対して提供される情報の種類を示しています。

アイテム 説明
ルール ID 規則の一意の識別子。 ルールの重大度を構成し、コード ファイル内の警告を抑制するために使用されます。
Title ルールのタイトル。
カテゴリ ルールのカテゴリ。
Subcategory 言語ルール、書式設定規則、名前付け規則など、ルールのサブカテゴリ。
該当言語 最低限の言語バージョン (存在する場合) で適用可能な .NET の言語 (C# または Visual Basic)。
導入されたバージョン ルールが最初に導入されたときの .NET SDK または Visual Studio のバージョン。
[オプション] ルールに使用できるオプション。

関連項目