Générer un fichier EditorConfigGenerate an EditorConfig file

Les fichiers EditorConfig aident à assurer la cohérence de votre code en définissant des styles et des mises en forme de code.EditorConfig files help to keep your code consistent by defining code styles and formats. Ces conventions permettent à Visual Studio d’offrir des correctifs de format et de style automatiques pour nettoyer votre document.These conventions allow Visual Studio to offer automatic style and format fixes to clean up your document. Si vous êtes développeur C#, IntelliCode peut inférer vos conventions de style et de mise en forme du code pour créer dynamiquement un fichier EditorConfig.For C# developers, IntelliCode can infer your code style and formatting conventions to dynamically create an EditorConfig file.

Vous pouvez ajouter un fichier EditorConfig généré par IntelliCode au niveau d’un projet ou d’une solution dans Visual Studio (ou au dossier d’une solution).You can add an IntelliCode-generated EditorConfig file at the project or solution level in Visual Studio (or to a solution folder). Pour ajouter un fichier EditorConfig prérempli, cliquez avec le bouton droit sur l’emplacement souhaité dans l’Explorateur de solutions et choisissez Ajouter > Nouvel EditorConfig (IntelliCode).To add a prepopulated EditorConfig file, right-click on the desired location in Solution Explorer and choose Add > New EditorConfig (IntelliCode)

Ajouter un fichier EditorConfig généré par IntelliCode dans Visual Studio

Une fois que vous avez ajouté le fichier de cette façon, IntelliCode le remplit automatiquement avec les conventions de style de code qu’il infère de votre code base.After you add the file in this way, IntelliCode automatically populates it with code style conventions it infers from your codebase.

Notes

L’inférence de style de code est une fonctionnalité en préversion qui est désactivée par défaut.Code style inference is a preview feature and is disabled by default. Il peut être activé par Tools > Options > IntelliCode.It can be enabled through Tools > Options > IntelliCode. Elle est actuellement disponible pour le code C# uniquement.It is currently available only for C# code. Pour accéder à cette fonctionnalité, n’oubliez pas de mettre à jour la dernière version Visual Studio 2019 Preview.To access this feature be sure to update to the latest Visual Studio 2019 Preview release.

Pour plus d’informations sur la génération d’un fichier EditorConfig basé sur les styles de code de votre code base, consultez cet article de blog.For more information about generating an EditorConfig file based on code styles in your codebase, see this blog article.

Appliquer les conventions du fichier EditorConfigApply EditorConfig conventions

Les violations des conventions de style de code d’un fichier EditorConfig n’apparaissent pas dans la Liste d’erreurs ni sous forme de « tildes » dans votre code.Violations of code style conventions in an EditorConfig file don't appear in the Error List or as "squiggles" in your code. Vous pouvez cependant les appliquer en utilisant la commande Nettoyage du code (Visual Studio 2019) ou la commande Mettre le document en forme (Visual Studio 2017).They can, however, be applied by using the Code Cleanup command (Visual Studio 2019) or the Format Document command (Visual Studio 2017).

Si vous utilisez Visual Studio 2017 et que la commande Mettre le document en forme ne corrige pas vos conventions de style, il est possible que vous n’ayez pas autorisé les corrections de style de code lors de la mise en forme du document.If you're using Visual Studio 2017 and Format Document is not fixing your style conventions, you may not be opted in to code style fixes during document formatting. Par exemple, Appliquer les préférences de type implicite/explicite applique les règles de style concernant l’utilisation de var.For example, Apply implicit/explicit type preferences runs style rules about the use of var. Configurez quels problèmes doivent être résolus en utilisant la boîte de dialogue Options de mise en forme.Configure which issues are fixed by using the formatting options dialog box. Choisissez Tools > Options > Text Editor > CMD > Code Style > Formatting > General > Format Document Paramètres (Expérience).Choose Tools > Options > Text Editor > C# > Code Style > Formatting > General > Format Document Settings (Experiment).

Informations de référence sur les conventions inféréesInferred convention reference

IntelliCode ne prend pas encore en charge l’ensemble des conventions décrites dans les informations de référence sur les paramètres des styles de code.IntelliCode doesn't yet support the full set of conventions documented in code style settings reference. IntelliCode peut actuellement inférer les conventions de mise en forme et de style suivantes :IntelliCode can currently infer the following formatting and style conventions:

