支持IDEA的Java规范代码格式化配置文件
更多配置详情参阅:EditorConfig Properties · editorconfig/editorconfig Wiki (github.com)
配置详解:
在项目根目录下创建 .editorconfig
文件,加入如下内容:
# http://editorconfig.org
root = true
# 空格替代Tab缩进在各种编辑工具下效果一致
[*]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
[*.java]
########################## idea java doc 格式化设置 start ##########################
# 是否开启doc注释格式化
ij_java_doc_enable_formatting = true
# 是否对齐doc参数注释
ij_java_doc_align_param_comments = true
# 是否对齐异常注释
ij_java_doc_align_exception_comments = true
# 是否保留空参注释
ij_java_doc_keep_empty_parameter_tag = false
# 是否保留空返回注释
ij_java_doc_keep_empty_return_tag = false
# 是否保留空抛错注释
ij_java_doc_keep_empty_throws_tag = false
# 是否将空行加入<p>标签
ij_java_doc_add_p_tag_on_empty_lines = true
# 是否在参数说明后面加入空行
ij_java_doc_add_blank_line_after_param_comments = true
# 是否在方法说明后加入空行
ij_java_doc_add_blank_line_after_description = true
# 是否使用@throw而不是@exception
ij_java_doc_use_throws_not_exception_tag = true
########################## idea java doc 格式化设置 end ##########################
########################## idea java 空格 格式化设置 start ##########################
# 括号之前
ij_java_space_before_for_parentheses = true
ij_java_space_before_if_parentheses = true
ij_java_space_before_while_parentheses = true
ij_java_space_before_switch_parentheses = true
ij_java_space_before_try_parentheses = true
ij_java_space_before_catch_parentheses = true
ij_java_space_before_synchronized_parentheses = true
# 左大括号之前
ij_java_space_before_class_left_brace = true
ij_java_space_before_method_left_brace = true
ij_java_space_before_for_left_brace = true
ij_java_space_before_if_left_brace = true
ij_java_space_before_else_left_brace = true
ij_java_space_before_do_left_brace = true
ij_java_space_before_while_left_brace = true
ij_java_space_before_switch_left_brace = true
ij_java_space_before_try_left_brace = true
ij_java_space_before_catch_left_brace = true
ij_java_space_before_finally_left_brace = true
ij_java_space_before_synchronized_left_brace = true
# 运算符周围
ij_java_spaces_around_additive_operators = true
ij_java_spaces_around_assignment_operators = true
ij_java_spaces_around_bitwise_operators = true
ij_java_spaces_around_equality_operators = true
ij_java_spaces_around_lambda_arrow = true
ij_java_spaces_around_logical_operators = true
ij_java_spaces_around_multiplicative_operators = true
ij_java_spaces_around_relational_operators = true
ij_java_spaces_around_shift_operators = true
# 关键字之前
ij_java_space_before_else_keyword = true
ij_java_space_before_while_keyword = true
ij_java_space_before_catch_keyword = true
ij_java_space_before_finally_keyword = true
# 类型实参
ij_java_space_after_comma_in_type_arguments = true
# 三元运算中
ij_java_space_before_quest = true
ij_java_space_after_quest = true
ij_java_space_before_colon = true
ij_java_space_after_colon = true
# 其他
ij_java_space_after_comma = true
ij_java_space_after_for_semicolon = true
ij_java_space_after_type_cast = true
ij_java_spaces_around_annotation_eq = true
ij_java_space_before_colon_in_foreach = true
ij_java_spaces_around_type_bounds_in_type_parameters = true
########################## idea java 空格 格式化设置 end ##########################
########################## idea java 空白行 格式化设置 started ##########################
ij_java_keep_blank_lines_in_declarations = 2
ij_java_keep_blank_lines_before_right_brace = 2
ij_java_keep_blank_lines_between_package_declaration_and_header = 2
ij_java_keep_blank_lines_in_code = 2
########################## idea java 空白行 格式化设置 end ##########################
ij_java_continuation_indent_size = 8
[*.{json,yml,yaml}]
indent_size = 2
[*.md]
insert_final_newline = false
trim_trailing_whitespace = false