Git Product home page Git Product logo

java-kotlin-code-styles's Introduction

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

java-kotlin-code-styles's People

Contributors

rastislavvasko avatar goncalossilva avatar julien-herrero-tab avatar panpeter avatar musenkishi avatar pedrodanielcsantos avatar

Watchers

James Cloos avatar

Forkers

jean-leraille

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.