Inteiilj IDEA 團隊代碼格式規範

Intellij IDEA code format

Tabs and Indents

  • Tab size 4
  • keep indents on empty lines

Spaces

Before Parenthenses

  • 'if' parenthesesgithub

  • 'for' parenthesesintellij-idea

  • 'while' parenthesesapp

  • 'switch' parentheseside

  • 'try' parenthesesui

  • 'catch' parenthesesgoogle

  • 'synchronized' parenthesesidea

Around Operators

  • Assignment operators (=,+=,....)spa

  • Logical operators (&&, ||)code

  • Equality operatores

  • Relational operators

  • Bitwise operators

  • Additive operators

  • Multiplicative operators

  • Shift operators

  • Unary operators

  • lambda arrow

Before Left Brace

  • Class left brace

  • Method left brace

  • if left brace

  • else left brace

  • for left brace

  • while left brace

  • do left bvrace

  • Switch left brace

  • try left brace

  • catch left brace

  • finally left brace

  • Synchronized left brace

  • Array initializer left brace

Before Keywords

  • else keyword

  • while keyword

  • catch keyword

  • finally keyword

Within

  • Array initializer braces

In Ternary Opertator

  • Before '?'

  • After '?'

  • Before ':'

  • After ':'

Type Arguments

  • After comma

Other

  • After comma

  • Before for semicolon

  • After for semicolon

  • Sapce before colon in foreach (待確認)

Type Paramters

  • Around Type bounds

Wrapping and Braces

keep when reformatting

  • comment at first column

  • Simple blocks in one line

  • simple methods in one line

  • simple lambda in one line

  • simple classes in one line

if() statement

  • Froce braces (always)

  • Special 'else if ' treatment

for() statement

  • Align when multiline

  • Force brace(always)

while() statement

  • Force brace (Always)

switch statment

  • Indent case branch

  • case in new line

try-with-resources

  • Align when multiline

Imports

general

  • User single class import
  • Class count to use import with '*' : 8
  • Names count to use static import with '*' 5

更新

最近發現了新大陸google 的codestyle github https://github.com/google/styleguide
[使用方式] (https://www.jianshu.com/p/a44329bf5935)

相關文章
相關標籤/搜索