Code Style
Configure Java Style for IntelliJ
First, download the style configuration.
curl https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml -o ~/Downloads/intellij-java-google-style.xml
Install it in IntelliJ:
- Go to
Preferences > Editor > Code Style
- Press the little cog:
Import Scheme > IntelliJ IDEA code style XML
- Select the file we just downloaded
- Select
GoogleStyle
in the dropdown - Change default
Hard wrap at
inWrapping and Braces
tab to 150 - Use explicit imports
- Under
Preferences > Code Style > Java > Imports
- change
Class count to use import with '*'
to9999
- change
Names count to use static import with '*'
to9999
- change
- Under
Preferences > Code Style > Kotlin > Imports
- change
Top Level Symbols
toUse single name import
- change
Java Statics and Enum Members
toUse single name import
- change
- Under
- Add the
final
keyword wherever possible. You can either set this as the default for your IDE or you can set it just for the Airbyte project(s) that you are using- Turn on the inspection. Go into
Preferences > Editor > Inspections
- Search
"Field may be 'final'"
> check the box - Search
"local variable or parameter can be 'final'"
> check the box - Apply the changes
- Search
- Turn on the auto add final. Go into IntelliJ Preferences
- Plugins - install Save Actions if not already installed
- If you're running Intellij 2023.1 or higher, the official version may not work. Try manually installing this fork (see Github issue).
- Go to Save Actions in the preferences left navigation column (NOT Tools > Actions on Save -- that is a different tool)
Activate save actions on save
> check the boxActive save actions on shortcut
> check the boxActivate save actions on batch
> check the boxAdd final modifier to field
> check the boxAdd final modifier to local variable or parameter
> check the box- Apply the changes
- Plugins - install Save Actions if not already installed
- Turn on the inspection. Go into
- You're done!
Source code comments
It's hard to pin down exactly what to do around source code comments, but there are two (very subjective) and rough guidelines:
If something is not obvious, write it down. Examples include:
- non-trivial class definitions should have docstrings
- magic variables should have comments explaining why those values are used (e.g: if using a page size of 10 in a connector, describe why if possible. If there is no reason, that's also fine, just mention in a comment).
- Complicated subroutines/logic which cannot be refactored should have comments explaining what they are doing and why
If something is obvious, don't write it down since it's probably more likely to go out of date. For example, a comment like x = 42; // sets x to 42
is not adding any new information and is therefore better omitted.