我正在使用Visual Studio 2019和用于格式化的编辑器配置文件。 我确实有几个用于翻译的资源文件,这些文件是通过Visual Studio自动生成的。
我想从任何格式中排除这些文件,但这似乎是不可能的,因为editorconfig不直接支持此格式。 https://github.com/editorconfig/editorconfig/issues/228
我现在在编辑器配置中有一个部分,只是忽略了* Designer.cs文件的所有格式
[*.Designer.cs]
charset = none
end_of_line = none
insert_final_newline = none
trim_trailing_whitespace = false
tab_width = none
indent_style = none
indent_size = none
# New line preferences
csharp_new_line_before_catch = none
csharp_new_line_before_else = none
csharp_new_line_before_finally = none
csharp_new_line_before_members_in_anonymous_types = none
csharp_new_line_before_members_in_object_initializers = none
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = none
# Indentation preferences
csharp_indent_block_contents = none
csharp_indent_braces = none
csharp_indent_case_contents = none
csharp_indent_case_contents_when_block = none
csharp_indent_labels = none
csharp_indent_switch_labels = none
# Space preferences
csharp_space_after_cast = none
csharp_space_after_colon_in_inheritance_clause = none
csharp_space_after_comma = none
csharp_space_after_dot = none
csharp_space_after_keywords_in_control_flow_statements = none
csharp_space_after_semicolon_in_for_statement = none
csharp_space_around_binary_operators = none
csharp_space_around_declaration_statements = none
csharp_space_before_colon_in_inheritance_clause = none
csharp_space_before_comma = none
csharp_space_before_dot = none
csharp_space_before_open_square_brackets = none
csharp_space_before_semicolon_in_for_statement = none
csharp_space_between_empty_square_brackets = none
csharp_space_between_method_call_empty_parameter_list_parentheses = none
csharp_space_between_method_call_name_and_opening_parenthesis = none
csharp_space_between_method_call_parameter_list_parentheses = none
csharp_space_between_method_declaration_empty_parameter_list_parentheses = none
csharp_space_between_method_declaration_name_and_open_parenthesis = none
csharp_space_between_method_declaration_parameter_list_parentheses = none
csharp_space_between_parentheses = none
csharp_space_between_square_brackets = none
# Wrapping preferences
csharp_preserve_single_line_blocks = none
csharp_preserve_single_line_statements = none
end_of_line = none
insert_final_newline = none
在大多数情况下,上面的配置有效,但是在某些情况下,Designer.cs文件仍然被格式化。它确实替换了否则为空的行上的缩进(制表符)。
任何提示都提示我如何将其排除在格式化之外?
答案 0 :(得分:1)
我试图用给定的.editorocnfig重现该问题,但我做不到。
/*
* TEST PRG
*/
namespace Program
{
internal class TestProgram{
private int x;
protected int y;
internal int z;
public int a;
Console.WriteLine(x);
Console.WriteLine(y);
Console.WriteLine(z);
Console.WriteLine(a);
}
}
}
能否请您尝试使用相同的.editorconfig文件创建一个新文件夹,并尝试使用上面的代码? 这样,我们就可以消除其他情况(例如yapf)用尾随空格修剪空行的情况。