IntelliJ IDEA Tips & Tricks: 3. Customizing the code style for each folder

When working in a team it is recommended to make sure that the style of your code is consistent for the whole team. Often this is not so important, what are your specific rules, since everyone adheres to the same agreements. This makes your codebase much cleaner, easier to read and maintain.



This translation continues the IntelliJ IDEA series:



EditorConfig


. Prettier. , . IDE, CI , Git Hooks.


โ€” EditorConfig. Prettier. .editorconfig . IDE . ยซ ยป, .


:


# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{jsundefinedpy}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.jsonundefined.travis.yml}]
indent_style = space
indent_size = 2

, , .editorconfig . . , . , .


IDEA


, , IDE, . , . .editorconfig , , , .


. , , EditorConfig. IDE , EditorConfig.


, , . , IDEA IDE.


, , Editor Config. , .


EditorConfig IDEA


IDEA EditorConfig . , 2019.2, , IDEA , EditorConfig.


, , IDEA. ?


.editorconfig


-, .editorconfig . , . :


New โ†’ EditorConfig File

IDEA , .



Root


root = true . ?


, . , IDE, , .editorconfig, . , , . , .editorconfig, root = true. root = true.


, IDE . . , , . , , , .



, .



, IDE, EditorConfig, EditorConfig standard. IDEA , IDEA, Java, Kotlin HTML.


Java. IDEA / Java. 250 !


[*.java]
ij_java_align_consecutive_assignments = false
ij_java_align_consecutive_variable_declarations = false
ij_java_align_group_field_declarations = false
ij_java_align_multiline_annotation_parameters = false
ij_java_align_multiline_array_initializer_expression = false
ij_java_align_multiline_assignment = false
ij_java_align_multiline_binary_operation = false
ij_java_align_multiline_chained_methods = false
ij_java_align_multiline_extends_list = false
ij_java_align_multiline_for = true
ij_java_align_multiline_method_parentheses = false
ij_java_align_multiline_parameters = true
ij_java_align_multiline_parameters_in_calls = false
ij_java_align_multiline_parenthesized_expression = false
ij_java_align_multiline_resources = true
ij_java_align_multiline_ternary_operation = false
ij_java_align_multiline_throws_list = false
ij_java_align_subsequent_simple_methods = false
ij_java_align_throws_keyword = false
ij_java_annotation_parameter_wrap = off
ij_java_array_initializer_new_line_after_left_brace = false

. , ij_. , IDEA.



IDEA , 250 Java. , , .


Add properties as comments ( ). , . - , , .



, . , .


, [*.Java] [*], .



, , . , , .



, .



.editorconfig . , - , , .


, [*] , Java [* .java], . IDEA gutter ( ). , .



, . , . , .



, .editorconfig. . . . :


  • .
  • , .
  • root = true
  • IDE
  • .editorconfig, IDE


Although the extended support for EditorConfig is very powerful, it is not a complete replacement for the good old IDE sync settings, which can also sync your IDE plugins.


Conclusion


EditorConfig in IDEA has become much more powerful. It supports not only the original EditorConfig parameters, but also many IDEA-specific parameters. This way, you can easily share a unified IDE configuration among your team members with zero configuration. No more import / export settings or tedious settings for synchronizing IDE settings. Moreover, now you can have different configuration parameters for each directory separately.


All Articles