imk13 / java-kotlin-code-styles

IntelliJ IDEA code style settings for Doist's Java and Android projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code Styles

IntelliJ IDEA code style settings for Doist's Java, Kotlin and Android projects.

Installation

  • Run the install.sh or install.bat script;
  • Restart IntelliJ if it's running;
  • Open IntelliJ Project Settings -> Code Styles, change the code style for the project to the one you want.

Java

The code style definition follows Google's general guidelines and Android's definitions, which override some of the rules.

There are, however, a few rules which we ourselves override and some that are not mentioned above:

  • No copyright notice is included at the top of files;
  • Import order and paragraphs are not managed manually by the developer, but instead automatically by IntelliJ / Android Studio;
  • The single parameterless annotation exception is never used, as annotations are always placed in their own line, except annotations on method parameters which can go on the same line;
  • Exceptions widely known to be safe to ignore can be ignored (common in Android and some libraries). It's better not to show a tooltip at a given moment than to crash the app for the user;
  • Non-public static member variables are prefixed with s, all others follow the conventions mentioned in the documents;
  • All comments always start capitalized and end with a period. They're written English, so they follow the written English rules;
  • Getters and setters are intercalated. setEmail follows getEmail.
  • Parcelable code goes at the end of the class in the following order: constructor, writeToParcel, CREATOR and describeContents. Follows the usual reader / writer flow and orders methods by usefulness and likelihood of change. There's a useful IntelliJ plug-in for this.

Kotlin

The code style definition follows the official Kotlin style guide, with a few changes to enforce compatibility with ktlint and additional rules not mentioned above:

  • No copyright notice is included at the top of files;
  • Import order and paragraphs are not managed manually by the developer, but instead automatically by IntelliJ / Android Studio;
  • Exceptions widely known to be safe to ignore can be ignored (common in Android and some libraries). It's better not to show a tooltip at a given moment than to crash the app for the user;
  • All comments always start capitalized and end with a period. They're written English, so they follow the written English rules;
  • Parcelable code goes at the end of the class in the following order: constructor, writeToParcel, CREATOR and describeContents. Follows the usual reader / writer flow and orders methods by usefulness and likelihood of change. Better yet, use @Parcelize.

Save actions in Android Studio

There is a handy plugin which will auto format code and organize imports everytime you save a file: https://plugins.jetbrains.com/plugin/7642

To install it

About

IntelliJ IDEA code style settings for Doist's Java and Android projects.


Languages

Language:PowerShell 49.7%Language:Shell 45.0%Language:Batchfile 5.2%