Conventions de mise en formeFormatting conventions

  • csharp_space_between_method_declaration_parameter_list_parenthesescsharp_space_between_method_declaration_parameter_list_parentheses
  • csharp_space_between_method_declaration_empty_parameter_list_parenthesescsharp_space_between_method_declaration_empty_parameter_list_parentheses
  • csharp_space_between_method_call_name_and_opening_parenthesiscsharp_space_between_method_call_name_and_opening_parenthesis
  • csharp_space_between_method_call_parameter_list_parenthesescsharp_space_between_method_call_parameter_list_parentheses
  • csharp_space_between_method_call_empty_parameter_list_parenthesescsharp_space_between_method_call_empty_parameter_list_parentheses
  • csharp_space_after_keywords_in_control_flow_statementscsharp_space_after_keywords_in_control_flow_statements
  • csharp_space_between_parenthesescsharp_space_between_parentheses
  • csharp_space_after_castcsharp_space_after_cast
  • csharp_space_after_colon_in_inheritance_clausecsharp_space_after_colon_in_inheritance_clause
  • csharp_space_before_colon_in_inheritance_clausecsharp_space_before_colon_in_inheritance_clause
  • csharp_space_around_binary_operatorscsharp_space_around_binary_operators
  • csharp_indent_switch_labelscsharp_indent_switch_labels
  • csharp_indent_case_contentscsharp_indent_case_contents
  • csharp_indent_case_contents_when_blockcsharp_indent_case_contents_when_block
  • csharp_indent_labelscsharp_indent_labels
  • csharp_preserve_single_line_blockscsharp_preserve_single_line_blocks
  • csharp_preserve_single_line_statementscsharp_preserve_single_line_statements
  • csharp_new_line_before_open_bracecsharp_new_line_before_open_brace
  • csharp_new_line_before_elsecsharp_new_line_before_else
  • csharp_new_line_before_catchcsharp_new_line_before_catch
  • csharp_new_line_before_finallycsharp_new_line_before_finally
  • csharp_new_line_before_members_in_object_initializerscsharp_new_line_before_members_in_object_initializers
  • csharp_new_line_before_members_in_anonymous_typescsharp_new_line_before_members_in_anonymous_types
  • csharp_new_line_between_query_expression_clausescsharp_new_line_between_query_expression_clauses

Conventions de styleStyle conventions

  • csharp_new_line_before_catchcsharp_new_line_before_catch
  • csharp_new_line_before_elsecsharp_new_line_before_else
  • csharp_new_line_before_members_in_anonymous_typescsharp_new_line_before_members_in_anonymous_types
  • csharp_new_line_before_members_in_object_initializerscsharp_new_line_before_members_in_object_initializers
  • csharp_new_line_before_finally_stylecsharp_new_line_before_finally_style
  • csharp_new_line_between_query_expression_clausescsharp_new_line_between_query_expression_clauses
  • csharp_prefer_bracescsharp_prefer_braces
  • csharp_preferred_modifier_order_stylecsharp_preferred_modifier_order_style
  • csharp_prefer_simple_default_expressioncsharp_prefer_simple_default_expression
  • csharp_preserve_single_line_blockscsharp_preserve_single_line_blocks
  • csharp_space_after_castcsharp_space_after_cast
  • csharp_space_after_keywords_in_control_flow_statementscsharp_space_after_keywords_in_control_flow_statements
  • csharp_space_between_method_call_parameter_list_parenthesescsharp_space_between_method_call_parameter_list_parentheses
  • csharp_space_between_method_declaration_parameter_list_parenthesescsharp_space_between_method_declaration_parameter_list_parentheses
  • csharp_space_between_parenthesescsharp_space_between_parentheses
  • csharp_style_expression_bodied_accessorscsharp_style_expression_bodied_accessors
  • csharp_style_expression_bodied_constructorscsharp_style_expression_bodied_constructors
  • csharp_style_expression_bodied_indexerscsharp_style_expression_bodied_indexers
  • csharp_style_expression_bodied_methodscsharp_style_expression_bodied_methods
  • csharp_style_expression_bodied_operatorscsharp_style_expression_bodied_operators
  • csharp_style_expression_bodied_propertiescsharp_style_expression_bodied_properties
  • csharp_style_inlined_variable_declarationcsharp_style_inlined_variable_declaration
  • csharp_style_pattern_local_over_anonymous_functioncsharp_style_pattern_local_over_anonymous_function
  • csharp_style_pattern_matching_over_as_with_null_checkcsharp_style_pattern_matching_over_as_with_null_check
  • csharp_style_var_for_built_in_typescsharp_style_var_for_built_in_types
  • csharp_style_var_when_type_is_apparentcsharp_style_var_when_type_is_apparent
  • dotnet_sort_system_directives_firstdotnet_sort_system_directives_first
  • dotnet_style_explicit_tuple_namesdotnet_style_explicit_tuple_names
  • dotnet_style_object_initializerdotnet_style_object_initializer
  • dotnet_style_predefined_type_for_locals_parameters_membersdotnet_style_predefined_type_for_locals_parameters_members
  • dotnet_style_predefined_type_for_member_accessdotnet_style_predefined_type_for_member_access
  • dotnet_style_prefer_inferred_anonymous_type_member_namesdotnet_style_prefer_inferred_anonymous_type_member_names
  • dotnet_style_qualification_for_eventdotnet_style_qualification_for_event
  • dotnet_style_qualification_for_fielddotnet_style_qualification_for_field
  • dotnet_style_qualification_for_methoddotnet_style_qualification_for_method
  • dotnet_style_qualification_for_propertydotnet_style_qualification_for_property
  • dotnet_style_require_accessibility_modifiersdotnet_style_require_accessibility_modifiers

Voir aussiSee also