-
Notifications
You must be signed in to change notification settings - Fork 61
Style Guidelines
- No line should be longer than 99 characters, except import statements, which should be one per line.
- Java code must declare the package it is part of.
- Imports should not be present unless they are used in the file.
-
import foo.*
should be used sparingly, only when it improves code readability. - Imports should be used whenever a qualified path is required, except in the case of namespace conflicts.
-
long
literals shall be declared with an uppercase "L". - There shall be one outer type per file, named the same as the filename.
- Text files shall end in a new line character.
Some suggestions for automatically handling the whitespace issues are gathered at Whitespace Tips.
- Code should not follow the pattern
if (something) { return true; } else { return false; }
or other similar patterns. - Comparison of a String literal to a String object reference should follow the pattern
"foo".equals(bar);
- In interfaces, all methods and the declaration itself should be javadoc'd.
- In enums, all enum values and the declaration itself should be javadoc'd.
- In classes, fields which have complex meaning, or methods which perform complex tasks, should be javadoc'd, as should the class itself.
Copyright notices shall be present in all files, and kept up to date. For example, in Java classes, the first line of any file which was created in 2012 and last modified in 2014 should be:
// Copyright (c) 2012-2014 K Team. All Rights Reserved.
The copyright notice is whitespace and capitalization sensitive. Whenever modifying a file, the copyright notice should be updated to end with the current year. This will be accomplished by means of periodic changes to the checkstyle xml file every January 1.
For information on the precise syntax of copyright notices in other languages, please refer to the checkstyle specification
- No tabs. All indents should be four spaces.
- No trailing whitespace at the end of the line.
- no Windows or Mac OS 9 line breaks.
-
IntelliJ has an option to remove trailing ws on changed lines on save. This is super useful.
-
If you add ?w=1 to Github URL of diff page, it shows diffs ignoring whitespace changes. Just like
git diff -w
. -
This vim key mapping makes
\W
delete trailing whitespacenoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
-
Adding this to .vimrc will highlight all tabs and trailing whitespace in red. Very handy.
set hlsearch highlight ExtraWhitespace ctermbg=red guibg=darkgreen match ExtraWhitespace /\s\+$\|\t/
We should only have correctly formatted code now, but here are some tips on merging the big whitespace-fixing commit into an unfixed branch:
- merge or rebase into your branch with the
-Xignore-space-change
flag to avoid conflicts - The script
src/main/scripts/fix_whitespace
adjusts whitespace to obey the new guidelines (fixes Windows newlines, but not early Mac ones). - Use
git diff --ignore-space-change
to ensure that you don't see any files that were modified which should not have been.